Skip to content

fix(fs): never let a stale file node reach the next file in its slot - #169

Merged
mattmattox merged 2 commits into
mainfrom
fix/stale-file-node-birth
Nov 16, 2026
Merged

mattmattox merged 2 commits into
mainfrom
fix/stale-file-node-birth

Conversation

@mattmattox

Copy link
Copy Markdown
Contributor

A file node that outlived its file, through an O_PATH descriptor or a cached name another node removed, reached whatever file took its inode slot next. go-fuse also gave lookups of the new file the old node, because both had generation 0. This was the PM's follow-up from the #159 review.

History checker, 3 nodes for 3 minutes:

Calls Reads of another file's data Torn reads write ESTALE ENOSPC
#161 228,612 10 39 0 5
+ this PR 186,479 0 27 ~11 9

The write ESTALE cases are files freed while open in create's window. Before this PR they wrote silently into the next file in the slot. The next PR fixes them.

Birth 0, from inodes older versions wrote, matches any node, because a snapshot assigns such a file its birth while nodes hold it.

🤖 Generated with Claude Code

mattmattox and others added 2 commits November 16, 2026 15:14
A file node that outlived its file, such as an O_PATH descriptor or a
name another node had just removed, opened, read, wrote and truncated
whatever file took its inode slot next. go-fuse also handed lookups of
the new file the old node, since both had the same inode number and
generation 0.

File nodes now record the inode's birth generation and pass it to
go-fuse as the generation, and open, getattr, read, write, truncate,
allocate and the xattr calls return ESTALE when the slot holds another
file. Birth 0, from inodes older versions wrote, matches any file,
because a snapshot gives such a file its birth while nodes hold it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
writeInternal checked the slot once, before the locks. A new file that
took the slot meanwhile and mapped the freed block at the same place
passed the in-place write's block check, so the write landed in it. The
check under the lock now refuses a slot that holds another file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattmattox
mattmattox merged commit 5f9d664 into main Nov 16, 2026
17 checks passed
mattmattox added a commit that referenced this pull request Nov 16, 2026
… slot

A symlink node did not check the inode's birth generation, so once its
link was unlinked and another symlink took the slot, readlink and
lchown through the old node reached the new link. The symlink unlink
fast path made that reuse immediate. Link nodes now record the birth
generation, pass it to go-fuse as the generation, and return ESTALE
when the slot holds another link, as #169 does for files.

A symlink create that fails after its commit now ends the intent
durably before it frees the target block, so replay cannot map a block
this node already freed; if that fails, the block stays allocated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mattmattox added a commit that referenced this pull request Nov 17, 2026
…172)

* feat(fs): symlinks, with targets inline in the inode or in one block

symlink, readlink, lstat, lchown and lutimes work through FUSE; the
kernel follows links itself. A target of up to 92 bytes is kept in the
inode bytes the inline extents and tree fields use, under a new
FlagInlineTarget; the inode decoder leaves the extents zero for such an
inode, so nothing that walks extents reads target bytes as blocks. A
longer target, up to 4095 bytes, goes in one zeroed data block mapped
like a one-block file.

-format sets the new RequiredSymlinks superblock flag, so older builds
and fsck refuse such volumes; on older volumes symlink returns
EOPNOTSUPP.

Creating a link is one transaction: InodeCreate, a new SymlinkTarget
entry and DirAddEntry (plus BlockUse for a reserved block). It claims
the inode before naming it, and replay applies the target only to an
inode that replay itself created.

fsck parses inline targets, checks symlink link counts, lengths,
layout, padding and targets, and checks that DT_LNK entries and symlink
inodes match. It reports bad symlinks without repairing them; an
unnamed one goes through the existing unnamed-inode repair.

Snapshots and clones of a symlink are refused: a Link node takes no
xattrs, as the kernel refuses user xattrs on symlinks anyway.

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

* style: keep the symlink comments to one line

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

* fix(fs): free a symlink's inode at its last unlink, since no node can hold one open

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

* style: gofmt the symlink tests

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

* fix(fs): never let a stale symlink node reach the next symlink in its slot

A symlink node did not check the inode's birth generation, so once its
link was unlinked and another symlink took the slot, readlink and
lchown through the old node reached the new link. The symlink unlink
fast path made that reuse immediate. Link nodes now record the birth
generation, pass it to go-fuse as the generation, and return ESTALE
when the slot holds another link, as #169 does for files.

A symlink create that fails after its commit now ends the intent
durably before it frees the target block, so replay cannot map a block
this node already freed; if that fails, the block stays allocated.

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

* fix(fs): name a symlink and update its parent in one write, as creates do after #181

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
mattmattox added a commit that referenced this pull request Nov 17, 2026
* feat(fs): symlinks, with targets inline in the inode or in one block

symlink, readlink, lstat, lchown and lutimes work through FUSE; the
kernel follows links itself. A target of up to 92 bytes is kept in the
inode bytes the inline extents and tree fields use, under a new
FlagInlineTarget; the inode decoder leaves the extents zero for such an
inode, so nothing that walks extents reads target bytes as blocks. A
longer target, up to 4095 bytes, goes in one zeroed data block mapped
like a one-block file.

-format sets the new RequiredSymlinks superblock flag, so older builds
and fsck refuse such volumes; on older volumes symlink returns
EOPNOTSUPP.

Creating a link is one transaction: InodeCreate, a new SymlinkTarget
entry and DirAddEntry (plus BlockUse for a reserved block). It claims
the inode before naming it, and replay applies the target only to an
inode that replay itself created.

fsck parses inline targets, checks symlink link counts, lengths,
layout, padding and targets, and checks that DT_LNK entries and symlink
inodes match. It reports bad symlinks without repairing them; an
unnamed one goes through the existing unnamed-inode repair.

Snapshots and clones of a symlink are refused: a Link node takes no
xattrs, as the kernel refuses user xattrs on symlinks anyway.

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

* style: keep the symlink comments to one line

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

* fix(fs): free a symlink's inode at its last unlink, since no node can hold one open

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

* test: symlinks across nodes and in the soak driver

Go integration, Docker and VM tests make symlinks with an inline and a
block target on one node, read them with readlink and lstat and read a
file through one on another node, and remove one there.

The soak driver gains a symlink op (a lane file, a missing name, or a
target too long for the inode) and unlinks links; directory listings
now show each link with its target, so every check compares targets
on all nodes, including after faults and replay.

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

* style: gofmt the symlink tests

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

* fix(fs): never let a stale symlink node reach the next symlink in its slot

A symlink node did not check the inode's birth generation, so once its
link was unlinked and another symlink took the slot, readlink and
lchown through the old node reached the new link. The symlink unlink
fast path made that reuse immediate. Link nodes now record the birth
generation, pass it to go-fuse as the generation, and return ESTALE
when the slot holds another link, as #169 does for files.

A symlink create that fails after its commit now ends the intent
durably before it frees the target block, so replay cannot map a block
this node already freed; if that fails, the block stays allocated.

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

* fix(fs): name a symlink and update its parent in one write, as creates do after #181

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

* docs: symlinks lack only hard links now; keep soak symlinks out of a full lane

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

* docs: phase 6 checks every entry type, not only symlinks

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