Skip to content

Make the setAtime* test helpers move whole timespecs - #586

Merged
smessmer merged 2 commits into
feature/fuse3from
fix/atime-test-helpers
Sep 7, 2026
Merged

smessmer merged 2 commits into
feature/fuse3from
fix/atime-test-helpers

Conversation

@smessmer

@smessmer smessmer commented Sep 6, 2026

Copy link
Copy Markdown
Member

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-10 job:

CryFS/FsppOpenFileTest_Timestamps/0.givenAtimeNewerThanMtime_read_outofbounds
TimestampTestUtils.h:175: Expected equality of these values:
  statBeforeOperation.atime   1788692363.029810
  statAfterOperation.atime    1788692364.110249

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, leaving tv_sec alone:

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;

That establishes the promised ordering only while atime and mtime already share a second.

givenAtimeNewerThanMtime_read_* calls CreateFileWithSize, 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. setAtimeNewerThanMtime then fixes up only the nanoseconds and leaves atime a second behind mtime — the opposite of its name. relatime's oldATime < oldMTime rule 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:

  • setAtimeOlderThanMtime has the mirror-image bug — 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 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: +1 on 999999999 yields an out-of-range tv_nsec of 1000000000, and -1 on 0 yields -1.

The change

Each helper now derives one timestamp from the other as a whole timespec, via plusOneNanosecond/minusOneNanosecond, which carry into tv_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:

Before the fix After
The 9 new tests (3 × file/dir/symlink) 9 failed 9 passed
givenAtime* suite passes (the race is timing-dependent) passes
cryfs-test overall 723 passed 732 passed

The "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 .cpp files — header-only fixtures.
  • src/fspp/CMakeLists.txt builds only fs_interface and fuse; fstest is never added.
  • The only thing that includes these headers anywhere is test/cryfs/impl/filesystem/FileSystemTest.cpp.
  • The tv_nsec-only pattern appears nowhere outside fstest/.

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

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

smessmer commented Sep 6, 2026

Copy link
Copy Markdown
Member Author

The failing CI (macos-*) jobs are not this PR's. This PR touches only two test headers under src/fspp/fstest/; the failure is a build error in src/fspp/fuse/Fuse.cpp, which it does not go near.

src/fspp/fuse/Fuse.cpp:194:41: error: unknown type name 'FUSE_OFF_T'
  (also 198, 247, 251, 295)

What is happening. FUSE_OFF_T is defined only by Dokany's headers — I checked, and it appears in none of libfuse 3.9.0, 3.14.0, 3.17.2 or macFUSE 3.18.2. Line 194 sits inside the FUSE 2 branch that #578 added for Windows (#if FUSE_MAJOR_VERSION >= 3 at 185, #else at 192, #endif at 201). macOS reaches that branch because src/fspp/fuse/CMakeLists.txt:45 still resolves the pkg-config module fuse on Darwin, which is macFUSE's libFUSE 2.9, so FUSE_MAJOR_VERSION is 2 there and the Windows-only path gets compiled with headers that have no FUSE_OFF_T.

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 (fuse_readdir_flags, fuse_config, incompatible function pointer types); now it fails earlier and differently, on a type that only exists in Dokany's world.

The fix is #577, which is open. It replaces the Darwin branch with pkg_check_modules(Fuse3 IMPORTED_TARGET "fuse3>=3.9"), so macOS links libFUSE 3, FUSE_MAJOR_VERSION becomes 3, and the FUSE 2 branch is never compiled there. It also adds an #error guard that would have said this plainly instead of failing on an unknown type.

I have deliberately not ported that change into this pull request. It is a platform fix to CMake and params.h that belongs in one place, and copying it into an unrelated test-helper change would duplicate an open pull request and make both harder to review. The Linux and Windows jobs are the ones that exercise this change.

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.
@smessmer
smessmer merged commit 7f77ddf into feature/fuse3 Sep 7, 2026
@smessmer
smessmer deleted the fix/atime-test-helpers branch September 7, 2026 02:15
smessmer pushed a commit that referenced this pull request Sep 7, 2026
Picks up #577 (macOS libFUSE 3), #586 and #589 (the unreleased section is
1.1.0 now, which the changelog entry in this branch has to go under).
smessmer added a commit that referenced this pull request Sep 7, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants