Skip to content

Commit 73d73af

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
1 parent 42ed2e0 commit 73d73af

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
@@ -100,7 +100,7 @@ public NFS4Client getClient() {
100100
* @param inode of opened file.
101101
* @param shareAccess type of access required.
102102
* @param shareDeny type of access to deny others.
103-
* @return stateid associated with open.
103+
* @return a snapshot of the stateid associated with open.
104104
* @throws ShareDeniedException if share reservation conflicts with an existing open.
105105
* @throws ChimeraNFSException
106106
*/
@@ -134,7 +134,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
134134
os.shareAccess |= shareAccess;
135135
os.shareDeny |= shareDeny;
136136
os.stateid.seqid++;
137-
return os.stateid;
137+
//we need to return copy to avoid modification by concurrent opens
138+
return new stateid4(os.stateid.other, os.stateid.seqid);
138139
}
139140
}
140141

@@ -144,7 +145,8 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
144145
opens.add(openState);
145146
state.addDisposeListener(s -> removeOpen(inode, stateid));
146147
stateid.seqid++;
147-
return stateid;
148+
//we need to return copy to avoid modification by concurrent opens
149+
return new stateid4(stateid.other, stateid.seqid);
148150
} finally {
149151
lock.unlock();
150152
}
@@ -158,7 +160,7 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
158160
* @param inode of opened file.
159161
* @param shareAccess type of access required.
160162
* @param shareDeny type of access to deny others.
161-
* @return stateid associated with open.
163+
* @return a snapshot of the stateid associated with open.
162164
* @throws ChimeraNFSException
163165
*/
164166
public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode, int shareAccess, int shareDeny) throws ChimeraNFSException {
@@ -187,7 +189,8 @@ public stateid4 downgradeOpen(NFS4Client client, stateid4 stateid, Inode inode,
187189
os.shareDeny = shareDeny;
188190

189191
os.stateid.seqid++;
190-
return os.stateid;
192+
//we need to return copy to avoid modification by concurrent opens
193+
return new stateid4(os.stateid.other, os.stateid.seqid);
191194
} finally {
192195
lock.unlock();
193196
}

0 commit comments

Comments
 (0)