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 <[email protected]>
  • Loading branch information
kofemann committed Mar 29, 2023
1 parent fac21bb commit abc0aa3
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 @@ -95,7 +95,7 @@ public StateOwner getOwner() {
* @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 @@ -129,7 +129,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 @@ -139,7 +140,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 @@ -153,7 +155,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 @@ -182,7 +184,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 abc0aa3

Please sign in to comment.