package migration import ( "context" "errors" "fmt" "io" "path" "strings" ) func nativePath(p string) (string, error) { if !strings.HasPrefix(p, "/") || path.Clean(p) != p || p == "/" { return "", fmt.Errorf("invalid Ceph data path %q", p) } return p, nil } // Access separates filesystem access from the shared snapshot/journal workflow. type Access interface { Inspect(context.Context, Config, Executor) (*Inspection, error) Empty(context.Context, string) error Claim(context.Context, Config, string, string) (io.Closer, error) Prepare(context.Context, string, string, string) error Apply(context.Context, string, string) error Verify(context.Context, string, string, string) error // Release deletes the claim of job id, and the claim directories if // they are empty. A missing claim is not an error. Release(context.Context, Config, string, string) error } func (e Engine) access() Access { return e.Access } // Inspect checks both endpoints without changing them and reports what a // migration would transfer. func (e Engine) Inspect(ctx context.Context, c Config) (*Inspection, error) { if e.Access == nil { return nil, errors.New("missing access") } return e.Access.Inspect(ctx, c, e.Exec) } // Transport copies a source tree to the target and verifies the copy. type Transport interface { Copy(context.Context, string, string) error Verify(context.Context, string, string) error } // Round describes one snapshot transfer handed to a RoundTransport. // BaseName and BaseSourcePath name the last completed snapshot, if any, // which allows an incremental transfer. type Round struct { SourcePath, TargetPath string BaseName, BaseSourcePath string Name, StatePath string } // RoundTransport is a Transport that keeps state across a snapshot round, // such as the native backend's on-disk index. type RoundTransport interface { BeginRound(context.Context, Round) error Published(string) Commit(context.Context, string) error Statistics() TransferStats } // TransferStats summarizes the work done for one snapshot round. type TransferStats struct { Mode string `json:"mode"` BaseSnapshot string `json:"base_snapshot,omitempty"` FilesVisited int64 `json:"files_visited"` FilesCopied int64 `json:"files_copied"` BytesCopied int64 `json:"bytes_copied"` BytesVerified int64 `json:"bytes_verified"` BlockDiffFiles int64 `json:"blockdiff_files"` SnapDiffEntries int64 `json:"snapdiff_entries"` // Seconds is the duration of the round from its start to the commit, // including verification and snapshot creation. Seconds float64 `json:"seconds"` } // NewEngine returns an Engine with the native libcephfs backend and a Closer // that releases its connections. Builds without the build tag ceph return an // error. func NewEngine(ctx context.Context, c Config, x Executor, log io.Writer) (Engine, io.Closer, error) { return openNativeEngine(ctx, c, x, log) }