Skip to content

fix(fs): claim a new inode before naming it, and check replayed entry changes under the directory lock - #84

Merged
mattmattox merged 6 commits into
mainfrom
claude/create-claim-first
Nov 13, 2026
Merged

mattmattox merged 6 commits into
mainfrom
claude/create-claim-first

Conversation

@mattmattox

@mattmattox mattmattox commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Create, mkdir and clone added the name before claiming the inode slot. A crash in between left a name for a free slot, and the next node to claim that slot gave its inode a second name. They now claim first. A crash in between leaks an unnamed inode, which fsck reports as an orphan.

The first commit merges the root and subdirectory copies of create and mkdir, so the order changes in one place. The copies had drifted: mkdir in the root left a link count of 1.

Replay's entry checks now run under the directory lock. DirRemoveEntry uses the new RemoveIf. DirAddEntry relies on Add, which already refused an existing name under the lock, so no AddIf was needed. Add and Remove now also refuse a directory another node removed (ErrRemoved). Before, Add on a removed directory returned success.

Not covered

  • Replay does not finish a create that crashed after its claim; that inode leaks until fsck can free orphans.
  • Live unlink has the same gap: it looks up the child, later removes the name without checking which inode it names, and frees the child unconditionally. Follow-up.
  • A replayed mkdir gets no "." and ".." entries and does not raise the parent's link count. This was already the case. Follow-up.
  • DirAddEntry's skip on ErrRemoved has no test: it needs a peer to remove the parent inside Add's lock window.

Results at 83e114b (the later commit only shortens comments)

  • Lint: 0 issues.
  • .66: race unit tests pass, the new tests pass 5 times in a row under race, integration -short 138/0.
  • Mutation checks: reverting the create or the mkdir order, dropping RemoveIf's lock, dropping the removed-directory check, or breaking either replay check makes a test fail.
  • VM (.68): 59 passed, 0 failed.

🤖 Generated with Claude Code

mattmattox and others added 6 commits November 13, 2026 10:58
The root copies had drifted: a directory made in the root kept a link count
of 1 instead of 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Create, mkdir and clone added the name first. A crash before the claim left a
name pointing at a free slot; the next node to claim that slot gave its new
inode a second name. Claiming first, a crash can only leak an unnamed inode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replay looked up an entry, then added or removed it in a separate locked step,
so a peer could change the entry in between. RemoveIf checks the entry under
the lock, and Add and Remove now refuse a directory another node removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es under replay's check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sts in the manifest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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