Skip to content

Commit fa72b28

Browse files
ovaistariqclaude
andcommitted
fix: Initialize DirHandle generation correctly to prevent spurious invalidations
The tests were failing because new DirHandles started with generation=0, but the directory might already have a non-zero generation from prior modifications. This caused the handle to immediately think it was out of date and reset its position, leading to missing entries in readdir. Changes: - Initialize generation when creating new DirHandles - Reset generation to current when seeking to offset 0 - Ensure consistent generation tracking across all handle creation paths This fixes the test failures where directory listings were returning incomplete results. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 914cd97 commit fa72b28

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

core/cluster_fs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ func (fs *ClusterFs) readDir(handleId fuseops.HandleID, offset fuseops.DirOffset
430430
dh.lastExternalOffset = 0
431431
dh.lastInternalOffset = 0
432432
dh.lastName = ""
433+
dh.generation = atomic.LoadUint64(&dh.inode.dir.generation)
433434
}
434435

435436
for {

core/cluster_fs_fuse.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,10 @@ func (fs *ClusterFsFuse) OpenDir(ctx context.Context, op *fuseops.OpenDirOp) (er
550550

551551
// 2nd phase
552552
fs.Goofys.mu.Lock()
553-
dh := &DirHandle{inode: inode}
553+
dh := &DirHandle{
554+
inode: inode,
555+
generation: atomic.LoadUint64(&inode.dir.generation),
556+
}
554557
fs.Goofys.dirHandles[fuseops.HandleID(resp.HandleId)] = dh
555558
fs.Goofys.mu.Unlock()
556559

core/dir.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ type DirHandle struct {
9393
}
9494

9595
func NewDirHandle(inode *Inode) (dh *DirHandle) {
96-
dh = &DirHandle{inode: inode}
96+
dh = &DirHandle{
97+
inode: inode,
98+
generation: atomic.LoadUint64(&inode.dir.generation),
99+
}
97100
return
98101
}
99102

@@ -775,6 +778,7 @@ func (dh *DirHandle) Seek(newOffset fuseops.DirOffset) {
775778
dh.lastExternalOffset = 0
776779
dh.lastInternalOffset = 0
777780
dh.lastName = ""
781+
dh.generation = atomic.LoadUint64(&dh.inode.dir.generation)
778782
}
779783
}
780784

0 commit comments

Comments
 (0)