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

+46
View File
@@ -12,6 +12,8 @@ import sys
import time
import uuid
import cephfs
def ceph(cluster, *args):
return subprocess.check_output([
@@ -122,6 +124,48 @@ def compare(src, dst):
visit(src, dst)
def mount(cluster):
fs = cephfs.LibCephFS(conffile=f"/clusters/{cluster}/ceph.conf",
conf={"keyring": f"/clusters/{cluster}/ceph.client.admin.keyring"})
fs.mount(filesystem_name=b"cephfs")
return fs
def compare_times(src, dst, atime):
"""Compare times through libcephfs; FUSE does not expose the birth time.
The access time is only compared for immutable snapshots, because the FUSE
reads in compare() update it in the live trees."""
keys = ("atime", "mtime", "btime") if atime else ("mtime", "btime")
mask = cephfs.CEPH_STATX_BASIC_STATS | cephfs.CEPH_STATX_BTIME
fa, fb = mount("source"), mount("target")
def ceph_path(p, cluster):
prefix = f"/mnt/{cluster}-fs"
assert p.startswith(prefix + "/"), p
return p[len(prefix):].encode()
def visit(a, b):
x = fa.statx(a, mask, cephfs.AT_SYMLINK_NOFOLLOW)
y = fb.statx(b, mask, cephfs.AT_SYMLINK_NOFOLLOW)
assert {k: x[k] for k in keys} == {k: y[k] for k in keys}, (a, x, y)
if not stat.S_ISDIR(x["mode"]):
return 1
d = fa.opendir(a)
names = []
while entry := fa.readdir(d):
if entry.d_name not in (b".", b"..", b".snap"):
names.append(entry.d_name)
fa.closedir(d)
return 1 + sum(visit(a + b"/" + n, b + b"/" + n) for n in names)
try:
return visit(ceph_path(src, "source"), ceph_path(dst, "target"))
finally:
fa.unmount()
fb.unmount()
action = sys.argv[1]
if action == "setup":
name = "native-itest-" + str(uuid.uuid4())
@@ -201,12 +245,14 @@ elif action == "mutate":
elif action in ("verify", "final"):
roots = json.load(open(fixture))
compare(roots["source"], roots["target"])
compare_times(roots["source"], roots["target"], atime=False)
s = json.load(open(state))
for snap in s["snapshots"]:
assert snap["done"], snap
a, b = [f"/mnt/{c}-fs" + ceph(c, "fs", "subvolume", "snapshot", "getpath",
"cephfs", name, snap["name"], "migration") for c in ("source", "target")]
compare(a, b)
assert compare_times(a, b, atime=True) > 10
assert snapshot("source", "metadata", "ls", "cephfs", name, snap["name"]) == snapshot(
"target", "metadata", "ls", "cephfs", name, snap["name"])
h2 = next(x for x in s["snapshots"] if x["name"] == "history-2")["transfer"]