chore: import CephMig prototype
Initial import of the existing CephFS subvolume migration prototype, including the native libcephfs transport, rsync backend, local Ceph lab environment and integration tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7705ed3eaf
58 files changed
+8769
No files matched your search
@@ -0,0 +1,94 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"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
|
||||
}
|
||||
|
||||
type mountedAccess struct{}
|
||||
|
||||
func (mountedAccess) Inspect(ctx context.Context, c Config, x Executor) (*Inspection, error) {
|
||||
return inspectMounted(ctx, c, x)
|
||||
}
|
||||
func (mountedAccess) Empty(_ context.Context, p string) error { return emptyDirectory(p) }
|
||||
func (mountedAccess) Claim(_ context.Context, c Config, fsid, id string) (io.Closer, error) {
|
||||
return claimTarget(c.Target.Mount, fsid, c.Target, id)
|
||||
}
|
||||
func (mountedAccess) Prepare(ctx context.Context, src, dst, scratch string) error {
|
||||
if err := clearQuotas(ctx, dst); err != nil {
|
||||
return err
|
||||
}
|
||||
return hardlinkTopology(ctx, src, dst, scratch, true)
|
||||
}
|
||||
func (mountedAccess) Apply(ctx context.Context, src, dst string) error {
|
||||
return quotas(ctx, src, dst, false)
|
||||
}
|
||||
func (mountedAccess) Verify(ctx context.Context, src, dst, scratch string) error {
|
||||
if err := hardlinkTopology(ctx, src, dst, scratch, false); err != nil {
|
||||
return err
|
||||
}
|
||||
return quotas(ctx, src, dst, true)
|
||||
}
|
||||
func (e Engine) access() Access {
|
||||
if e.Access != nil {
|
||||
return e.Access
|
||||
}
|
||||
return mountedAccess{}
|
||||
}
|
||||
func (e Engine) Inspect(ctx context.Context, c Config) (*Inspection, error) {
|
||||
return e.access().Inspect(ctx, c, e.Exec)
|
||||
}
|
||||
|
||||
type Round struct {
|
||||
SourcePath, TargetPath string
|
||||
BaseName, BaseSourcePath string
|
||||
Name, StatePath string
|
||||
}
|
||||
type RoundTransport interface {
|
||||
BeginRound(context.Context, Round) error
|
||||
Published(string)
|
||||
Commit(context.Context, string) error
|
||||
Statistics() TransferStats
|
||||
}
|
||||
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"`
|
||||
}
|
||||
|
||||
// NewEngine never silently falls back from native I/O to mounted/rsync I/O.
|
||||
func NewEngine(ctx context.Context, c Config, x Executor, log io.Writer) (Engine, io.Closer, error) {
|
||||
if c.Backend == "native" {
|
||||
return openNativeEngine(ctx, c, x, log)
|
||||
}
|
||||
return Engine{Exec: x, Log: log, Transport: Rsync{Exec: x, Log: log, BandwidthKiB: c.BandwidthKiB}}, nopCloser{}, nil
|
||||
}
|
||||
|
||||
type nopCloser struct{}
|
||||
|
||||
func (nopCloser) Close() error { return nil }
|
||||
Reference in new issue
Block a user