Skip to content

Commit

Permalink
nfs4: expose open files known to FileTracker
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kofemann committed Oct 23, 2022
1 parent 5bb88a2 commit 91708e3
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/src/main/java/org/dcache/nfs/v4/FileTracker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 - 2020 Deutsches Elektronen-Synchroton,
* Copyright (c) 2017 - 2022 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand All @@ -21,11 +21,13 @@

import com.google.common.util.concurrent.Striped;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.stream.Collectors;
import org.dcache.nfs.ChimeraNFSException;
import org.dcache.nfs.status.BadStateidException;
import org.dcache.nfs.status.InvalException;
Expand Down Expand Up @@ -84,6 +86,9 @@ public StateOwner getOwner() {
return owner;
}

public NFS4Client getClient() {
return client;
}
}

/**
Expand Down Expand Up @@ -251,4 +256,18 @@ public int getShareAccess(NFS4Client client, Inode inode, stateid4 stateid) thro
lock.unlock();
}
}

/**
* Get all currently open files with associated clients. The resulting map contains file's inodes
* as key and collection of nfs clients that have this file opened as a value.
*
* @return map of all open files.
*/
public Map<Inode, Collection<NFS4Client>> getOpenFiles() {
return files.entrySet().stream()
.collect(Collectors.toMap(
e -> Inode.forFile(e.getKey().getOpaque()),
e -> e.getValue().stream().map(OpenState::getClient).collect(Collectors.toSet()))
);
}
}

0 comments on commit 91708e3

Please sign in to comment.