Skip to content

fix(fs): hold the inode lock across directory time and link-count updates - #41

Merged
mattmattox merged 6 commits into
mainfrom
fix/dir-mtime-writeback
Oct 24, 2026
Merged

mattmattox merged 6 commits into
mainfrom
fix/dir-mtime-writeback

Conversation

@mattmattox

@mattmattox mattmattox commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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's LinkCount update on the child can also overwrite another node's change to that file. The nine parent and child write-backs now go through updateInodeLocked, which holds the local and cluster inode locks from the read to the write. I didn't change updateInode itself: discardInode frees blocks inside its callback, and taking the bitmap lock while holding the inode lock is rejected (ErrDeadlockRisk).

TestUpdateInodeLockedWaitsForOtherNode runs node B's update inside node A's read-to-write window. With the old updateInode, it fails with link count 3, want 4.

Tested on .68 at 34e78e7:

  • Unit tests pass, and -race is clean on internal/goclusterfs and internal/dir.
  • -short integration: 107 pass, 16 skip, 0 fail.
  • Docker and VM are pending.

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

mattmattox and others added 6 commits October 24, 2026 17:36
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>
@mattmattox
mattmattox merged commit 7df9b21 into main Oct 24, 2026
8 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