Skip to content

Commit 78d36f9

Browse files
committed
Provide open and close callbacks to virtual filesystem implementations as described in #38.
Signed-off-by: David Kocher <[email protected]>
1 parent 15d38f2 commit 78d36f9

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void process(CompoundContext context, nfs_resop4 result)
4747
Inode inode = context.currentInode();
4848

4949
stateid4 stateid = Stateids.getCurrentStateidIfNeeded(context, _args.opclose.open_stateid);
50+
context.getFs().close(inode, stateid);
5051
NFS4Client client;
5152
if (context.getMinorversion() > 0) {
5253
client = context.getSession().getClient();

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
206206
}
207207

208208
context.currentInode(inode);
209+
context.getFs().open(inode, this.getAccessMode(_args.opopen.share_access), result.opopen.resok4.stateid);
209210

210211
break;
211212
case open_claim_type4.CLAIM_PREVIOUS:
@@ -279,11 +280,10 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
279280
}
280281

281282

282-
private void checkCanAccess(CompoundContext context, Inode inode, uint32_t share_access) throws IOException {
283-
284-
int accessMode;
283+
private int getAccessMode(final uint32_t share_access) throws IOException {
284+
final int accessMode;
285285

286-
switch (share_access.value & ~nfs4_prot.OPEN4_SHARE_ACCESS_WANT_DELEG_MASK) {
286+
switch(share_access.value & ~nfs4_prot.OPEN4_SHARE_ACCESS_WANT_DELEG_MASK) {
287287
case nfs4_prot.OPEN4_SHARE_ACCESS_READ:
288288
accessMode = nfs4_prot.ACCESS4_READ;
289289
break;
@@ -296,6 +296,13 @@ private void checkCanAccess(CompoundContext context, Inode inode, uint32_t share
296296
default:
297297
throw new InvalException("Invalid share_access mode: " + share_access.value);
298298
}
299+
return accessMode;
300+
}
301+
302+
303+
private void checkCanAccess(CompoundContext context, Inode inode, uint32_t share_access) throws IOException {
304+
305+
int accessMode = getAccessMode(share_access);
299306

300307
if (context.getFs().access(inode, accessMode) != accessMode) {
301308
throw new AccessException();

core/src/main/java/org/dcache/nfs/vfs/PseudoFs.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.dcache.nfs.status.*;
3838
import org.dcache.nfs.v4.acl.Acls;
3939
import org.dcache.nfs.v4.xdr.acemask4;
40+
import org.dcache.nfs.v4.xdr.stateid4;
4041
import org.dcache.oncrpc4j.rpc.RpcCall;
4142

4243
import static org.dcache.nfs.v4.xdr.nfs4_prot.*;
@@ -183,6 +184,16 @@ public Inode create(Inode parent, Stat.Type type, String path, Subject subject,
183184
return pushExportIndex(parent, _inner.create(parent, type, path, effectiveSubject, mode));
184185
}
185186

187+
@Override
188+
public void open(Inode inode, int mode, stateid4 stateid) throws IOException {
189+
190+
}
191+
192+
@Override
193+
public void close(Inode inode, stateid4 stateid) throws IOException {
194+
195+
}
196+
186197
@Override
187198
public Inode getRootInode() throws IOException {
188199
/*

core/src/main/java/org/dcache/nfs/vfs/VfsCache.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.security.auth.Subject;
3535
import org.dcache.nfs.util.GuavaCacheMXBeanImpl;
3636
import org.dcache.nfs.util.Opaque;
37+
import org.dcache.nfs.v4.xdr.stateid4;
3738

3839
import static java.util.Objects.requireNonNull;
3940

@@ -172,6 +173,16 @@ public Inode create(Inode parent, Stat.Type type, String path, Subject subject,
172173
return inode;
173174
}
174175

176+
@Override
177+
public void open(Inode inode, int mode, stateid4 stateid) throws IOException {
178+
_inner.open(inode, mode, stateid);
179+
}
180+
181+
@Override
182+
public void close(Inode inode, stateid4 stateid) throws IOException {
183+
_inner.close(inode, stateid);
184+
}
185+
175186
@Override
176187
public Stat getattr(Inode inode) throws IOException {
177188
return statFromCacheOrLoad(inode);

core/src/main/java/org/dcache/nfs/vfs/VirtualFileSystem.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.dcache.nfs.v4.NfsIdMapping;
2626
import org.dcache.nfs.v4.xdr.nfsace4;
2727
import org.dcache.nfs.v4.xdr.stable_how4;
28+
import org.dcache.nfs.v4.xdr.stateid4;
2829

2930
/**
3031
* An interface to file system.
@@ -69,6 +70,23 @@ public interface VirtualFileSystem {
6970
*/
7071
Inode create(Inode parent, Stat.Type type, String name, Subject subject, int mode) throws IOException;
7172

73+
/**
74+
* Notify about file handle opened
75+
* @param inode inode of the object
76+
* @param mode Access mode bitmask like ACCESS4_READ
77+
* @param stateid Open state id
78+
* @throws IOException
79+
*/
80+
void open(Inode inode, int mode, stateid4 stateid) throws IOException;
81+
82+
/**
83+
* Notify about file handle closed
84+
* @param inode inode of the object
85+
* @param stateid Open state id
86+
* @throws IOException
87+
*/
88+
void close(Inode inode, stateid4 stateid) throws IOException;
89+
7290
/**
7391
* Get file system's usage information.
7492
*

0 commit comments

Comments
 (0)