Skip to content

fix(fs): remove a name only while it names the looked-up inode, and replay mkdir and claimed creates whole - #94

Merged
mattmattox merged 10 commits into
mainfrom
claude/remove-name-guards
Nov 13, 2026
Merged

mattmattox merged 10 commits into
mainfrom
claude/remove-name-guards

Conversation

@mattmattox

@mattmattox mattmattox commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The four follow-ups from #84, in the PM's order.

  1. Unlink and rmdir looked up the child, then removed the name and freed the child as the lookup saw it. If another node removed the name and made a new one in between, they removed the new name and freed it with stale extents. RemoveIf now checks the entry under the directory lock:

    • The name points to another inode: ENOENT, nothing is freed.
    • Same inode, but no longer in use, of a different type, or with a different link count: start over from the lookup, which then acts on what the name points to now, for example EISDIR for a directory.
    • A directory must also keep its generation, because an entry added to it changes the generation; the retry then reports ENOTEMPTY. A file's generation is not checked, because every write changes it, and unlink of a file another node keeps writing must succeed.
    • The free uses the inode as FreeIf sees it under the inode lock, not the lookup's copy.

    There is no rename.

  2. Replayed mkdir now gets "." and "..", a link count of 2, and raises the parent's link count. The parent update uses the new inode.Table.Update, which holds the inode lock from the read to the write. A plain read followed by Write could overwrite a peer's directory change.

  3. Name errors in create, mkdir, clone, unlink and rmdir: EEXIST for a taken name, ENOENT for a removed directory.

  4. Replay finishes a claimed create. When the slot is in use, replay names it if the transaction's owner wrote it last, and at most as often as a create does before naming (2 writes for a file, 3 for a directory). Nothing else can reach an unnamed inode. A finished create also passes this check, but its name already exists, so the add is skipped.

Not covered

  • Rmdir: another node can add an entry to the directory after the name is removed and before the free. The free is then refused, which leaves an unnamed directory for fsck.
  • A crash in a live mkdir between adding the name and raising the parent's link count leaves the count one short. Replay can't tell which step ran.
  • The write limit in (4) must follow create and mkdir. If either adds a write before naming, the crash tests fail.

Results

  • Lint at 94223c1: 0 issues.
  • .66 at 94223c1: race unit tests pass, the new tests pass 5 times in a row under race, integration -short 138/0.
  • Mutation checks: each of these makes a test fail: skipping the inode-number check, the type and link-count check, the directory generation check, or the free that uses the current inode; checking a file's generation again (unlink returns EAGAIN while another node writes); mapping name errors to EIO; skipping the mkdir setup or the parent link; dropping the owner check or the write limit in (4); turning (4) off.
  • VM (.68) at 94223c1: 59 passed, 0 failed.

🤖 Generated with Claude Code

mattmattox and others added 10 commits November 13, 2026 12:42
Unlink and rmdir looked up the child, then removed the name and freed the
child by that lookup. If another node removed the name and made a new one in
between, they removed the new name and freed with stale extents. The removal
now checks the child under the directory lock: a name that points to another
inode returns ENOENT, and a changed child is looked up again. The free uses
what the inode maps when it is freed. Name errors map to EEXIST and ENOENT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anded

A replayed mkdir now gets "." and ".." and raises the parent's link count,
under the parent's inode lock. A create that crashed after claiming its inode
used to leave it unnamed: replay now names it when the logging node wrote it
last, and no more often than a create does before naming it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… name errors

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… directories

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every write raises a file's generation, so unlink of a file another node kept
writing ran out of retries with EAGAIN. A file now only has to keep its type
and link count; a directory still has to be unchanged, since an entry added
to it changes its generation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattmattox
mattmattox merged commit 29feedb into main Nov 13, 2026
13 checks passed
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