Repository navigation
Make the setAtime* test helpers move whole timespecs - #586
Conversation
The three helpers that arrange a node's atime relative to its mtime each
patched only tv_nsec and left tv_sec alone, so they established the ordering
they promise only while atime and mtime already happened to be in the same
second.
setAtimeOlderThanMtime: st.atime.tv_nsec = st.mtime.tv_nsec - 1;
setAtimeNewerThanMtime: st.atime.tv_nsec = st.mtime.tv_nsec + 1;
...ButBeforeYesterday: st.atime = before_yesterday;
st.mtime.tv_nsec = st.atime.tv_nsec - 1;
This is what has been failing intermittently in CI:
CryFS/FsppOpenFileTest_Timestamps/0.givenAtimeNewerThanMtime_read_outofbounds
TimestampTestUtils.h:175: Expected equality of these values:
statBeforeOperation.atime 1788692363.029810
statAfterOperation.atime 1788692364.110249
givenAtimeNewerThanMtime_read_* first calls CreateFileWithSize, which creates
the file and then truncates it. The truncate moves mtime but not atime, so when
those two operations straddle a second boundary mtime ends up a whole second
ahead. setAtimeNewerThanMtime then fixes up only the nanoseconds and leaves
atime a second behind mtime - the opposite of its name. relatime's
"oldATime < oldMTime" rule correctly updates atime on the following read, and
the test that asserts atime does not move fails. The window is however long the
create and truncate take, which is why it fired rarely and looked like a flake.
setAtimeOlderThanMtime has the mirror-image defect, so far unobserved but
equally reachable. setAtimeNewerThanMtimeButBeforeYesterday is wrong in a third
way: it sets atime to a full timespec near yesterday but patches only
mtime.tv_nsec, leaving mtime.tv_sec at roughly now, so atime comes out older
than mtime rather than newer. Its tests pass anyway, because atime being more
than 24 hours old makes relatime update it either way - the right answer for the
wrong reason.
Both nanosecond adjustments were also unnormalised: +1 on 999999999 produces an
out-of-range tv_nsec of 1000000000, and -1 on 0 produces -1.
So each helper now derives one timestamp from the other as a whole timespec,
through plusOneNanosecond/minusOneNanosecond, which carry into tv_sec.
Three regression tests pin the case that used to come out backwards, by putting
atime and mtime a second apart before calling the helper. They run for file,
directory and symlink nodes. Verified they fail on the current helpers and pass
after: 9 failed before, 9 passed after, and cryfs-test as a whole goes from 723
to 732 passing.
This is test-only and needs no ChangeLog entry. src/fspp/fstest contains no .cpp
files, src/fspp/CMakeLists.txt builds only fs_interface and fuse, and the only
thing that includes these headers is test/cryfs/impl/filesystem/FileSystemTest.cpp,
so no released binary can contain this code. The same tv_nsec-only pattern does
not appear anywhere outside fstest.
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_015ErTwCwE5TPLj5VL3PDKhP
|
The failing What is happening. So this is the branch's known macOS breakage wearing a new hat. Before #578 landed, macOS failed with the FUSE 2/3 signature mismatches ( The fix is #577, which is open. It replaces the Darwin branch with I have deliberately not ported that change into this pull request. It is a platform fix to CMake and I have not re-run the macOS jobs, because this is a deterministic compile error rather than an intermittent one. Generated by Claude Code |
The macOS jobs on this branch were failing to build with 'unknown type name FUSE_OFF_T', because the base branch still resolved pkg-config module 'fuse' on Darwin, which is macFUSE's libFUSE 2.9, so macOS compiled the FUSE 2 code path meant for Dokany. #577 fixed that on the base. Merging it in so CI runs these tests against a base that builds on macOS.
The three helpers that arrange a node's atime relative to its mtime each
patched only tv_nsec and left tv_sec alone, so they established the ordering
they promise only while atime and mtime already happened to be in the same
second.
setAtimeOlderThanMtime: st.atime.tv_nsec = st.mtime.tv_nsec - 1;
setAtimeNewerThanMtime: st.atime.tv_nsec = st.mtime.tv_nsec + 1;
...ButBeforeYesterday: st.atime = before_yesterday;
st.mtime.tv_nsec = st.atime.tv_nsec - 1;
This is what has been failing intermittently in CI:
CryFS/FsppOpenFileTest_Timestamps/0.givenAtimeNewerThanMtime_read_outofbounds
TimestampTestUtils.h:175: Expected equality of these values:
statBeforeOperation.atime 1788692363.029810
statAfterOperation.atime 1788692364.110249
givenAtimeNewerThanMtime_read_* first calls CreateFileWithSize, which creates
the file and then truncates it. The truncate moves mtime but not atime, so when
those two operations straddle a second boundary mtime ends up a whole second
ahead. setAtimeNewerThanMtime then fixes up only the nanoseconds and leaves
atime a second behind mtime - the opposite of its name. relatime's
"oldATime < oldMTime" rule correctly updates atime on the following read, and
the test that asserts atime does not move fails. The window is however long the
create and truncate take, which is why it fired rarely and looked like a flake.
setAtimeOlderThanMtime has the mirror-image defect, so far unobserved but
equally reachable. setAtimeNewerThanMtimeButBeforeYesterday is wrong in a third
way: it sets atime to a full timespec near yesterday but patches only
mtime.tv_nsec, leaving mtime.tv_sec at roughly now, so atime comes out older
than mtime rather than newer. Its tests pass anyway, because atime being more
than 24 hours old makes relatime update it either way - the right answer for the
wrong reason.
Both nanosecond adjustments were also unnormalised: +1 on 999999999 produces an
out-of-range tv_nsec of 1000000000, and -1 on 0 produces -1.
So each helper now derives one timestamp from the other as a whole timespec,
through plusOneNanosecond/minusOneNanosecond, which carry into tv_sec.
Three regression tests pin the case that used to come out backwards, by putting
atime and mtime a second apart before calling the helper. They run for file,
directory and symlink nodes. Verified they fail on the current helpers and pass
after: 9 failed before, 9 passed after, and cryfs-test as a whole goes from 723
to 732 passing.
This is test-only and needs no ChangeLog entry. src/fspp/fstest contains no .cpp
files, src/fspp/CMakeLists.txt builds only fs_interface and fuse, and the only
thing that includes these headers is test/cryfs/impl/filesystem/FileSystemTest.cpp,
so no released binary can contain this code. The same tv_nsec-only pattern does
not appear anywhere outside fstest.
Claude-Session: https://claude.ai/code/session_015ErTwCwE5TPLj5VL3PDKhP
Co-authored-by: Claude <[email protected]>
This is the intermittent atime failure that has been showing up in CI on unrelated pull requests, for example on #576's
ubuntu-24.04 / Debug / gcc-10job:atime moved forward by exactly one second, with fresh nanoseconds — i.e. relatime really did update it, in a test asserting it would not.
Root cause
The three helpers that arrange a node's atime relative to its mtime each patched only
tv_nsec, leavingtv_secalone:That establishes the promised ordering only while atime and mtime already share a second.
givenAtimeNewerThanMtime_read_*callsCreateFileWithSize, which creates the file and then truncates it. The truncate moves mtime but not atime, so when those two straddle a second boundary mtime ends up a whole second ahead.setAtimeNewerThanMtimethen fixes up only the nanoseconds and leaves atime a second behind mtime — the opposite of its name. relatime'soldATime < oldMTimerule then correctly updates atime on the following read, and the assertion fails. The window is however long create-then-truncate takes, which is why it fired rarely and read as a flake.Two more defects fall out of the same pattern:
setAtimeOlderThanMtimehas the mirror-image bug — so far unobserved, but equally reachable.setAtimeNewerThanMtimeButBeforeYesterdayis wrong in a third way: it sets atime to a full timespec near yesterday but patches onlymtime.tv_nsec, leavingmtime.tv_secat roughly now, so atime comes out older than mtime rather than newer. Its tests pass regardless, because atime being more than 24 hours old makes relatime update it either way — the right answer for the wrong reason. The new tests confirm this: it fails all three node types before this change.Both nanosecond adjustments were also unnormalised:
+1on999999999yields an out-of-rangetv_nsecof1000000000, and-1on0yields-1.The change
Each helper now derives one timestamp from the other as a whole timespec, via
plusOneNanosecond/minusOneNanosecond, which carry intotv_sec.Tests
Three regression tests pin exactly the case that used to come out backwards, by putting atime and mtime a second apart before calling the helper. They run for file, directory and symlink nodes.
Verified both directions rather than assumed:
givenAtime*suitecryfs-testoverallThe "before" figure comes from building with the new tests against the unmodified helpers, so they are demonstrably capable of failing.
No ChangeLog entry
This is test-only, and I checked rather than assumed:
src/fspp/fstest/contains zero.cppfiles — header-only fixtures.src/fspp/CMakeLists.txtbuilds onlyfs_interfaceandfuse;fstestis never added.test/cryfs/impl/filesystem/FileSystemTest.cpp.tv_nsec-only pattern appears nowhere outsidefstest/.No shipped binary can contain this code, so no released version can exhibit the bug.
🤖 Generated with Claude Code
https://claude.ai/code/session_015ErTwCwE5TPLj5VL3PDKhP
Generated by Claude Code