From: NeilBrown <neilb@ownmail.net>
To: Chuck Lever <chuck.lever@oracle.com>, Jeff Layton <jlayton@kernel.org>
Cc: Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
linux-nfs@vger.kernel.org
Subject: [PATCH v5 11/11] nfsd: conditionally clear seqid when current_stateid is used.
Date: Wed, 19 Nov 2025 14:28:57 +1100 [thread overview]
Message-ID: <20251119033204.360415-12-neilb@ownmail.net> (raw)
In-Reply-To: <20251119033204.360415-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
As described in RFC 8881 scions 8.2.3 on Special Stateids:
The stateid passed to the operation in place of the special value
has its "seqid" value set to zero, except when the current stateid
is used by the operation CLOSE or OPEN_DOWNGRADE.
Linux NFSD does not currently follow this guidance. The seqid (known as
si_generation) is left unchanged.
This patch introduces a new status flag SC_STATUS_KEEP_SEQID which is
only used for lookup requests and sets it for the two exceptions: CLOSE
and OPEN_DOWNGRADE. When this flag is not present, the value copied
from the current stateid has the si_generation (aka seqid) cleared.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/nfsd/nfs4state.c | 24 +++++++++++++++---------
fs/nfsd/state.h | 6 ++++++
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 7508158f5f8c..f4b2ae7bc44d 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -7202,6 +7202,8 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
if (!cstate->current_fh.fh_have_stateid)
return nfserr_bad_stateid;
memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t));
+ if (!(statusmask & SC_STATUS_KEEP_SEQID))
+ stateid->si_generation = 0;
}
/*
* only return revoked delegations if explicitly asked.
@@ -7523,6 +7525,7 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
if (!cstate->current_fh.fh_have_stateid)
return nfserr_bad_stateid;
memcpy(stateid, &cstate->current_stateid, sizeof(stateid_t));
+ stateid->si_generation = 0;
}
spin_lock(&cl->cl_lock);
@@ -7645,15 +7648,17 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
return status;
}
-static __be32 nfs4_preprocess_confirmed_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
- stateid_t *stateid, struct nfs4_ol_stateid **stpp, struct nfsd_net *nn)
+static __be32
+nfs4_preprocess_confirmed_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
+ stateid_t *stateid, struct nfs4_ol_stateid **stpp,
+ struct nfsd_net *nn, unsigned short statusmask)
{
__be32 status;
struct nfs4_openowner *oo;
struct nfs4_ol_stateid *stp;
status = nfs4_preprocess_seqid_op(cstate, seqid, stateid,
- SC_TYPE_OPEN, 0, &stp, nn);
+ SC_TYPE_OPEN, statusmask, &stp, nn);
if (status)
return status;
oo = openowner(stp->st_stateowner);
@@ -7751,7 +7756,8 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
od->od_deleg_want);
status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid,
- &od->od_stateid, &stp, nn);
+ &od->od_stateid, &stp, nn,
+ SC_STATUS_KEEP_SEQID);
if (status)
goto out;
status = nfserr_inval;
@@ -7821,7 +7827,8 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid,
&close->cl_stateid,
- SC_TYPE_OPEN, SC_STATUS_CLOSED,
+ SC_TYPE_OPEN,
+ SC_STATUS_CLOSED | SC_STATUS_KEEP_SEQID,
&stp, nn);
nfsd4_bump_seqid(cstate, status);
if (status)
@@ -8313,10 +8320,9 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
sizeof(clientid_t));
/* validate and update open stateid and open seqid */
- status = nfs4_preprocess_confirmed_seqid_op(cstate,
- lock->lk_new_open_seqid,
- &lock->lk_new_open_stateid,
- &open_stp, nn);
+ status = nfs4_preprocess_confirmed_seqid_op(
+ cstate, lock->lk_new_open_seqid,
+ &lock->lk_new_open_stateid, &open_stp, nn, 0);
if (status)
goto out;
mutex_unlock(&open_stp->st_mutex);
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index c6e97d6daa5f..6043baf10ceb 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -138,6 +138,12 @@ struct nfs4_stid {
#define SC_STATUS_ADMIN_REVOKED BIT(2)
#define SC_STATUS_FREEABLE BIT(3)
#define SC_STATUS_FREED BIT(4)
+/*
+ * Ops other than CLOSE and OPEN_DOWNGRADE which use the "current stateid"
+ * must clear the seqid (aka si_generation). Following flag is never stored
+ * in states but is passed through to request the seq not be cleared.
+ */
+#define SC_STATUS_KEEP_SEQID BIT(5)
unsigned short sc_status;
struct list_head sc_cp_list;
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2025-11-19 3:33 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-19 3:28 [PATCH v5 00/11] nfsd: assorted cleanups involving v4 special stateids NeilBrown
2025-11-19 3:28 ` [PATCH v5 01/11] nfsd: rename ALLOWED_WITHOUT_FH to ALLOWED_WITHOUT_LOCAL_FH and revise use NeilBrown
2025-11-19 16:02 ` Chuck Lever
2025-11-19 21:13 ` NeilBrown
2025-11-19 19:12 ` Jeff Layton
2025-11-19 3:28 ` [PATCH v5 02/11] nfsd: discard NFSD4_FH_FOREIGN NeilBrown
2025-11-19 16:27 ` Chuck Lever
2025-11-19 21:25 ` NeilBrown
2025-11-19 19:13 ` Jeff Layton
2025-11-19 3:28 ` [PATCH v5 03/11] nfsd: simplify foreign-filehandle handling to better match RFC-7862 NeilBrown
2025-11-19 16:55 ` Chuck Lever
2025-11-19 21:38 ` NeilBrown
2025-11-20 21:58 ` Chuck Lever
2025-11-22 0:46 ` NeilBrown
2025-11-19 19:23 ` Jeff Layton
2025-11-19 3:28 ` [PATCH v5 04/11] nfsd: report correct error for attempt to use foreign filehandle NeilBrown
2025-11-19 19:26 ` Jeff Layton
2025-11-19 3:28 ` [PATCH v5 05/11] nfsd: drop explicit tests for special stateids which would be invalid NeilBrown
2025-11-19 19:11 ` Chuck Lever
2025-11-19 19:32 ` Jeff Layton
2025-11-19 3:28 ` [PATCH v5 06/11] nfsd: revise names of special stateid, and predicate functions NeilBrown
2025-11-19 19:27 ` Chuck Lever
2025-11-19 21:47 ` NeilBrown
2025-11-19 3:28 ` [PATCH v5 07/11] nfsd: simplify clearing of current-state-id NeilBrown
2025-11-19 20:23 ` Chuck Lever
2025-11-19 21:55 ` NeilBrown
2025-11-19 3:28 ` [PATCH v5 08/11] nfsd: simplify use of the current stateid NeilBrown
2025-11-19 3:28 ` [PATCH v5 09/11] nfsd: simplify saving " NeilBrown
2025-11-19 3:28 ` [PATCH v5 10/11] nfsd: discard current_stateid.h NeilBrown
2025-11-19 3:28 ` NeilBrown [this message]
2025-11-19 20:32 ` [PATCH v5 00/11] nfsd: assorted cleanups involving v4 special stateids Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251119033204.360415-12-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox