Skip to content

Commit c3d7390

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 c3d7390

File tree

7 files changed

+66
-4
lines changed

7 files changed

+66
-4
lines changed

Diff for: core/src/main/java/org/dcache/nfs/v4/OperationCLOSE.java

+1
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();

Diff for: core/src/main/java/org/dcache/nfs/v4/OperationOPEN.java

+11-4
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();

Diff for: core/src/main/java/org/dcache/nfs/vfs/PseudoFs.java

+11
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
/*

Diff for: core/src/main/java/org/dcache/nfs/vfs/VfsCache.java

+11
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);

Diff for: core/src/main/java/org/dcache/nfs/vfs/VirtualFileSystem.java

+18
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
*

Diff for: core/src/test/java/org/dcache/nfs/v4/NFS4ClientTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.dcache.nfs.v4.xdr.nfs_opnum4;
3131
import org.dcache.nfs.v4.xdr.nfs_resop4;
3232
import org.dcache.nfs.v4.xdr.stateid4;
33+
import org.dcache.nfs.vfs.VirtualFileSystem;
3334
import org.junit.Before;
3435
import org.junit.Test;
3536

@@ -73,6 +74,7 @@ public void testStateCleanOnOpenCloseV41() throws Exception {
7374
OperationCLOSE CLOSE = new OperationCLOSE(close_args);
7475
result = nfs_resop4.resopFor(nfs_opnum4.OP_CLOSE);
7576
context = new CompoundContextBuilder()
77+
.withFs(mock(VirtualFileSystem.class))
7678
.withStateHandler(stateHandler)
7779
.withMinorversion(1)
7880
.withDeviceManager(mock(NFSv41DeviceManager.class))
@@ -100,6 +102,7 @@ public void testStateCleanOnOpenCloseV40() throws Exception {
100102
OperationCLOSE CLOSE = new OperationCLOSE(close_args);
101103
result = nfs_resop4.resopFor(nfs_opnum4.OP_CLOSE);
102104
context = new CompoundContextBuilder()
105+
.withFs(mock(VirtualFileSystem.class))
103106
.withStateHandler(stateHandler)
104107
.withMinorversion(0)
105108
.withCall(generateRpcCall())

Diff for: core/src/test/java/org/dcache/nfs/vfs/DummyVFS.java

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.common.jimfs.Configuration;
2323
import com.google.common.jimfs.Jimfs;
2424
import com.google.common.primitives.Longs;
25+
import org.dcache.nfs.v4.xdr.stateid4;
2526
import org.slf4j.Logger;
2627
import org.slf4j.LoggerFactory;
2728

@@ -208,6 +209,16 @@ public Inode create(Inode parent, Type type, String path, Subject subject, int m
208209
return toFileHandle(newInodeNumber);
209210
}
210211

212+
@Override
213+
public void open(Inode inode, int mode, stateid4 stateid) throws IOException {
214+
215+
}
216+
217+
@Override
218+
public void close(Inode inode, stateid4 stateid) throws IOException {
219+
220+
}
221+
211222
@Override
212223
public FsStat getFsStat() throws IOException {
213224
FileStore store = Files.getFileStore(_root);

0 commit comments

Comments
 (0)