Repository navigation
fix(fs): hold the inode lock across directory time and link-count updates - #41
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates Create, mkdir, unlink, rmdir and their Dir variants re-read the parent inode without its lock, then wrote it back to set Mtime or LinkCount. If another node's dir.Add grew the directory to a new block in between, the write-back reverted the directory's Size and extents: the new entries vanished and their block leaked. Unlink's child LinkCount update could likewise revert another node's write to the file. updateInodeLocked holds the local and cluster inode locks from the read to the write. It is only for updates that touch no extents, since freeing blocks under the inode lock would break the lock order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each directory block holds only 15 entries with 255-byte names, and growing a directory past two non-contiguous blocks fails on its own (extent tree block allocation under the inode lock), so the test grows 50 directories from one block to two. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On main, a directory growing between the read and the write is already caught: every inode write compares the on-disk extents with the ones it read and retries on a change (staleExtents, from #8). The growth tests passed without the fix and failed only on slot collisions and lock timeouts. What the lock still protects is fields outside the extents, such as a parent's link count, so test that directly with two nodes interleaved inside the update. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A skipped link count change leaves an inconsistency that fsck reports, so operators need to find it in the log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The scenario as reported (another node grows the directory between the parent read and the Mtime write-back) is already caught on main. Since #8, every inode write compares the on-disk extents with the ones it read and retries on a change (
staleExtents). Two-node tests that grew 100 directories during concurrent creates passed without this fix.What still gets lost is anything outside the extents. If two nodes update a parent's
LinkCount(mkdir/rmdir) or Mtime at the same time, one update overwrites the other. Unlink'sLinkCountupdate on the child can also overwrite another node's change to that file. The nine parent and child write-backs now go throughupdateInodeLocked, which holds the local and cluster inode locks from the read to the write. I didn't changeupdateInodeitself:discardInodefrees blocks inside its callback, and taking the bitmap lock while holding the inode lock is rejected (ErrDeadlockRisk).TestUpdateInodeLockedWaitsForOtherNoderuns node B's update inside node A's read-to-write window. With the oldupdateInode, it fails with link count 3, want 4.Tested on .68 at 34e78e7:
-raceis clean oninternal/goclusterfsandinternal/dir.-shortintegration: 107 pass, 16 skip, 0 fail.3378569 only changes log levels: a skipped link count update now logs at WARN with the inode number.
Found while testing, not fixed (details are in the PM notes): directory blocks only use their first 4 KB chunk (15 long-name entries per 1 MB block). Concurrent creates fail with EIO once a directory needs an extent tree, from tree block allocation under the inode lock.
🤖 Generated with Claude Code