Skip to content

Commit

Permalink
nfs4: FileTracker should return a copy of stateid
Browse files Browse the repository at this point in the history
Motivation:
As parallel threads modifies open-stateid sequence number the
FileTracker should always return a copy to avoid that sequence
is modified before reply is sent.

Modification:
Update FileTracker#addOpen and FileTracker#downgradeOpen to return a
copy of stateid.

Result:
Spec compliant behaviour in concurrent environment.

Fixes: #96
Acked-by: Albert Rossi
Target: master, 0.24, 0.23
(cherry picked from commit 73d73af)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann committed Mar 29, 2023
1 parent 7b4981f commit 584e988
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/src/main/java/org/dcache/nfs/v4/FileTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public NFS4Client getClient() {
* @param inode of opened file.
* @param shareAccess type of access required.
* @param shareDeny type of access to deny others.
* @return stateid associated with open.
* @return a snapshot of the stateid associated with open.
* @throws ShareDeniedException if share reservation conflicts with an existing open.
* @throws ChimeraNFSException
*/
Expand Down Expand Up @@ -134,7 +134,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
os.shareAccess |= shareAccess;
os.shareDeny |= shareDeny;
os.stateid.seqid++;
return os.stateid;
//we need to return copy to avoid modification by concurrent opens
return new stateid4(os.stateid.other, os.stateid.seqid);
}
}

Expand All @@ -144,7 +145,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
opens.add(openState);
state.addDisposeListener(s -> removeOpen(inode, stateid));
stateid.seqid++;
return stateid;
//we need to return copy to avoid modification by concurrent opens
return new stateid4(stateid.other, stateid.seqid);
} finally {
lock.unlock();
}
Expand All @@ -158,7 +160,7 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
* @param inode of opened file.
* @param shareAccess type of access required.
* @param shareDeny type of access to deny others.
* @return stateid associated with open.
* @return a snapshot of the stateid associated with open.
* @throws ChimeraNFSException
*/
public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode, int shareAccess, int shareDeny) throws ChimeraNFSException {
Expand Down Expand Up @@ -187,7 +189,8 @@ public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode,
os.shareDeny = shareDeny;

os.stateid.seqid++;
return os.stateid;
//we need to return copy to avoid modification by concurrent opens
return new stateid4(os.stateid.other, os.stateid.seqid);
} finally {
lock.unlock();
}
Expand Down

0 comments on commit 584e988

Please sign in to comment.