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

+16 -88
View File
@@ -5,11 +5,8 @@ import (
"errors"
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"syscall"
)
func nativePath(p string) (string, error) {
@@ -33,84 +30,22 @@ type Access interface {
Release(context.Context, Config, 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) Release(_ context.Context, c Config, fsid, id string) error {
dir := filepath.Join(c.Target.Mount, ".cephmig", "claims")
p := filepath.Join(dir, claimName(fsid, c.Target))
f, err := os.OpenFile(p, os.O_RDONLY|syscall.O_NOFOLLOW, 0)
if errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return err
}
b, err := io.ReadAll(io.LimitReader(f, 256))
f.Close()
if err != nil {
return err
}
if string(b) != id+"\n" {
return errors.New("target claim belongs to a different job; not removed")
}
if err = os.Remove(p); err != nil {
return err
}
for _, d := range []string{dir, filepath.Dir(dir)} {
if err := os.Remove(d); err != nil && !errors.Is(err, os.ErrNotExist) && !errors.Is(err, syscall.ENOTEMPTY) && !errors.Is(err, syscall.EEXIST) {
return err
}
}
return nil
}
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) 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) {
return e.access().Inspect(ctx, c, e.Exec)
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.
@@ -149,16 +84,9 @@ type TransferStats struct {
Seconds float64 `json:"seconds"`
}
// NewEngine returns an Engine for c.Backend and a Closer that releases its
// connections. It never silently falls back from native I/O to mounted/rsync I/O.
// 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) {
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
return openNativeEngine(ctx, c, x, log)
}
type nopCloser struct{}
func (nopCloser) Close() error { return nil }
+1 -7
View File
@@ -11,7 +11,6 @@ import (
type ceph struct {
endpoint Endpoint
exec Executor
native bool
}
func (c ceph) call(ctx context.Context, args ...string) ([]byte, error) {
@@ -64,12 +63,7 @@ func (c ceph) snapshotPath(ctx context.Context, name string) (string, error) {
return "", err
}
p := strings.TrimSpace(string(b))
if c.native {
return nativePath(p)
}
return dataPath(c.endpoint.Mount, p)
return nativePath(strings.TrimSpace(string(b)))
}
func (c ceph) names(ctx context.Context) ([]string, error) {
+1 -2
View File
@@ -108,8 +108,7 @@ func (e Engine) Cleanup(ctx context.Context, c Config, statePath string) error {
defer claim.Close()
}
native := c.Backend == "native"
src, dst := ceph{endpoint: c.Source, exec: e.Exec, native: native}, ceph{endpoint: c.Target, exec: e.Exec, native: native}
src, dst := ceph{endpoint: c.Source, exec: e.Exec}, ceph{endpoint: c.Target, exec: e.Exec}
s.LiveSnapshot = ""
if err = removeOwnedSnapshots(ctx, src, dst, abs, s, ""); err != nil {
return err
-51
View File
@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"os"
"path/filepath"
"slices"
"testing"
@@ -128,56 +127,6 @@ func TestStateRejectsInvalidRemoval(t *testing.T) {
}
}
func TestReleaseRemovesOnlyOwnClaim(t *testing.T) {
root := t.TempDir()
c := testConfig()
c.Target.Mount = root
other := c
other.Target.Subvolume = "other"
for _, x := range []struct {
c Config
id string
}{{c, "job-one"}, {other, "job-two"}} {
f, err := claimTarget(root, "fsid", x.c.Target, x.id)
if err != nil {
t.Fatal(err)
}
f.Close()
}
access := mountedAccess{}
if err := access.Release(context.Background(), c, "fsid", "job-two"); err == nil {
t.Fatal("removed the claim of a different job")
}
if err := access.Release(context.Background(), c, "fsid", "job-one"); err != nil {
t.Fatal(err)
}
claims := filepath.Join(root, ".cephmig", "claims")
if _, err := os.Stat(filepath.Join(claims, claimName("fsid", c.Target))); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("own claim still present: %v", err)
}
if _, err := os.Stat(filepath.Join(claims, claimName("fsid", other.Target))); err != nil {
t.Fatalf("claim of another job removed: %v", err)
}
if err := access.Release(context.Background(), other, "fsid", "job-two"); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(root, ".cephmig")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("empty claim directories kept: %v", err)
}
// Releasing again is a no-op.
if err := access.Release(context.Background(), c, "fsid", "job-one"); err != nil {
t.Fatal(err)
}
}
func TestCleanedUp(t *testing.T) {
s := testState()
s.Phase = "ready-for-cutover"
+5 -52
View File
@@ -11,8 +11,7 @@ import (
)
// Endpoint describes how to reach one side of a migration: the Ceph
// client identity and configuration, the subvolume and, for the rsync
// backend, the local mount of the CephFS filesystem root.
// client identity and configuration and the subvolume.
type Endpoint struct {
User string `json:"user,omitempty"`
Config string `json:"config"`
@@ -20,11 +19,10 @@ type Endpoint struct {
Filesystem string `json:"filesystem"`
Group string `json:"group"`
Subvolume string `json:"subvolume"`
Mount string `json:"mount,omitempty"`
}
// Config is the JSON migration configuration read by ReadConfig.
// Backend selects "native" (libcephfs) or "rsync" (the default).
// Backend is optional; the only backend is "native" (libcephfs).
type Config struct {
Backend string `json:"backend,omitempty"`
Workers int `json:"workers,omitempty"`
@@ -77,8 +75,8 @@ func validName(s string) bool {
// Validate checks names, paths, worker and bandwidth limits and reports
// the first problem found.
func (c Config) Validate() error {
if c.Backend != "" && c.Backend != "rsync" && c.Backend != "native" {
return errors.New("backend must be native or rsync")
if c.Backend != "" && c.Backend != "native" {
return errors.New(`backend must be "native"; the rsync backend was removed`)
}
if c.Workers < 0 || c.Workers > 64 {
@@ -103,12 +101,7 @@ func (c Config) Validate() error {
return fmt.Errorf("%s: invalid group", p.name)
}
paths := []string{p.e.Config, p.e.Keyring}
if c.Backend != "native" || p.e.Mount != "" {
paths = append(paths, p.e.Mount)
}
for _, path := range paths {
for _, path := range []string{p.e.Config, p.e.Keyring} {
if !filepath.IsAbs(path) || filepath.Clean(path) != path {
return fmt.Errorf("%s: paths must be absolute and clean: %q", p.name, path)
}
@@ -119,45 +112,5 @@ func (c Config) Validate() error {
return errors.New("bandwidth_kib must be nonnegative and fit in bytes per second")
}
if c.Backend != "native" && overlaps(c.Source.Mount, c.Target.Mount) {
return errors.New("source and target mounts must not overlap")
}
return nil
}
func beneath(root, path string) bool {
rel, err := filepath.Rel(root, path)
return err == nil && rel != ".." && !strings.HasPrefix(rel, ".."+string(filepath.Separator))
}
func overlaps(a, b string) bool { return beneath(a, b) || beneath(b, a) }
// dataPath resolves cephPath to a real directory below the filesystem mount
// root. No symlink component is permitted, including in the mount path.
func dataPath(root, cephPath string) (string, error) {
if !filepath.IsAbs(cephPath) || filepath.Clean(cephPath) != cephPath || cephPath == "/" {
return "", fmt.Errorf("invalid Ceph path %q", cephPath)
}
p := filepath.Join(root, strings.TrimPrefix(cephPath, "/"))
resolved, err := filepath.EvalSymlinks(p)
if err != nil {
return "", err
}
if resolved != p || !beneath(root, p) {
return "", fmt.Errorf("path escapes mount or contains symlinks: %q", p)
}
st, err := os.Stat(p)
if err != nil {
return "", err
}
if !st.IsDir() {
return "", fmt.Errorf("not a directory: %s", p)
}
return p, nil
}
+11 -27
View File
@@ -9,15 +9,15 @@ import (
)
func testConfig() Config {
return Config{Source: Endpoint{Config: "/clusters/a/ceph.conf", Keyring: "/clusters/a/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "source", Mount: "/mnt/a"},
Target: Endpoint{Config: "/clusters/b/ceph.conf", Keyring: "/clusters/b/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "target", Mount: "/mnt/b"}}
return Config{Source: Endpoint{Config: "/clusters/a/ceph.conf", Keyring: "/clusters/a/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "source"},
Target: Endpoint{Config: "/clusters/b/ceph.conf", Keyring: "/clusters/b/keyring", Filesystem: "cephfs", Group: "group", Subvolume: "target"}}
}
func TestConfigRejectsUnsafePathsAndNames(t *testing.T) {
for name, modify := range map[string]func(*Config){
"overlap": func(c *Config) { c.Target.Mount = "/mnt/a/nested" },
"relative": func(c *Config) { c.Source.Mount = "relative" },
"unclean": func(c *Config) { c.Source.Mount = "/mnt/a/../a" },
"relative": func(c *Config) { c.Source.Config = "relative" },
"unclean": func(c *Config) { c.Target.Keyring = "/clusters/b/../b/keyring" },
"rsync-backend": func(c *Config) { c.Backend = "rsync" },
"flag-name": func(c *Config) { c.Target.Subvolume = "--force" },
"traversal": func(c *Config) { c.Source.Group = "../outside" },
"negative-rate": func(c *Config) { c.BandwidthKiB = -1 },
@@ -43,11 +43,16 @@ func TestConfigRejectsUnsafePathsAndNames(t *testing.T) {
func TestNativeConfigAndResumeSettings(t *testing.T) {
c := testConfig()
c.Backend = "native"
c.Source.Mount, c.Target.Mount = "", ""
if err := c.Validate(); err != nil {
t.Fatal(err)
}
implicit := c
implicit.Backend = ""
if !sameMigrationIdentity(c, implicit) {
t.Fatal(`backend "" and "native" differ in resume identity`)
}
changed := c
changed.Workers, changed.BandwidthKiB = 32, 100000
if !sameMigrationIdentity(c, changed) {
@@ -76,27 +81,6 @@ func TestStrictJSONConfig(t *testing.T) {
}
}
func TestDataPathRejectsEscapeAndSymlink(t *testing.T) {
root := t.TempDir()
if err := os.Mkdir(filepath.Join(root, "real"), 0700); err != nil {
t.Fatal(err)
}
if err := os.Symlink(t.TempDir(), filepath.Join(root, "link")); err != nil {
t.Fatal(err)
}
for _, path := range []string{"/../escape", "/real/../real", "relative", "/link", "/"} {
if _, err := dataPath(root, path); err == nil {
t.Fatalf("accepted %q", path)
}
}
if got, err := dataPath(root, "/real"); err != nil || got != filepath.Join(root, "real") {
t.Fatalf("got %q, %v", got, err)
}
}
func TestPrivateDirectoriesNeverFollowsSymlink(t *testing.T) {
root, outside := t.TempDir(), t.TempDir()
if err := os.Symlink(outside, filepath.Join(root, "link")); err != nil {
+2 -2
View File
@@ -4,6 +4,6 @@
// A migration is a sequence of rounds. Each round creates or picks a source
// snapshot, copies it with a Transport, verifies the target and publishes a
// target snapshot of the same name. Progress is recorded in a State journal so
// that every step can be resumed. Two backends exist: rsync over mounted
// filesystems and a native libcephfs transport (build tag ceph).
// that every step can be resumed. Data moves through libcephfs (build tag
// ceph); no mount and no rsync are needed.
package migration
+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)
}
-143
View File
@@ -2,14 +2,6 @@ package migration
import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"syscall"
"time"
bolt "go.etcd.io/bbolt"
@@ -82,138 +74,3 @@ func (x *linkIndex) observe(bucket string, key, value [16]byte) (bool, error) {
return same, nil
}
func inodeIdentity(info os.FileInfo) ([16]byte, uint64, error) {
var key [16]byte
st, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return key, 0, errors.New("missing Linux inode information")
}
binary.BigEndian.PutUint64(key[:8], uint64(st.Dev))
binary.BigEndian.PutUint64(key[8:], st.Ino)
return key, uint64(st.Nlink), nil
}
// hardlinkTopology compares the hard-link groups of src and dst.
// In repair mode it removes only excess target hardlinks. Missing paths are then
// recreated by the copy backend. In verification mode check both directions:
// source groups must stay joined, and unrelated source files must stay separate.
func hardlinkTopology(ctx context.Context, src, dst, scratchParent string, repair bool) (result error) {
scratch, err := os.MkdirTemp(scratchParent, ".cephmig-links-")
if err != nil {
return err
}
defer os.RemoveAll(scratch)
index, err := openLinkIndex(filepath.Join(scratch, "index.bolt"))
if err != nil {
return err
}
defer func() {
if err := index.close(); result == nil {
result = err
}
}()
targetPath := func(path string) (string, error) {
rel, err := filepath.Rel(src, path)
if err != nil || !beneath(src, path) {
return "", fmt.Errorf("hardlink path outside source: %s", path)
}
return filepath.Join(dst, rel), nil
}
visitDir := func(path string) error {
target, err := targetPath(path)
if err != nil {
return err
}
st, err := os.Lstat(target)
if repair && (errors.Is(err, os.ErrNotExist) || (err == nil && !st.IsDir())) {
// Never follow a target symlink directory, even when its referent exists.
return fs.SkipDir
}
if err != nil {
return err
}
if !st.IsDir() {
return fmt.Errorf("target directory changed type: %s", target)
}
return nil
}
visitFile := func(path string, sourceInfo os.FileInfo) error {
if !sourceInfo.Mode().IsRegular() {
return nil
}
target, err := targetPath(path)
if err != nil {
return err
}
targetInfo, err := os.Lstat(target)
if repair && errors.Is(err, os.ErrNotExist) {
return nil
}
if err != nil {
return err
}
if !targetInfo.Mode().IsRegular() {
if repair {
return nil
}
return fmt.Errorf("hardlink target is not a regular file: %s", target)
}
sourceKey, sourceLinks, err := inodeIdentity(sourceInfo)
if err != nil {
return err
}
targetKey, targetLinks, err := inodeIdentity(targetInfo)
if err != nil {
return err
}
if !repair && sourceLinks > 1 {
same, err := index.observe("source", sourceKey, targetKey)
if err != nil {
return err
}
if !same {
return fmt.Errorf("source hardlink group was split at %s", target)
}
}
if targetLinks > 1 {
same, err := index.observe("target", targetKey, sourceKey)
if err != nil {
return err
}
if !same {
if !repair {
return fmt.Errorf("unrelated source files became hardlinked at %s", target)
}
if err := os.Remove(target); err != nil {
return fmt.Errorf("break obsolete target hardlink: %w", err)
}
}
}
return nil
}
return walkTree(ctx, src, visitDir, visitFile)
}
-137
View File
@@ -1,148 +1,11 @@
package migration
import (
"context"
"encoding/binary"
"io"
"os"
"os/exec"
"path/filepath"
"testing"
)
func mustWrite(t *testing.T, path string) {
t.Helper()
if err := os.WriteFile(path, []byte("identical contents"), 0640); err != nil {
t.Fatal(err)
}
}
func TestHardlinkTopologyHandlesSplitAndRejoin(t *testing.T) {
if _, err := exec.LookPath("rsync"); err != nil {
t.Skip("rsync is not installed")
}
ctx := context.Background()
src, dst, scratch := t.TempDir(), t.TempDir(), t.TempDir()
if err := os.Mkdir(filepath.Join(src, "d"), 0700); err != nil {
t.Fatal(err)
}
a, b := filepath.Join(src, "a"), filepath.Join(src, "d", "b")
mustWrite(t, a)
if err := os.Link(a, b); err != nil {
t.Fatal(err)
}
r := Rsync{Exec: Process{Stderr: io.Discard}, Log: io.Discard}
if err := r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err := hardlinkTopology(ctx, src, dst, scratch, false); err != nil {
t.Fatal(err)
}
// Break one source link without changing bytes, mode or mtime. Rsync -H
// alone can leave an extra target link in this exact case.
old, err := os.Stat(b)
if err != nil {
t.Fatal(err)
}
if err = os.Remove(b); err != nil {
t.Fatal(err)
}
mustWrite(t, b)
if err = os.Chtimes(b, old.ModTime(), old.ModTime()); err != nil {
t.Fatal(err)
}
if err = hardlinkTopology(ctx, src, dst, scratch, false); err == nil {
t.Fatal("extra destination hardlink was missed")
}
if err = hardlinkTopology(ctx, src, dst, scratch, true); err != nil {
t.Fatal(err)
}
if err = r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err = hardlinkTopology(ctx, src, dst, scratch, false); err != nil {
t.Fatal(err)
}
x, _ := os.Stat(filepath.Join(dst, "a"))
y, _ := os.Stat(filepath.Join(dst, "d", "b"))
if os.SameFile(x, y) {
t.Fatal("split source files remained linked")
}
if err = os.Remove(b); err != nil {
t.Fatal(err)
}
if err = os.Link(a, b); err != nil {
t.Fatal(err)
}
if err = hardlinkTopology(ctx, src, dst, scratch, false); err == nil {
t.Fatal("missing target hardlink was missed")
}
if err = hardlinkTopology(ctx, src, dst, scratch, true); err != nil {
t.Fatal(err)
}
if err = r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err = hardlinkTopology(ctx, src, dst, scratch, false); err != nil {
t.Fatal(err)
}
entries, err := os.ReadDir(scratch)
if err != nil || len(entries) != 0 {
t.Fatal("scratch indexes were not removed")
}
}
func TestHardlinkRepairDoesNotFollowTargetSymlinkDirectories(t *testing.T) {
src, dst, outside, scratch := t.TempDir(), t.TempDir(), t.TempDir(), t.TempDir()
if err := os.Mkdir(filepath.Join(src, "d"), 0700); err != nil {
t.Fatal(err)
}
mustWrite(t, filepath.Join(src, "d", "a"))
mustWrite(t, filepath.Join(src, "d", "b"))
mustWrite(t, filepath.Join(outside, "a"))
if err := os.Link(filepath.Join(outside, "a"), filepath.Join(outside, "b")); err != nil {
t.Fatal(err)
}
if err := os.Symlink(outside, filepath.Join(dst, "d")); err != nil {
t.Fatal(err)
}
if err := hardlinkTopology(context.Background(), src, dst, scratch, true); err != nil {
t.Fatal(err)
}
a, err := os.Stat(filepath.Join(outside, "a"))
if err != nil {
t.Fatal(err)
}
b, err := os.Stat(filepath.Join(outside, "b"))
if err != nil || !os.SameFile(a, b) {
t.Fatal("repair touched files outside the target tree")
}
}
func TestHardlinkDiskIndexSurvivesBatchBoundaries(t *testing.T) {
x, err := openLinkIndex(filepath.Join(t.TempDir(), "index"))
if err != nil {
-235
View File
@@ -3,22 +3,13 @@
package migration
import (
"bufio"
"context"
"errors"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"strings"
"syscall"
)
func unescapeMount(s string) string {
return strings.NewReplacer("\\040", " ", "\\011", "\t", "\\012", "\n", "\\134", "\\").Replace(s)
}
func privateDirectories(path string) error {
if !filepath.IsAbs(path) {
return errors.New("directory path must be absolute")
@@ -47,229 +38,3 @@ func privateDirectories(path string) error {
return nil
}
func checkMount(root string, writable bool) error {
f, err := os.Open("/proc/self/mountinfo")
if err != nil {
return err
}
defer f.Close()
scan := bufio.NewScanner(f)
found := false
for scan.Scan() {
parts := strings.SplitN(scan.Text(), " - ", 2)
if len(parts) != 2 {
continue
}
fields, after := strings.Fields(parts[0]), strings.Fields(parts[1])
if len(fields) < 6 || len(after) < 2 {
continue
}
mount := unescapeMount(fields[4])
if mount == root {
if after[0] != "ceph" && after[0] != "fuse.ceph-fuse" {
return fmt.Errorf("%s is not a CephFS mount", root)
}
if writable && !strings.Contains(","+fields[5]+",", ",rw,") {
return fmt.Errorf("target %s must be mounted read-write", root)
}
found = true
} else if beneath(root, mount) {
return fmt.Errorf("nested mount %s below %s is unsupported", mount, root)
}
}
if err := scan.Err(); err != nil {
return err
}
if !found {
return fmt.Errorf("%s must be a dedicated CephFS filesystem-root mount", root)
}
resolved, err := filepath.EvalSymlinks(root)
if err != nil {
return err
}
if resolved != root {
return errors.New("mount path must not contain symlinks")
}
return nil
}
func xattr(path, key string) ([]byte, error) {
for attempt := 0; attempt < 3; attempt++ {
n, err := syscall.Getxattr(path, key, nil)
if errors.Is(err, syscall.ENODATA) {
return []byte("0"), nil
}
if err != nil {
return nil, err
}
if n > 1<<20 {
return nil, fmt.Errorf("xattr too large: %s", key)
}
b := make([]byte, n)
n, err = syscall.Getxattr(path, key, b)
if errors.Is(err, syscall.ERANGE) {
continue
}
if err != nil {
return nil, err
}
return b[:n], nil
}
return nil, errors.New("xattr changed repeatedly")
}
var quotaKeys = []string{"ceph.quota.max_bytes", "ceph.quota.max_files"}
// walkDirectories calls visit for every directory below root.
func walkDirectories(ctx context.Context, root string, visit func(string) error) error {
return walkTree(ctx, root, visit, nil)
}
// walkTree walks root depth-first, skipping .snap. ReadDir batches keep a
// single very large directory from exhausting memory.
func walkTree(ctx context.Context, root string, visitDir func(string) error, visitFile func(string, os.FileInfo) error) error {
var walk func(string, int) error
walk = func(path string, depth int) error {
if err := ctx.Err(); err != nil {
return err
}
if depth > 128 {
return errors.New("directory depth exceeds supported limit (128)")
}
if visitDir != nil {
if err := visitDir(path); errors.Is(err, fs.SkipDir) {
return nil
} else if err != nil {
return err
}
}
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
for {
batch, readErr := f.ReadDir(128)
for _, e := range batch {
if err := ctx.Err(); err != nil {
return err
}
if e.Name() == ".snap" {
continue
}
child := filepath.Join(path, e.Name())
if e.IsDir() {
if err := walk(child, depth+1); err != nil {
return err
}
} else if visitFile != nil {
info, err := e.Info()
if err != nil {
return err
}
if err = visitFile(child, info); err != nil {
return err
}
}
}
if errors.Is(readErr, io.EOF) {
return nil
}
if readErr != nil {
return readErr
}
}
}
return walk(root, 0)
}
func clearQuotas(ctx context.Context, root string) error {
return walkDirectories(ctx, root, func(path string) error {
for _, key := range quotaKeys {
old, err := xattr(path, key)
if err != nil {
return fmt.Errorf("read quota %s: %w", path, err)
}
if string(old) == "0" {
continue
}
if err := syscall.Setxattr(path, key, []byte("0"), 0); err != nil {
return fmt.Errorf("clear quota %s: %w", path, err)
}
}
return nil
})
}
func quotas(ctx context.Context, src, dst string, verify bool) error {
return walkDirectories(ctx, src, func(path string) error {
rel, err := filepath.Rel(src, path)
if err != nil {
return err
}
target := filepath.Join(dst, rel)
st, err := os.Lstat(target)
if err != nil {
return err
}
if !st.IsDir() {
return fmt.Errorf("quota target is not a real directory: %s", target)
}
for _, key := range quotaKeys {
value, err := xattr(path, key)
if err != nil {
return fmt.Errorf("source quota %s %s: %w", path, key, err)
}
actual, err := xattr(target, key)
if err != nil {
return fmt.Errorf("target quota %s %s: %w", target, key, err)
}
if string(value) == string(actual) {
continue
}
if verify {
return fmt.Errorf("quota mismatch: %s %s", rel, key)
}
if err := syscall.Setxattr(target, key, value, 0); err != nil {
return fmt.Errorf("set quota %s %s: %w", target, key, err)
}
}
return nil
})
}
+3 -3
View File
@@ -23,12 +23,12 @@ func (a nativeAccess) Inspect(ctx context.Context, c Config, x Executor) (*Inspe
return nil, err
}
sf, si, err := queryEndpoint(ctx, ceph{endpoint: c.Source, exec: x, native: true})
sf, si, err := queryEndpoint(ctx, ceph{endpoint: c.Source, exec: x})
if err != nil {
return nil, err
}
tf, ti, err := queryEndpoint(ctx, ceph{endpoint: c.Target, exec: x, native: true})
tf, ti, err := queryEndpoint(ctx, ceph{endpoint: c.Target, exec: x})
if err != nil {
return nil, err
}
@@ -59,7 +59,7 @@ func (a nativeAccess) Inspect(ctx context.Context, c Config, x Executor) (*Inspe
}
}
names, err := (ceph{endpoint: c.Source, exec: x, native: true}).names(ctx)
names, err := (ceph{endpoint: c.Source, exec: x}).names(ctx)
if err != nil {
return nil, err
}
+126
View File
@@ -0,0 +1,126 @@
package migration
import (
"context"
"errors"
"os"
"path/filepath"
"syscall"
"testing"
"git.zb-server.de/Sebi/CephfsMig/internal/storage"
)
// rootFS is a storage.FS rooted at a local directory, with real flock
// locks, for the claim operations.
type rootFS struct {
storage.FS
root string
}
func (f rootFS) path(p string) string { return filepath.Join(f.root, p) }
func (f rootFS) Stat(p string) (storage.Node, error) { return diskFS{}.Stat(f.path(p)) }
func (f rootFS) Mkdir(p string, mode uint32) error { return os.Mkdir(f.path(p), os.FileMode(mode)) }
func (f rootFS) Unlink(p string) error { return syscall.Unlink(f.path(p)) }
func (f rootFS) Rmdir(p string) error { return syscall.Rmdir(f.path(p)) }
func (f rootFS) Close() error { return nil }
func (f rootFS) Open(p string, flags int, mode uint32) (storage.File, error) {
file, err := os.OpenFile(f.path(p), flags, os.FileMode(mode))
if err != nil {
return nil, err
}
return lockingFile{diskFile{file}}, nil
}
type lockingFile struct{ diskFile }
func (f lockingFile) Lock(uint64) error {
return syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB)
}
func claimAccess(root string) nativeAccess {
fs := rootFS{root: root}
return nativeAccess{&nativeTransport{target: fs, openTarget: func() (storage.FS, error) { return fs, nil }}}
}
func TestNativeClaimExcludesOtherJobsAndSurvivesStateLoss(t *testing.T) {
ctx, c := context.Background(), testConfig()
a := claimAccess(t.TempDir())
first, err := a.Claim(ctx, c, "fsid", "job-one")
if err != nil {
t.Fatal(err)
}
if second, err := a.Claim(ctx, c, "fsid", "job-one"); err == nil {
second.Close()
t.Fatal("concurrent use allowed")
}
if err := first.Close(); err != nil {
t.Fatal(err)
}
if other, err := a.Claim(ctx, c, "fsid", "job-two"); err == nil {
other.Close()
t.Fatal("different job stole target")
}
resumed, err := a.Claim(ctx, c, "fsid", "job-one")
if err != nil {
t.Fatal(err)
}
resumed.Close()
}
func TestNativeReleaseRemovesOnlyOwnClaim(t *testing.T) {
ctx, root := context.Background(), t.TempDir()
a := claimAccess(root)
c := testConfig()
other := c
other.Target.Subvolume = "other"
for _, x := range []struct {
c Config
id string
}{{c, "job-one"}, {other, "job-two"}} {
f, err := a.Claim(ctx, x.c, "fsid", x.id)
if err != nil {
t.Fatal(err)
}
f.Close()
}
if err := a.Release(ctx, c, "fsid", "job-two"); err == nil {
t.Fatal("removed the claim of a different job")
}
if err := a.Release(ctx, c, "fsid", "job-one"); err != nil {
t.Fatal(err)
}
claims := filepath.Join(root, ".cephmig", "claims")
if _, err := os.Stat(filepath.Join(claims, claimName("fsid", c.Target))); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("own claim still present: %v", err)
}
if _, err := os.Stat(filepath.Join(claims, claimName("fsid", other.Target))); err != nil {
t.Fatalf("claim of another job removed: %v", err)
}
if err := a.Release(ctx, other, "fsid", "job-two"); err != nil {
t.Fatal(err)
}
if _, err := os.Stat(filepath.Join(root, ".cephmig")); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("empty claim directories kept: %v", err)
}
// Releasing again is a no-op.
if err := a.Release(ctx, c, "fsid", "job-one"); err != nil {
t.Fatal(err)
}
}
+3
View File
@@ -18,6 +18,9 @@ import (
// the entries below it.
var errSkipSubtree = errors.New("skip subtree")
// quotaKeys are the directory quota xattrs that the migration copies.
var quotaKeys = []string{"ceph.quota.max_bytes", "ceph.quota.max_files"}
func walkNative(ctx context.Context, fs storage.FS, root string, visit func(string, storage.Node, int) error) error {
var walk func(string, storage.Node, int) error
walk = func(p string, n storage.Node, depth int) error {
+27
View File
@@ -0,0 +1,27 @@
package migration
import (
"context"
"io"
"testing"
"time"
)
func TestProcessCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.Canceled {
t.Fatalf("got %v", err)
}
ctx, cancel = context.WithTimeout(context.Background(), 50*time.Millisecond)
defer cancel()
start := time.Now()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.DeadlineExceeded {
t.Fatalf("got %v", err)
}
if time.Since(start) > 2*time.Second {
t.Fatal("cancellation was too slow")
}
}
-82
View File
@@ -1,82 +0,0 @@
package migration
import (
"context"
"errors"
"fmt"
"io"
"os/exec"
"strconv"
"strings"
)
// Transport copies a snapshot tree to the target and verifies the result.
type Transport interface {
Copy(context.Context, string, string) error
Verify(context.Context, string, string) error
}
// Rsync is the Transport that copies between mounted CephFS trees with
// rsync. BandwidthKiB limits the transfer rate when positive.
type Rsync struct {
Exec Executor
Log io.Writer
BandwidthKiB int64
}
func (r Rsync) args(src, dst string) []string {
a := []string{"-aHAXS", "--numeric-ids", "--checksum", "--no-whole-file",
"--delete-during", "--partial", "--fsync", "--one-file-system",
"--filter=- .snap/", "--filter=-x ceph.*", "--filter=-x system.*"}
if r.BandwidthKiB > 0 {
a = append(a, "--bwlimit="+strconv.FormatInt(r.BandwidthKiB, 10))
}
return append(a, "--", src+"/", dst+"/")
}
// Copy mirrors src into dst, including hard links, ACLs and xattrs.
func (r Rsync) Copy(ctx context.Context, src, dst string) error {
for attempt := 0; attempt < 2; attempt++ {
err := r.Exec.Exec(ctx, r.Log, "rsync", r.args(src, dst)...)
var processError *ProcessError
var exitError *exec.ExitError
// EEXIST was observed on Ceph-FUSE while rsync rebuilt a hardlink group.
// One idempotent retry repairs the partial group. All other errors
// are returned immediately; publication still requires full verification.
if attempt == 0 && errors.As(err, &processError) && errors.As(err, &exitError) && exitError.ExitCode() == 23 && strings.Contains(processError.Diagnostic, "link ") && strings.Contains(processError.Diagnostic, "File exists (17)") {
if r.Log != nil {
fmt.Fprintln(r.Log, "rsync hardlink EEXIST: retrying once before snapshot verification")
}
continue
}
return err
}
return errors.New("rsync retry limit reached")
}
type differences struct{ n int64 }
func (d *differences) Write(p []byte) (int, error) {
d.n += int64(len(p))
return len(p), nil
}
// Verify runs rsync as a dry run and fails if any difference remains.
func (r Rsync) Verify(ctx context.Context, src, dst string) error {
args := append([]string{"--dry-run", "--itemize-changes", "--out-format=%i"}, r.args(src, dst)...)
var d differences
if err := r.Exec.Exec(ctx, &d, "rsync", args...); err != nil {
return err
}
if d.n != 0 {
return fmt.Errorf("verification found differences between %s and %s", src, dst)
}
return nil
}
-172
View File
@@ -1,172 +0,0 @@
package migration
import (
"context"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"testing"
"time"
)
type executorFunc func(context.Context, io.Writer, string, ...string) error
func (f executorFunc) Exec(ctx context.Context, out io.Writer, name string, args ...string) error {
return f(ctx, out, name, args...)
}
func TestRsyncRetriesOnlyObservedHardlinkEEXIST(t *testing.T) {
exitErr := exec.Command("sh", "-c", "exit 23").Run()
for name, tc := range map[string]struct {
diagnostic string
attempts int
}{
"hardlink": {"link target failed: File exists (17)", 2},
"permission": {"Permission denied (13)", 1},
"other-eexist": {"mkdir failed: File exists (17)", 1},
} {
t.Run(name, func(t *testing.T) {
calls := 0
x := executorFunc(func(context.Context, io.Writer, string, ...string) error {
calls++
if calls == 1 {
return &ProcessError{Name: "rsync", Err: exitErr, Diagnostic: tc.diagnostic}
}
return nil
})
err := (Rsync{Exec: x, Log: io.Discard}).Copy(context.Background(), "/a", "/b")
if calls != tc.attempts {
t.Fatalf("attempts: %d", calls)
}
if (err == nil) != (tc.attempts == 2) {
t.Fatalf("unexpected result: %v", err)
}
})
}
calls := 0
x := executorFunc(func(context.Context, io.Writer, string, ...string) error { calls++; return context.Canceled })
err := (Rsync{Exec: x}).Copy(context.Background(), "/a", "/b")
if !errors.Is(err, context.Canceled) || calls != 1 {
t.Fatalf("retried cancellation: %v, %d", err, calls)
}
}
func TestRsyncDetectsSameSizeSameMtimeAndPreservesLinks(t *testing.T) {
if _, err := exec.LookPath("rsync"); err != nil {
t.Skip("rsync is not installed")
}
src, dst := t.TempDir(), t.TempDir()
path := filepath.Join(src, "file with spaces\nand newline")
if err := os.WriteFile(path, []byte("AAAA"), 0640); err != nil {
t.Fatal(err)
}
if err := os.Link(path, filepath.Join(src, "hardlink")); err != nil {
t.Fatal(err)
}
if err := os.Symlink("nonexistent", filepath.Join(src, "dangling")); err != nil {
t.Fatal(err)
}
if err := syscall.Setxattr(path, "user.cephmig", []byte("test"), 0); err != nil {
t.Fatal(err)
}
r := Rsync{Exec: Process{Stderr: io.Discard}, Log: io.Discard}
ctx := context.Background()
if err := r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err := r.Verify(ctx, src, dst); err != nil {
t.Fatal(err)
}
a, _ := os.Stat(filepath.Join(dst, "hardlink"))
b, _ := os.Stat(filepath.Join(dst, filepath.Base(path)))
if !os.SameFile(a, b) {
t.Fatal("hardlinks were split")
}
st, err := os.Stat(path)
if err != nil {
t.Fatal(err)
}
if err = os.WriteFile(path, []byte("BBBB"), 0640); err != nil {
t.Fatal(err)
}
if err = os.Chtimes(path, st.ModTime(), st.ModTime()); err != nil {
t.Fatal(err)
}
if err = r.Verify(ctx, src, dst); err == nil {
t.Fatal("checksum verification missed changed bytes")
}
if err = os.WriteFile(filepath.Join(dst, "obsolete"), []byte("extra"), 0600); err != nil {
t.Fatal(err)
}
if err = r.Copy(ctx, src, dst); err != nil {
t.Fatal(err)
}
if err = r.Verify(ctx, src, dst); err != nil {
t.Fatal(err)
}
if _, err = os.Stat(filepath.Join(dst, "obsolete")); !os.IsNotExist(err) {
t.Fatal("obsolete target file survived")
}
got, err := xattr(filepath.Join(dst, "hardlink"), "user.cephmig")
if err != nil || string(got) != "test" {
t.Fatalf("xattr: %q, %v", got, err)
}
}
func TestProcessCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.Canceled {
t.Fatalf("got %v", err)
}
ctx, cancel = context.WithTimeout(context.Background(), 50*time.Millisecond)
defer cancel()
start := time.Now()
if err := (Process{Stderr: io.Discard}).Exec(ctx, io.Discard, "sleep", "60"); err != context.DeadlineExceeded {
t.Fatalf("got %v", err)
}
if time.Since(start) > 2*time.Second {
t.Fatal("cancellation was too slow")
}
}
func TestRsyncUsesIncrementalSafeOptions(t *testing.T) {
joined := strings.Join((Rsync{BandwidthKiB: 1024}).args("/source", "/target"), " ")
for _, required := range []string{"-aHAXS", "--checksum", "--delete-during", "--no-whole-file", "--fsync", "--bwlimit=1024", "--filter=-x ceph.*"} {
if !strings.Contains(joined, required) {
t.Fatalf("missing %s", required)
}
}
for _, bad := range []string{"--inplace", "--delete-before", "--delete-after", "--delay-updates"} {
if strings.Contains(joined, bad) {
t.Fatalf("unsafe option %s", bad)
}
}
}
-27
View File
@@ -115,33 +115,6 @@ func TestLockExclusionAndRelease(t *testing.T) {
third.Close()
}
func TestTargetClaimExcludesOtherJobsAndSurvivesStateLoss(t *testing.T) {
root := t.TempDir()
c := testConfig()
first, err := claimTarget(root, "fsid", c.Target, "job-one")
if err != nil {
t.Fatal(err)
}
if second, err := claimTarget(root, "fsid", c.Target, "job-one"); err == nil {
second.Close()
t.Fatal("concurrent use allowed")
}
first.Close()
if other, err := claimTarget(root, "fsid", c.Target, "job-two"); err == nil {
other.Close()
t.Fatal("different job stole target")
}
resumed, err := claimTarget(root, "fsid", c.Target, "job-one")
if err != nil {
t.Fatal(err)
}
resumed.Close()
}
func TestStateAndLockRejectSymlinks(t *testing.T) {
root := t.TempDir()
real := filepath.Join(root, "real")