Skip to content

nfs: serve real ._* files; let a user chmod through the refresh mark (review #8, #9) - #762

Merged
yifanxuaaa merged 2 commits into
layerfs_v2_0_0from
claude/v2-nfs-fixes-076fff
Nov 23, 2026
Merged

yifanxuaaa merged 2 commits into
layerfs_v2_0_0from
claude/v2-nfs-fixes-076fff

Conversation

@yifanxuaaa

Copy link
Copy Markdown
Contributor

Fixes two NFS-route findings from the LayerFS 2.0.0 overlay review (#8 / V-OV-3 and #9 / V-OV-4). I re-checked both in the code before fixing them, and both were real.

1. Real ._* files were hidden (finding #8)

Bug: with refuse_apple_double (the default), LOOKUP answered NFS3ERR_NOENT for every ._ name before it asked the engine. READDIR still listed the real ones, so a repository containing ._foo showed it in ls, but opening it failed.

Fix: a ._ name that the Workspace view holds is now an ordinary Workspace file.

  • LOOKUP asks the view first. It answers from a companion only when the view has no such name, so LOOKUP and READDIR now agree. GETATTR, READ, WRITE and SETATTR then reach the engine by serial.
  • CREATE of a name the view holds is the ordinary CREATE of that file:
    • UNCHECKED opens it; GUARDED and EXCLUSIVE answer EXIST.
    • No companion is made, so nothing shadows the real file.
    • The attributes a macOS client then stores there go into the Workspace file, as on any NFSv3 server.
    • This is the documented decision.
  • REMOVE removes the real file. RENAME may replace it. RENAME onto a ._ name the view does not hold is still ACCES.
  • Names the view does not hold use the export-memory companions, as before. If the view gains a companion's name later, the real file wins.
  • Cost: LOOKUP, CREATE, REMOVE and RENAME of a ._ name now each make one engine LOOKUP. That includes companion and absent names.
  • ⚠️ Changed test expectation: the job-count test in tests/write.rs asserted zero owner jobs for those calls. Zero jobs is the behaviour that hid real files. The test now expects exactly 2 and 3 observe visits, with 0 mutate visits.

2. The refresh mark swallowed a user's chmod (finding #9)

Bug: after a merged Commit, every stale serial was marked at once. For up to 30 s, any mode-only SETATTR on a marked serial did nothing, whatever mode it asked for. So chmod +x right after a Commit reported success and changed nothing.

Fix:

  • Server::refresh now returns (serial, path) pairs and marks nothing.
  • For each path, the refresh thread:
    • runs lstat through the mount, and skips a symlink, a vanished path, or a path that now names another inode;
    • marks that serial with exactly the mode it is about to ask (Refresher::arm, which holds a weak reference so it never blocks unmount);
    • then runs the chmod.
  • A mark is taken only by a mode-only SETATTR that asks the marked mode.
  • A client SETATTR asking another mode is applied. The refresh chmod that follows it is answered without a change, so it never overwrites the newer mode.
  • Residual case (documented): a client chmod to exactly the marked mode, sent in the microseconds between the mark and the refresh chmod, is answered unchanged. The refresh chmod that follows then applies that same mode.
  • Existing limits, now documented: the refresh is best effort, runs after the Commit reply and stops at 4,096 inodes.
  • ⚠️ Replaced test assertion: tests/refresh.rs asserted that a marked chmod to another mode is swallowed. That assertion was the bug itself, so it now checks the new contract.

Checks run (macOS, tools/worktree.py cargo, toolchain 1.85.1, each test target ≤100 s)

  • test -p layerfs-nfs -p layerfs-daemon --tests --no-run: ok
  • clippy -p layerfs-nfs -p layerfs-daemon --all-targets -D warnings: ok, at the final commit
  • cargo fmt --check: ok
  • layerfs-nfs test targets, all passing:
    • apple_double_view (new): 1
    • refresh: 1
    • write: 15
    • export: 10
    • apple_double_decode: 32
    • apple_double_codec: 7
    • protocol: 15
    • collect: 1
    • daemon: 2
    • helper_deadline: 9
    • mounter: 2
    • the layerfs-nfs and layerfs-daemon lib targets (0 tests each)

Gaps

  • No real macOS NFS mount was tested. No cheap, bounded mount test exists for this. The refresh thread's lstat → arm → chmod sequence through a real client is therefore covered only by the in-process export tests. Also unchecked: whether macOS st_ino equals the export fileid (the inode check depends on it).
  • No test for an expired mark. MARK_LIFE is 30 s.
  • No daemon integration tests ran beyond the compile.

Production LOC (range 343c59b..a10feaf)

Production LOC: 206,537 -> 206,624 (delta +87)
  core     40,988 -> 40,988 (0)
  engine   95,899 -> 95,986 (+87)  layerfs-daemon +5, layerfs-nfs +82
  control  59,325 -> 59,325 (0)
  api      10,325 -> 10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd1917812)
  Method: tools/production_loc.py --detail on 343c59b2ca and a10feafb1d

Each commit message has its own LOC block (+48 and +39).

🤖 Generated with Claude Code

yifanxuaaa and others added 2 commits November 23, 2026 14:18
With `refuse_apple_double` (the default), LOOKUP answered NFS3ERR_NOENT for
every `._` name before asking the engine, while READDIR listed the real ones:
a repository that contains `._foo` showed it in `ls` and then failed to open
it (review finding #8, V-OV-3).

A `._` name the Workspace view holds is now an ordinary Workspace file:
- LOOKUP of a `._` name asks the view first and answers a companion only
  when the view has no such name, so LOOKUP and READDIR agree; GETATTR,
  READ, WRITE and SETATTR then reach the engine by serial as for any file.
- CREATE of a `._` name the view holds is the ordinary CREATE of that file
  (UNCHECKED opens it, GUARDED/EXCLUSIVE answer EXIST); no companion is
  made, so nothing shadows it. The attributes a macOS client then stores
  there go into the Workspace file, as on any NFSv3 server.
- REMOVE removes it, and RENAME may replace it; RENAME onto a `._` name the
  view lacks stays NFS3ERR_ACCES.
- Names the view does not hold keep using the export-memory companions as
  before; a companion whose name the view gains later is shadowed by the
  real file.

Cost: LOOKUP, CREATE, REMOVE and RENAME of a `._` name now make one engine
LOOKUP (an observe visit) to ask the view, also for companions and absent
names. The job-count test in tests/write.rs asserted zero owner jobs for a
companion CREATE+WRITE+SETATTR+REMOVE and an absent `._` LOOKUP; that
contract is what hid real files, so its exact expectation is now two and
three observe visits with zero mutate visits (still exact, not loosened).

Tests: new tests/apple_double_view.rs (a base with `._foo` and `d/._bar`:
listed, LOOKUP+READ, CREATE GUARDED/UNCHECKED, WRITE, RENAME onto it,
REMOVE, committed; a new companion still stays in memory and out of the
Commit). Docs: kernel-routes/nfs.md AppleDouble section and LOOKUP rule,
kernel-routes/README.md test table.

Production LOC: 206,537 -> 206,585 (delta +48)
  core     40,988 -> 40,988 (0)
  engine   95,899 -> 95,947 (+48)  layerfs-nfs +48
  control  59,325 -> 59,325 (0)
  api      10,325 -> 10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --detail on parent 343c59b and the staged tree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a merged Commit the daemon marked every stale serial at once, then
chmodded the paths one by one on a background thread; for up to 30 s any
mode-only SETATTR on a marked serial was answered with the current
attributes and changed nothing, without comparing the requested mode. So
`chmod +x f` right after a Commit reported success and did nothing (review
finding #9, V-OV-4).

Now the mark suppresses only the refresh's own chmod:
- `Server::refresh` returns (serial, path) and marks nothing.
- The refresh thread lstats each path through the mount (skipping a
  symlink, a vanished path and a path that now names another inode), marks
  that serial with exactly the mode it is about to ask
  (`Refresher::arm`), then chmods to it.
- `Kernel::refreshed` takes the mark only for a mode-only SETATTR asking the
  marked mode. A client SETATTR asking another mode is applied, and leaves
  the mark for the refresh chmod still on its way, which is then answered
  without a change, so the refresh never overwrites a newer user chmod.
- `Refresher` holds a weak reference, so the thread never keeps a stopping
  export alive (unmount's `Arc::try_unwrap` stays unaffected), and stops
  once the export is gone.

Residual: a client chmod to the very mode just marked, sent in the
microseconds between the mark and the refresh's chmod, is answered unchanged;
the refresh's chmod that follows applies that same mode. Documented, with
the existing limits: the refresh is best effort, runs after the Commit reply
and stops at 4,096 stale inodes.

Tests: tests/refresh.rs now asserts the new contract. Its old assertion
that a marked chmod to another mode (0o600 on a 0o644 file) is swallowed was
the bug itself and is replaced: the refresh chmod asking the marked mode is
answered unchanged; a user chmod to another mode inside the window is
applied and the refresh chmod after it does not undo it (committed 0o700);
a stopped export takes no mark. Docs: kernel-routes/nfs.md refresh section,
kernel-routes/README.md.

Production LOC: 206,585 -> 206,624 (delta +39)
  core     40,988 -> 40,988 (0)
  engine   95,947 -> 95,986 (+39)  layerfs-daemon +5, layerfs-nfs +34
  control  59,325 -> 59,325 (0)
  api      10,325 -> 10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --detail on parent 2033a2e and the staged tree

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yifanxuaaa added a commit that referenced this pull request Nov 23, 2026
Follow-up to 37c0a8b (finding #4), found on an integration branch of
PRs #762-#765. layerfs-control tests/mount_control.rs
an_original_unknown_blocks_another_commit_and_normal_unmount injected a
StorageError::UnknownOutcome from the producer during construction and
expected the Workspace to stay Uncertain. Before the Publish phase a Store
unknown cannot have published, so under the phase-aware
CommitFailure::uncertain() it folds back and answers Failed; the test
failed at mount_control.rs:298.

The test keeps its intent ("an original unknown blocks another Commit and a
normal unmount") with an uncertainty that still holds before Publish: an
overlay outcome unknown (OverlayError::Uncertain). It is renamed
an_original_local_unknown_blocks_another_commit_and_normal_unmount. The
Store unknown it used to inject moves to a new test,
a_store_unknown_before_publication_folds_back_and_admits_a_commit: Failed,
the Workspace stays Idle on its binding with nothing published, a later
Commit publishes over the bound head, and a normal unmount is admitted. No
test deleted.

Production LOC: 207,195 -> 207,195 (delta 0)
  core      40,989 ->  40,989 (0)
  engine    96,515 ->  96,515 (0)
  control   59,366 ->  59,366 (0)
  api       10,325 ->  10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --detail on parent 384dbb3 and the staged tree (test-only change)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yifanxuaaa added a commit that referenced this pull request Nov 23, 2026
Follow-up to 384dbb3 (finding #5), found by the nightly mount lane on
an integration branch of PRs #762-#765. layerfs-daemon
tests/mounted_commit_failures.rs F3 stages Boundary::LostAcknowledgement
(a real publication, then UnknownOutcome) and its retained tail expected
the next Commit to be refused; under #5 that Commit's one resolution reads
the head, finds exactly this Commit and installs it, so the Commit was
admitted (panic at mounted_commit_failures.rs:478).

F3 is renamed
f3_unknown_history_outcome_is_resolved_by_the_next_commit_and_the_mount_still_serves
and ends in a new resolved_tail: after the failure the Workspace is
Uncertain with both owners kept and the mount still serves the same view
and a new write; an independent session reads the head as one Commit of
the candidate root over the bound head (published once), and a fresh bind
of it is the captured tree; the next Commit is admitted, its parent is that
landed Commit, its root carries the write made since and equals the
mount's tree (later_exact), the registry is Idle; reads still work and the
normal unmount drains and removes the mount.

Deleted: the retained_tail helper, its Kept enum, the refused() helper and
the SECOND constant, whose only caller was F3's old expectation that the
next Commit and a normal unmount are refused under retained custody. That
contract no longer holds for a resolvable unknown outcome; retained
custody that cannot be resolved is covered without a mount by
store_commit.rs an_unknown_outcome_under_a_moved_head_stays_retained and
by layerfs-control mount_control.rs
an_original_local_unknown_blocks_another_commit_and_normal_unmount. The
module header notes F3's new end and where the nothing-published case is
staged.

Production LOC: 207,195 -> 207,195 (delta 0)
  core      40,989 ->  40,989 (0)
  engine    96,515 ->  96,515 (0)
  control   59,366 ->  59,366 (0)
  api       10,325 ->  10,325 (0)
  reference absent (retired R9c; last counted 65,417 at tree 498dd19)
  Method: tools/production_loc.py --detail on parent cecee1e and the staged tree (test-only change)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yifanxuaaa
yifanxuaaa merged commit a0d8a65 into layerfs_v2_0_0 Nov 23, 2026
2 checks passed
@yifanxuaaa
yifanxuaaa deleted the claude/v2-nfs-fixes-076fff branch November 23, 2026 08:14
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.

1 participant