feat: release the target claim in cleanup

cleanup now deletes the claim file under .cephmig/claims as its last
step, if it holds the job's own ID, and removes the claim directories
when they are empty. A cleaned-up job is finished: cleanup and finalize
do nothing and do not claim the target again, and sync is refused.

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 20:37:20 +01:00
1 parent 5f29328932
commit a6e7bbb17e
10 files changed
+218 -14

No files matched your search

+41 -2
View File
@@ -118,8 +118,7 @@ func (a nativeAccess) Claim(ctx context.Context, c Config, fsid, id string) (io.
}
}
sum := sha256.Sum256([]byte(fsid + "\x00" + c.Target.Filesystem + "\x00" + c.Target.Group + "\x00" + c.Target.Subvolume))
p := path.Join(current, hex.EncodeToString(sum[:]))
p := path.Join(current, claimName(fsid, c.Target))
f, err := fs.Open(p, syscall.O_CREAT|syscall.O_EXCL|syscall.O_RDWR|syscall.O_NOFOLLOW, 0600)
if err == nil {
if err = writeNativeAt(f, []byte(id+"\n"), 0); err == nil {
@@ -171,6 +170,46 @@ func (a nativeAccess) Claim(ctx context.Context, c Config, fsid, id string) (io.
return f, nil
}
func (a nativeAccess) Release(ctx context.Context, c Config, fsid, id string) error {
if err := ctx.Err(); err != nil {
return err
}
fs := a.backend.target
dir := "/.cephmig/claims"
p := path.Join(dir, claimName(fsid, c.Target))
f, err := fs.Open(p, syscall.O_RDONLY|syscall.O_NOFOLLOW, 0)
if errors.Is(err, syscall.ENOENT) {
return nil
}
if err != nil {
return err
}
b := make([]byte, 256)
n, err := f.ReadAt(b, 0)
f.Close()
if err != nil && !errors.Is(err, io.EOF) {
return err
}
if string(b[:n]) != id+"\n" {
return errors.New("native target claim belongs to a different job; not removed")
}
if err = fs.Unlink(p); err != nil {
return err
}
for _, d := range []string{dir, "/.cephmig"} {
if err := fs.Rmdir(d); err != nil && !errors.Is(err, syscall.ENOENT) && !errors.Is(err, syscall.ENOTEMPTY) {
return err
}
}
return nil
}
func (a nativeAccess) Prepare(ctx context.Context, _, target, _ string) error {
return clearNativeQuotas(ctx, a.backend.target, target)
}