Skip to content

Commit

Permalink
Extract dh.Seek() from ReadDir()
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jun 9, 2023
1 parent 2688d6d commit 96589d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
29 changes: 29 additions & 0 deletions internal/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,35 @@ func (dh *DirHandle) loadListing() error {
return nil
}

// LOCKS_REQUIRED(dh.mu)
func (dh *DirHandle) Seek(newOffset fuseops.DirOffset) {
if newOffset != 0 && newOffset != dh.lastExternalOffset {
// Do our best to support directory seeks even though we can't guarantee
// consistent listings in this case (i.e. files may be duplicated or skipped on changes)
// 'Normal' software doesn't seek within the directory.
// nfs-kernel-server, though, does: it closes the dir between paged listing calls.
fuseLog.Debugf("Directory seek from %v to %v in %v", newOffset, dh.lastExternalOffset, dh.inode.FullName())
dh.inode.mu.Lock()
dh.lastExternalOffset = newOffset
dh.lastInternalOffset = int(newOffset)
if dh.lastInternalOffset > len(dh.inode.dir.Children) {
dh.lastInternalOffset = len(dh.inode.dir.Children)
}
if len(dh.inode.dir.Children) > 0 {
dh.inode.dir.Children[dh.lastInternalOffset-1].mu.Lock()
dh.lastName = dh.inode.dir.Children[dh.lastInternalOffset-1].Name
dh.inode.dir.Children[dh.lastInternalOffset-1].mu.Unlock()
} else {
dh.lastName = ""
}
dh.inode.mu.Unlock()
} else if newOffset == 0 {
dh.lastExternalOffset = 0
dh.lastInternalOffset = 0
dh.lastName = ""
}
}

// LOCKS_REQUIRED(dh.mu)
// LOCKS_EXCLUDED(dh.inode.mu)
// LOCKS_EXCLUDED(dh.inode.fs)
Expand Down
26 changes: 1 addition & 25 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -1275,31 +1275,7 @@ func (fs *Goofys) ReadDir(

dh.mu.Lock()

if op.Offset != 0 && op.Offset != dh.lastExternalOffset {
// Do our best to support directory seeks even though we can't guarantee
// consistent listings in this case (i.e. files may be duplicated or skipped on changes)
// 'Normal' software doesn't seek within the directory.
// nfs-kernel-server, though, does: it closes the dir between paged listing calls.
fuseLog.Debugf("Directory seek from %v to %v in %v", op.Offset, dh.lastExternalOffset, inode.FullName())
inode.mu.Lock()
dh.lastExternalOffset = op.Offset
dh.lastInternalOffset = int(op.Offset)
if dh.lastInternalOffset > len(inode.dir.Children) {
dh.lastInternalOffset = len(inode.dir.Children)
}
if len(inode.dir.Children) > 0 {
inode.dir.Children[dh.lastInternalOffset-1].mu.Lock()
dh.lastName = inode.dir.Children[dh.lastInternalOffset-1].Name
inode.dir.Children[dh.lastInternalOffset-1].mu.Unlock()
} else {
dh.lastName = ""
}
inode.mu.Unlock()
} else if op.Offset == 0 {
dh.lastExternalOffset = 0
dh.lastInternalOffset = 0
dh.lastName = ""
}
dh.Seek(op.Offset)

for {
e, err := dh.ReadDir(dh.lastInternalOffset, dh.lastExternalOffset)
Expand Down

0 comments on commit 96589d6

Please sign in to comment.