Skip to content

Commit 91708e3

Browse files
committed
nfs4: expose open files known to FileTracker
Motivation: As being stateful NFSv4.0 keeps the track of currently open files. This information might be important to server implementations, for example to dCache: ``` admin > show opens Open files: 00004A19604BF9A140BEB7B19FEFAEB87C56 (/public/2GB): 7156940215641243649 ([::1]:678) 0000D57D61A4046F4CA19961196D9CBA1F90 (/public/10GB): 7156940215641243649 ([::1]:678) ``` Modification: add FileTracker#getOpenFiles, that returns maps of open files. Result: More information for server implementations. Acked-by: Albert Rossi Target: master
1 parent 5bb88a2 commit 91708e3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

core/src/main/java/org/dcache/nfs/v4/FileTracker.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 - 2020 Deutsches Elektronen-Synchroton,
2+
* Copyright (c) 2017 - 2022 Deutsches Elektronen-Synchroton,
33
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
44
*
55
* This library is free software; you can redistribute it and/or modify
@@ -21,11 +21,13 @@
2121

2222
import com.google.common.util.concurrent.Striped;
2323
import java.util.ArrayList;
24+
import java.util.Collection;
2425
import java.util.Iterator;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.concurrent.ConcurrentHashMap;
2829
import java.util.concurrent.locks.Lock;
30+
import java.util.stream.Collectors;
2931
import org.dcache.nfs.ChimeraNFSException;
3032
import org.dcache.nfs.status.BadStateidException;
3133
import org.dcache.nfs.status.InvalException;
@@ -84,6 +86,9 @@ public StateOwner getOwner() {
8486
return owner;
8587
}
8688

89+
public NFS4Client getClient() {
90+
return client;
91+
}
8792
}
8893

8994
/**
@@ -251,4 +256,18 @@ public int getShareAccess(NFS4Client client, Inode inode, stateid4 stateid) thro
251256
lock.unlock();
252257
}
253258
}
259+
260+
/**
261+
* Get all currently open files with associated clients. The resulting map contains file's inodes
262+
* as key and collection of nfs clients that have this file opened as a value.
263+
*
264+
* @return map of all open files.
265+
*/
266+
public Map<Inode, Collection<NFS4Client>> getOpenFiles() {
267+
return files.entrySet().stream()
268+
.collect(Collectors.toMap(
269+
e -> Inode.forFile(e.getKey().getOpaque()),
270+
e -> e.getValue().stream().map(OpenState::getClient).collect(Collectors.toSet()))
271+
);
272+
}
254273
}

0 commit comments

Comments
 (0)