feat(native): preserve access and birth time of every entry

Read atime and btime with statx and set them together with owner,
mode and mtime. Verification compares both, so a published snapshot
must match the source in all three times. The integration fixture
compares the times through libcephfs, since ceph-fuse does not expose
the birth time.

The ctime cannot be preserved: Ceph 21.2.0 accepts CEPH_SETATTR_CTIME
but stores the time of the call. The rsync backend still preserves
only the mtime.

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 18:48:25 +01:00
1 parent a6fda8f8d3
commit 02ebc08c88
7 files changed
+137 -19

No files matched your search

+28 -9
View File
@@ -16,20 +16,28 @@ package cephfsnative
static int cm_stat(struct ceph_mount_info *m, const char *p, struct ceph_statx *s, int flags)
{
return ceph_statx(m, p, s, CEPH_STATX_BASIC_STATS | CEPH_STATX_VERSION, flags);
return ceph_statx(m, p, s, CEPH_STATX_BASIC_STATS | CEPH_STATX_VERSION | CEPH_STATX_BTIME, flags);
}
// cm_attr sets owner, mode and the access, modification and birth times.
// t holds seconds and nanoseconds for atime, mtime and btime in this order.
// The change time cannot be set: the MDS always records the time of the call.
static int cm_attr(struct ceph_mount_info *m, const char *p, unsigned mode, unsigned uid,
unsigned gid, long sec, long nsec)
unsigned gid, const long *t)
{
struct ceph_statx s = {0};
s.stx_mode = mode;
s.stx_uid = uid;
s.stx_gid = gid;
s.stx_mtime.tv_sec = sec;
s.stx_mtime.tv_nsec = nsec;
s.stx_atime.tv_sec = t[0];
s.stx_atime.tv_nsec = t[1];
s.stx_mtime.tv_sec = t[2];
s.stx_mtime.tv_nsec = t[3];
s.stx_btime.tv_sec = t[4];
s.stx_btime.tv_nsec = t[5];
int mask = CEPH_SETATTR_UID | CEPH_SETATTR_GID | CEPH_SETATTR_MTIME;
int mask = CEPH_SETATTR_UID | CEPH_SETATTR_GID | CEPH_SETATTR_ATIME |
CEPH_SETATTR_MTIME | CEPH_SETATTR_BTIME;
if ((mode & S_IFMT) != S_IFLNK)
mask |= CEPH_SETATTR_MODE;
return ceph_setattrx(m, p, &s, mask, AT_SYMLINK_NOFOLLOW);
@@ -159,7 +167,11 @@ func node(s C.struct_ceph_statx) storage.Node {
return storage.Node{Mode: uint32(s.stx_mode), Inode: uint64(s.stx_ino),
Version: uint64(s.stx_version), Nlink: uint64(s.stx_nlink), Size: uint64(s.stx_size),
Rdev: uint64(s.stx_rdev), UID: uint32(s.stx_uid), GID: uint32(s.stx_gid),
Mtime: time.Unix(int64(s.stx_mtime.tv_sec), int64(s.stx_mtime.tv_nsec))}
Atime: timespec(s.stx_atime), Mtime: timespec(s.stx_mtime), Btime: timespec(s.stx_btime)}
}
func timespec(t C.struct_timespec) time.Time {
return time.Unix(int64(t.tv_sec), int64(t.tv_nsec))
}
// Stat returns the attributes of path without following a final symlink.
@@ -282,7 +294,7 @@ func (d *dir) Next() (*storage.Entry, error) {
var entry C.struct_dirent
var s C.struct_ceph_statx
ret := C.ceph_readdirplus_r(d.client.mount, d.handle, &entry, &s,
C.CEPH_STATX_BASIC_STATS|C.CEPH_STATX_VERSION, C.uint(d.flags), nil)
C.CEPH_STATX_BASIC_STATS|C.CEPH_STATX_VERSION|C.CEPH_STATX_BTIME, C.uint(d.flags), nil)
if err := errno(ret); err != nil {
return nil, err
@@ -379,11 +391,18 @@ func (c *Client) Readlink(path string) (string, error) {
return "", errors.New("symlink target exceeds 1 MiB")
}
// SetAttr sets numeric owner, mode and mtime without following symlinks.
// SetAttr sets numeric owner, mode, atime, mtime and btime without following
// symlinks. The ctime cannot be set; Ceph records the time of the call.
func (c *Client) SetAttr(path string, n storage.Node) error {
p, f := str(path)
defer f()
return errno(C.cm_attr(c.mount, p, C.uint(n.Mode), C.uint(n.UID), C.uint(n.GID), C.long(n.Mtime.Unix()), C.long(n.Mtime.Nanosecond())))
times := [6]C.long{
C.long(n.Atime.Unix()), C.long(n.Atime.Nanosecond()),
C.long(n.Mtime.Unix()), C.long(n.Mtime.Nanosecond()),
C.long(n.Btime.Unix()), C.long(n.Btime.Nanosecond()),
}
return errno(C.cm_attr(c.mount, p, C.uint(n.Mode), C.uint(n.UID), C.uint(n.GID), &times[0]))
}
// GetXattr returns the value of an extended attribute.