feat(native): preserve ctime of files, directories and symlinks
The MDS takes an inode's ctime from the time stamp the client sends with each request. The native backend overrides clock_gettime per thread and per libcephfs call: modifying calls run at 1970-01-01T00:00:01Z, and the last change to each entry creates and removes the xattr user.cephmig.ctime stamped with the source ctime. Link, unlink, rename and xattr requests set ctime = max(stamp, mtime), also backwards. - write xattrs and quotas before SetAttr, which must come last - always restamp directories after their children and hardlinks after linking or pruning, since the writer's cache may be stale - verify through a separate, freshly mounted target client - name the differing attributes in metadata mismatch errors - compare ctime of every entry, the root included, in the lab fixture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
02ebc08c88
commit
cc2dff46a0
11 files changed
+491
-96
No files matched your search
@@ -25,8 +25,15 @@ const nativeBlockThreshold = 16 << 20
|
||||
type nativeTransport struct {
|
||||
source, target storage.FS
|
||||
config Config
|
||||
log io.Writer
|
||||
identity string
|
||||
|
||||
// openVerifier opens a separate client of the target for Verify. The
|
||||
// writing client may cache a ctime that differs from the MDS, so only a
|
||||
// client without caps of its own sees what other clients see. Nil means
|
||||
// verify through target.
|
||||
openVerifier func() (storage.FS, error)
|
||||
|
||||
log io.Writer
|
||||
identity string
|
||||
|
||||
// State of the current round.
|
||||
round Round
|
||||
@@ -393,7 +400,14 @@ func (b *nativeTransport) Copy(ctx context.Context, from, to string) error {
|
||||
return fmt.Errorf("native hardlink %s -> %s: %w", string(k), string(v), err)
|
||||
}
|
||||
|
||||
return nil
|
||||
// Linking resets the ctime of the inode; set it again.
|
||||
src := path.Join(from, string(k))
|
||||
n, err := b.source.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return restoreNativeMetadata(b.source, b.target, src, dst, n)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -403,6 +417,9 @@ func (b *nativeTransport) Copy(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
// Child creation/deletion has finished; restore directory metadata last.
|
||||
// Creating or removing a child sets the ctime of its directory on the
|
||||
// MDS, while the cache of this client may keep the old value, so the
|
||||
// cached stat cannot tell whether a directory is current.
|
||||
if err = b.pending.each("dirs", true, func(_, v []byte) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
@@ -415,7 +432,7 @@ func (b *nativeTransport) Copy(ctx context.Context, from, to string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return syncNativeMetadata(b.source, b.target, src, dst, n, false)
|
||||
return restoreNativeMetadata(b.source, b.target, src, dst, n)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -469,7 +486,7 @@ func (b *nativeTransport) prune(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
// Store deletions on disk and apply after closing the directory streams.
|
||||
err := walkNative(ctx, b.target, to, func(p string, _ storage.Node, _ int) error {
|
||||
err := walkNative(ctx, b.target, to, func(p string, n storage.Node, _ int) error {
|
||||
rel, err := relativeNative(to, p)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -484,17 +501,70 @@ func (b *nativeTransport) prune(ctx context.Context, from, to string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !present {
|
||||
return b.pending.put("delete", []byte(rel), []byte{1})
|
||||
if present {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
// Removing one name of a hardlinked inode resets its ctime; the
|
||||
// remaining names are set again below.
|
||||
if n.Kind() != storage.Directory && n.Nlink > 1 {
|
||||
if err = b.pending.put("relinked", nativeInodeKey(n.Inode), []byte{1}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return b.pending.put("delete", []byte(rel), []byte{1})
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.pending.each("delete", true, func(k, _ []byte) error { return removeNative(ctx, b.target, path.Join(to, string(k))) })
|
||||
err = b.pending.each("delete", true, func(k, _ []byte) error {
|
||||
return removeNative(ctx, b.target, path.Join(to, string(k)))
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.restoreRelinked(from, to)
|
||||
}
|
||||
|
||||
// restoreRelinked sets the metadata of regular files again whose target inode
|
||||
// lost a name during pruning. The source inventory records the target inode
|
||||
// of every regular file copied in this round.
|
||||
func (b *nativeTransport) restoreRelinked(from, to string) error {
|
||||
inodes := map[uint64]bool{}
|
||||
if err := b.pending.each("relinked", false, func(k, _ []byte) error {
|
||||
inodes[binary.BigEndian.Uint64(k)] = true
|
||||
return nil
|
||||
}); err != nil || len(inodes) == 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
var rels []string
|
||||
if err := b.pending.each("paths", false, func(k, v []byte) error {
|
||||
if e, ok := decodeEntry(v); ok && e.TargetInode != 0 && inodes[e.TargetInode] {
|
||||
rels = append(rels, string(k))
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range rels {
|
||||
src := path.Join(from, rel)
|
||||
n, err := b.source.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = restoreNativeMetadata(b.source, b.target, src, path.Join(to, rel), n); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *nativeTransport) Published(p string) { b.verified[p] = true }
|
||||
|
||||
Reference in new issue
Block a user