Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions core/src/main/java/org/dcache/nfs/v4/NFSv4StateHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class NFSv4StateHandler {
*/
private final Clock _clock;

private boolean supportStateless = true;

public NFSv4StateHandler() {
this(Duration.ofSeconds(NFSv4Defaults.NFS4_LEASE_TIME), 0, new EphemeralClientRecoveryStore());
}
Expand Down Expand Up @@ -500,4 +502,40 @@ public Duration getLeaseTime() {
return _leaseTime;
}

/**
* Checks if stateless stateids are supported.
*
* @return true if supported.
*/
public boolean isSupportStateless() {
return supportStateless;
}

/**
* Enables/disables support for stateless stateids.
*
* @param supportStateless flag.
*/
public void setSupportStateless(boolean supportStateless) {
this.supportStateless = supportStateless;
}

/**
* Checks if the given stateid is stateless. If so but stateless stateids are not supported, a
* {@link BadStateidException} is thrown.
*
* @param stateid The stateid.
* @return {@code true} if stateless.
* @throws BadStateidException if stateless but not supported.
* @see #setSupportStateless(boolean)
*/
public boolean checkStatelessAndSupported(stateid4 stateid) throws BadStateidException {
if (Stateids.isStateLess(stateid)) {
if (supportStateless) {
return true;
}
throw new BadStateidException();
}
return false;
}
}
10 changes: 6 additions & 4 deletions core/src/main/java/org/dcache/nfs/v4/OperationREAD.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public void process(CompoundContext context, nfs_resop4 result) throws IOExcepti

stateid4 stateid = Stateids.getCurrentStateidIfNeeded(context, _args.opread.stateid);
var inode = context.currentInode();
if (Stateids.isStateLess(stateid)) {

NFSv4StateHandler stateHandler = context.getStateHandler();
if (stateHandler.checkStatelessAndSupported(stateid)) {
// Anonymous access as per RFC 7530
// https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3
// we only check file access rights.
Expand All @@ -64,13 +66,13 @@ public void process(CompoundContext context, nfs_resop4 result) throws IOExcepti
*
* With introduction of sessions in v4.1 update of the lease time done through SEQUENCE operations.
*/
context.getStateHandler().updateClientLeaseTime(stateid);
client = context.getStateHandler().getClientIdByStateId(stateid);
stateHandler.updateClientLeaseTime(stateid);
client = stateHandler.getClientIdByStateId(stateid);
} else {
client = context.getSession().getClient();
}

int shareAccess = context.getStateHandler().getFileTracker().getShareAccess(client, inode, stateid);
int shareAccess = stateHandler.getFileTracker().getShareAccess(client, inode, stateid);
if ((shareAccess & nfs4_prot.OPEN4_SHARE_ACCESS_READ) == 0) {
throw new OpenModeException("Invalid open mode");
}
Expand Down
9 changes: 5 additions & 4 deletions core/src/main/java/org/dcache/nfs/v4/OperationWRITE.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
}

var inode = context.currentInode();
if (Stateids.isStateLess(stateid)) {
NFSv4StateHandler stateHandler = context.getStateHandler();
if (stateHandler.checkStatelessAndSupported(stateid)) {
// Anonymous access as per RFC 7530
// https://datatracker.ietf.org/doc/html/rfc7530#section-9.1.4.3
// we only check file access rights.
Expand All @@ -85,13 +86,13 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
*
* With introduction of sessions in v4.1 update of the lease time done through SEQUENCE operations.
*/
context.getStateHandler().updateClientLeaseTime(stateid);
client = context.getStateHandler().getClientIdByStateId(stateid);
stateHandler.updateClientLeaseTime(stateid);
client = stateHandler.getClientIdByStateId(stateid);
} else {
client = context.getSession().getClient();
}

int shareAccess = context.getStateHandler().getFileTracker().getShareAccess(client, inode, stateid);
int shareAccess = stateHandler.getFileTracker().getShareAccess(client, inode, stateid);
if ((shareAccess & nfs4_prot.OPEN4_SHARE_ACCESS_WRITE) == 0) {
throw new OpenModeException("Invalid open mode");
}
Expand Down
Loading