mount: improve NFS directory listing (#7696)

mount: remove unused isEarlyTerminated variable

The variable was redundant because when processEachEntryFn returns false,
we immediately return fuse.OK, so the check was always false.
This commit is contained in:
Chris Lu
2025-12-09 22:02:17 -08:00
committed by GitHub
parent 4bc2b6d62b
commit 1e1473ef4a

View File

@@ -159,7 +159,6 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
} }
} }
isEarlyTerminated := false
dirPath, code := wfs.inodeToPath.GetPath(input.NodeId) dirPath, code := wfs.inodeToPath.GetPath(input.NodeId)
if code != fuse.OK { if code != fuse.OK {
return code return code
@@ -179,13 +178,11 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
if !isPlusMode { if !isPlusMode {
if !out.AddDirEntry(dirEntry) { if !out.AddDirEntry(dirEntry) {
isEarlyTerminated = true
return false return false
} }
} else { } else {
entryOut := out.AddDirLookupEntry(dirEntry) entryOut := out.AddDirLookupEntry(dirEntry)
if entryOut == nil { if entryOut == nil {
isEarlyTerminated = true
return false return false
} }
if fh, found := wfs.fhMap.FindFileHandle(inode); found { if fh, found := wfs.fhMap.FindFileHandle(inode); found {
@@ -257,35 +254,33 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
} }
// Cache exhausted, load next batch // Cache exhausted, load next batch
if !isEarlyTerminated { if err := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath); err != nil {
if err := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath); err != nil { glog.Errorf("dir ReadDirAll %s: %v", dirPath, err)
glog.Errorf("dir ReadDirAll %s: %v", dirPath, err) return fuse.EIO
return fuse.EIO }
}
// Batch loading: fetch batchSize entries starting from lastEntryName // Batch loading: fetch batchSize entries starting from lastEntryName
loadedCount := 0 loadedCount := 0
bufferFull := false bufferFull := false
loadErr := wfs.metaCache.ListDirectoryEntries(context.Background(), dirPath, lastEntryName, false, int64(batchSize), func(entry *filer.Entry) (bool, error) { loadErr := wfs.metaCache.ListDirectoryEntries(context.Background(), dirPath, lastEntryName, false, int64(batchSize), func(entry *filer.Entry) (bool, error) {
currentIndex := int64(len(dh.entryStream)) currentIndex := int64(len(dh.entryStream))
dh.entryStream = append(dh.entryStream, entry) dh.entryStream = append(dh.entryStream, entry)
loadedCount++ loadedCount++
if !processEachEntryFn(entry, currentIndex) { if !processEachEntryFn(entry, currentIndex) {
bufferFull = true bufferFull = true
return false, nil return false, nil
}
return true, nil
})
if loadErr != nil {
glog.Errorf("list meta cache: %v", loadErr)
return fuse.EIO
} }
return true, nil
})
if loadErr != nil {
glog.Errorf("list meta cache: %v", loadErr)
return fuse.EIO
}
// Mark finished only when loading completed normally (not buffer full) // Mark finished only when loading completed normally (not buffer full)
// and we got fewer entries than requested // and we got fewer entries than requested
if !bufferFull && loadedCount < batchSize { if !bufferFull && loadedCount < batchSize {
dh.isFinished = true dh.isFinished = true
}
} }
} }