feat!: remove the rsync backend

The native libcephfs backend is the only transfer path. The rsync
transport, the mounted-filesystem access and its helpers (mount check,
path resolution below a mount, mount claim, quota and hardlink repair
through the mount) are removed, together with the rsync lab test and
the client image that only added rsync.

The claim and release tests now exercise the native claim through a
local test file system with real flock locks.

BREAKING CHANGE: "backend": "rsync" and the endpoint field "mount" are
rejected. "backend" is optional and only accepts "native"; jobs created
with "native" resume without it. Journals of rsync jobs cannot be
resumed. Builds without the build tag ceph only support doctor and
status.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 22:03:22 +01:00
1 parent f0ea1fd7cd
commit 330a3ec12c
31 files changed
+263 -1522

No files matched your search

+6 -160
View File
@@ -15,12 +15,11 @@ import (
"slices"
"sort"
"strings"
"syscall"
"time"
)
// Engine runs the snapshot-based migration workflow. Transport moves the
// data; Access, if nil, defaults to mounted filesystem access.
// data; Access reaches both clusters for everything else. Both are required.
type Engine struct {
Exec Executor
Transport Transport
@@ -88,80 +87,6 @@ func queryEndpoint(ctx context.Context, c ceph) (string, endpointInfo, error) {
return fsid, info, nil
}
func endpoint(ctx context.Context, c ceph) (string, endpointInfo, string, error) {
fsid, info, err := queryEndpoint(ctx, c)
if err != nil {
return "", info, "", err
}
path, err := dataPath(c.endpoint.Mount, info.Path)
if err != nil {
return "", info, "", err
}
mountedFSID, err := xattr(path, "ceph.cluster_fsid")
if err != nil {
return "", info, "", fmt.Errorf("cannot verify mount FSID: %w", err)
}
if string(mountedFSID) != fsid {
return "", info, "", fmt.Errorf("mount belongs to a different cluster than the configured Ceph endpoint")
}
return fsid, info, path, err
}
func inspectMounted(ctx context.Context, c Config, x Executor) (*Inspection, error) {
if err := c.Validate(); err != nil {
return nil, err
}
if err := checkMount(c.Source.Mount, false); err != nil {
return nil, err
}
if err := checkMount(c.Target.Mount, true); err != nil {
return nil, err
}
src, dst := ceph{endpoint: c.Source, exec: x}, ceph{endpoint: c.Target, exec: x}
sf, si, sp, err := endpoint(ctx, src)
if err != nil {
return nil, fmt.Errorf("source: %w", err)
}
tf, _, tp, err := endpoint(ctx, dst)
if err != nil {
return nil, fmt.Errorf("target: %w", err)
}
if sf == tf {
return nil, errors.New("source and target must be different clusters")
}
var ss, ts syscall.Stat_t
if err = syscall.Stat(sp, &ss); err != nil {
return nil, err
}
if err = syscall.Stat(tp, &ts); err != nil {
return nil, err
}
if ss.Dev == ts.Dev {
return nil, errors.New("source and target are on the same mounted filesystem")
}
names, err := src.names(ctx)
if err != nil {
return nil, err
}
inspection := &Inspection{SourceFSID: sf, TargetFSID: tf, SourcePath: sp, TargetPath: tp, SourceBytes: si.BytesUsed, SourceSnapshots: names}
inspection.Notes = []string{SnapshotIdentityNote}
return inspection, nil
}
func newID() (string, error) {
var b [16]byte
if _, err := rand.Read(b[:]); err != nil {
@@ -171,25 +96,6 @@ func newID() (string, error) {
return hex.EncodeToString(b[:]), nil
}
func emptyDirectory(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
entries, err := f.ReadDir(1)
if err != nil && !errors.Is(err, io.EOF) {
return err
}
if len(entries) != 0 {
return fmt.Errorf("new migration requires empty target subvolume: %s", path)
}
return nil
}
// claimName is the file name of the claim for the target subvolume ep in
// the cluster fsid, below .cephmig/claims at the file system root.
func claimName(fsid string, ep Endpoint) string {
@@ -197,64 +103,6 @@ func claimName(fsid string, ep Endpoint) string {
return hex.EncodeToString(key[:])
}
// claimTarget locks the target subvolume for the job id. The claim is outside
// the migrated tree and survives deletion of the local journal. O_EXCL prevents two different jobs from adopting the same target.
func claimTarget(root, fsid string, ep Endpoint, id string) (*os.File, error) {
dir := filepath.Join(root, ".cephmig", "claims")
if err := privateDirectories(dir); err != nil {
return nil, err
}
resolved, err := filepath.EvalSymlinks(dir)
if err != nil || resolved != dir {
return nil, errors.New("claim directory contains symlinks")
}
path := filepath.Join(dir, claimName(fsid, ep))
f, err := os.OpenFile(path, os.O_CREATE|os.O_EXCL|os.O_RDWR, 0600)
if err == nil {
if _, err = f.WriteString(id + "\n"); err == nil {
err = f.Sync()
}
if closeErr := f.Close(); err == nil {
err = closeErr
}
if err != nil {
return nil, err
}
} else if !errors.Is(err, os.ErrExist) {
return nil, err
}
st, err := os.Lstat(path)
if err != nil {
return nil, err
}
if !st.Mode().IsRegular() {
return nil, errors.New("target claim is not a regular file")
}
f, err = os.OpenFile(path, os.O_RDWR|syscall.O_NOFOLLOW, 0)
if err != nil {
return nil, err
}
if err = syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
f.Close()
return nil, fmt.Errorf("target is being migrated by another process: %w", err)
}
b, err := io.ReadAll(io.LimitReader(f, 256))
if err != nil || string(b) != id+"\n" {
f.Close()
return nil, errors.New("target is claimed by a different job or claim is incomplete; preserve the original state file")
}
return f, nil
}
func snapshotDetails(ctx context.Context, src ceph, name string) (Snapshot, error) {
var s Snapshot
s.Name = name
@@ -294,8 +142,8 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
return errors.New("migration requires root for numeric ownership, ACLs and xattrs")
}
if e.Exec == nil || e.Transport == nil {
return errors.New("missing executor or transport")
if e.Exec == nil || e.Transport == nil || e.Access == nil {
return errors.New("missing executor, transport or access")
}
abs, err := filepath.Abs(statePath)
@@ -303,10 +151,6 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
return err
}
if c.Backend != "native" && (overlaps(filepath.Dir(abs), c.Source.Mount) || overlaps(filepath.Dir(abs), c.Target.Mount)) {
return errors.New("state directory must be outside the CephFS mounts")
}
if err = privateDirectories(filepath.Dir(abs)); err != nil {
return err
}
@@ -327,7 +171,7 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
return err
}
src, dst := ceph{endpoint: c.Source, exec: e.Exec, native: c.Backend == "native"}, ceph{endpoint: c.Target, exec: e.Exec, native: c.Backend == "native"}
src, dst := ceph{endpoint: c.Source, exec: e.Exec}, ceph{endpoint: c.Target, exec: e.Exec}
s, err := LoadState(abs)
if errors.Is(err, os.ErrNotExist) {
if err = e.access().Empty(ctx, inspection.TargetPath); err != nil {
@@ -590,6 +434,8 @@ func sameMigrationIdentity(a, b Config) bool {
a.Workers, b.Workers = 0, 0
a.BandwidthKiB, b.BandwidthKiB = 0, 0
a.FullScan, b.FullScan = false, false
// "" and "native" select the same backend.
a.Backend, b.Backend = "", ""
return reflect.DeepEqual(a, b)
}