All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NFSv4: ensure the open stateid seqid doesn't go backwards
@ 2025-10-29 19:31 Scott Mayhew
  2025-10-30 15:22 ` Benjamin J Coddington
  0 siblings, 1 reply; 4+ messages in thread
From: Scott Mayhew @ 2025-10-29 19:31 UTC (permalink / raw)
  To: trondmy, anna; +Cc: linux-nfs

We have observed an NFSv4 client receiving a LOCK reply with a status of
NFS4ERR_OLD_STATEID and subsequently retrying the LOCK request with an
earlier seqid value in the stateid.  As this was for a new lockowner,
that would imply that nfs_set_open_stateid_locked() had updated the open
stateid seqid with an earlier value.

Looking at nfs_set_open_stateid_locked(), if the incoming seqid is out
of sequence, the task will sleep on the state->waitq for up to 5
seconds.  If the task waits for the full 5 seconds, then after finishing
the wait it'll update the open stateid seqid with whatever value the
incoming seqid has.  If there are multiple waiters in this scenario,
then the last one to perform said update may not be the one with the
highest seqid.

Add a check to ensure that the seqid can only be incremented, and add a
tracepoint to indicate when old seqids are skipped.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 fs/nfs/nfs4proc.c  | 7 +++++++
 fs/nfs/nfs4trace.h | 1 +
 2 files changed, 8 insertions(+)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 411776718494..840ec732ade4 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1780,6 +1780,13 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state,
 		if (nfs_stateid_is_sequential(state, stateid))
 			break;
 
+		if (nfs4_stateid_match_other(stateid, &state->open_stateid) &&
+		    !nfs4_stateid_is_newer(stateid, &state->open_stateid)) {
+			trace_nfs4_open_stateid_update_skip(state->inode,
+							    stateid, status);
+			return;
+		}
+
 		if (status)
 			break;
 		/* Rely on seqids for serialisation with NFSv4.0 */
diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h
index 9776d220cec3..6285128e631a 100644
--- a/fs/nfs/nfs4trace.h
+++ b/fs/nfs/nfs4trace.h
@@ -1353,6 +1353,7 @@ DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_setattr);
 DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_delegreturn);
 DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update);
 DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update_wait);
+DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update_skip);
 DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_close_stateid_update_wait);
 
 DECLARE_EVENT_CLASS(nfs4_getattr_event,
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-10-31 16:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-29 19:31 [PATCH] NFSv4: ensure the open stateid seqid doesn't go backwards Scott Mayhew
2025-10-30 15:22 ` Benjamin J Coddington
2025-10-31 15:17   ` Scott Mayhew
2025-10-31 16:33     ` Benjamin Coddington

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.