Skip to content

Commit 9829fe8

Browse files
committed
LocalFileSystem: Reuse FileStore instance for FsStat
Currently, we are calling Files.getFileStore for every request to VirtualFileSystem.getFileStat. On some systems, such as macOS, this may introduce extremely long wait times for NFS operations, effectively hanging the entire NFS client. Delays as high as 14 seconds (!) have been observed. Move the FileStore access to LocalFileSystem's constructor, such that it can be reused. Signed-off-by: Christian Kohlschütter <[email protected]>
1 parent f85f46c commit 9829fe8

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

basic-server/src/main/java/org/dcache/nfs4j/server/LocalFileSystem.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class LocalFileSystem implements VirtualFileSystem {
6666
private static final Logger LOG = LoggerFactory.getLogger(LocalFileSystem.class);
6767

6868
private final Path _root;
69+
private final FileStore _store;
6970
private final NonBlockingHashMapLong<Path> inodeToPath = new NonBlockingHashMapLong<>();
7071
private final NonBlockingHashMap<Path, Long> pathToInode = new NonBlockingHashMap<>();
7172
private final AtomicLong fileId = new AtomicLong(1); //numbering starts at 1
@@ -150,6 +151,7 @@ private void remap(long inodeNumber, Path oldPath, Path newPath) {
150151
public LocalFileSystem(Path root, Iterable<FsExport> exportIterable) throws IOException {
151152
_root = root;
152153
assert (Files.exists(_root));
154+
_store = Files.getFileStore(_root);
153155
for (FsExport export : exportIterable) {
154156
String relativeExportPath = export.getPath().substring(1); // remove the opening '/'
155157
Path exportRootPath = root.resolve(relativeExportPath);
@@ -203,9 +205,8 @@ public Inode create(Inode parent, Type type, String path, Subject subject, int m
203205

204206
@Override
205207
public FsStat getFsStat() throws IOException {
206-
FileStore store = Files.getFileStore(_root);
207-
long total = store.getTotalSpace();
208-
long free = store.getUsableSpace();
208+
long total = _store.getTotalSpace();
209+
long free = _store.getUsableSpace();
209210
return new FsStat(total, Long.MAX_VALUE, total-free, pathToInode.size());
210211
}
211212

0 commit comments

Comments
 (0)