Skip to content

Commit

Permalink
nfs4: bump open-stateid sequence only in FileTracker#addOpen
Browse files Browse the repository at this point in the history
Motivation:
To avoid race conditions, the updating of the open-stateid must happen
only under lock, which is guaranteed by FileTracker#addOpen

Modification:
Update open-stateid sequence only in FileTracker#addOpen

Result:
Fix of the race condition

Fixes: #120
Acked-by: Paul Millar
Target: master, 0.24, 0.23
(cherry picked from commit 42ed2e0)
Signed-off-by: Tigran Mkrtchyan <[email protected]>
  • Loading branch information
kofemann committed Mar 28, 2023
1 parent 91ad32f commit 056ffe3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/src/main/java/org/dcache/nfs/v4/FileTracker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 - 2020 Deutsches Elektronen-Synchroton,
* Copyright (c) 2017 - 2023 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -120,14 +120,15 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
throw new ShareDeniedException("Conflicting share");
}

// if there is an another open from the same client we must merge
// if there is another open from the same client we must merge
// access mode and return the same stateid as required by rfc5661#18.16.3

for (OpenState os : opens) {
if (os.client.getId() == client.getId() &&
os.getOwner().equals(owner)) {
os.shareAccess |= shareAccess;
os.shareDeny |= shareDeny;
os.stateid.seqid++;
return os.stateid;
}
}
Expand All @@ -137,6 +138,7 @@ public stateid4 addOpen(NFS4Client client, StateOwner owner, Inode inode, int sh
OpenState openState = new OpenState(client, owner, stateid, shareAccess, shareDeny);
opens.add(openState);
state.addDisposeListener(s -> removeOpen(inode, stateid));
stateid.seqid++;
return stateid;
} finally {
lock.unlock();
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/dcache/nfs/v4/OperationLOCK.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -122,6 +122,7 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
context.getLm().unlockIfExists(inode.getFileId(), lock);
});

// FIXME: we might run into race condition, thus updating sedid must be fenced!
lock_state.bumpSeqid();
context.currentStateid(lock_state.stateid());
result.oplock.status = nfsstat.NFS_OK;
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/org/dcache/nfs/v4/OperationOPEN.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Copyright (c) 2009 - 2023 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -271,7 +271,6 @@ public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNF
_args.opopen.share_access.value,
_args.opopen.share_deny.value);

stateid.seqid++;
context.currentStateid(stateid);
res.resok4.stateid = stateid;
res.status = nfsstat.NFS_OK;
Expand Down

0 comments on commit 056ffe3

Please sign in to comment.