Skip to content

Commit abc0aa3

Browse files
committed
nfs4: FileTracker should return a copy of stateid
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>
1 parent fac21bb commit abc0aa3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public StateOwner getOwner() {
9595
* @param inode of opened file.
9696
* @param shareAccess type of access required.
9797
* @param shareDeny type of access to deny others.
98-
* @return stateid associated with open.
98+
* @return a snapshot of the stateid associated with open.
9999
* @throws ShareDeniedException if share reservation conflicts with an existing open.
100100
* @throws ChimeraNFSException
101101
*/
@@ -129,7 +129,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
129129
os.shareAccess |= shareAccess;
130130
os.shareDeny |= shareDeny;
131131
os.stateid.seqid++;
132-
return os.stateid;
132+
//we need to return copy to avoid modification by concurrent opens
133+
return new stateid4(os.stateid.other, os.stateid.seqid);
133134
}
134135
}
135136

@@ -139,7 +140,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
139140
opens.add(openState);
140141
state.addDisposeListener(s -> removeOpen(inode, stateid));
141142
stateid.seqid++;
142-
return stateid;
143+
//we need to return copy to avoid modification by concurrent opens
144+
return new stateid4(stateid.other, stateid.seqid);
143145
} finally {
144146
lock.unlock();
145147
}
@@ -153,7 +155,7 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
153155
* @param inode of opened file.
154156
* @param shareAccess type of access required.
155157
* @param shareDeny type of access to deny others.
156-
* @return stateid associated with open.
158+
* @return a snapshot of the stateid associated with open.
157159
* @throws ChimeraNFSException
158160
*/
159161
public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode, int shareAccess, int shareDeny) throws ChimeraNFSException {
@@ -182,7 +184,8 @@ public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode,
182184
os.shareDeny = shareDeny;
183185

184186
os.stateid.seqid++;
185-
return os.stateid;
187+
//we need to return copy to avoid modification by concurrent opens
188+
return new stateid4(os.stateid.other, os.stateid.seqid);
186189
} finally {
187190
lock.unlock();
188191
}

0 commit comments

Comments
 (0)