From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Chuck Lever <chuck.lever@oracle.com>
Subject: Re: [PATCH v5 1/7] NFSD: Extract revoke_one_stid() utility function
Date: Fri, 27 Mar 2026 08:00:26 -0400 [thread overview]
Message-ID: <884708aef3b2cf3574b4c7db6cc9f82a53a66d9d.camel@kernel.org> (raw)
In-Reply-To: <20260326-umount-kills-nfsv4-state-v5-1-d2ce071b3570@oracle.com>
On Thu, 2026-03-26 at 13:55 -0400, Chuck Lever wrote:
> From: Chuck Lever <chuck.lever@oracle.com>
>
> The per-stateid revocation logic in nfsd4_revoke_states() handles
> four stateid types in a deeply nested switch. Extract two helpers:
>
> revoke_ol_stid() performs admin-revocation of an open or lock
> stateid with st_mutex already held: marks the stateid as
> SC_STATUS_ADMIN_REVOKED, closes POSIX locks for lock stateids,
> and releases file access.
>
> revoke_one_stid() dispatches by sc_type, acquires st_mutex with
> the appropriate lockdep class for open and lock stateids, and
> handles delegation unhash and layout close inline.
>
> No functional change. Preparation for adding export-scoped state
> revocation which reuses revoke_one_stid().
>
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
> fs/nfsd/nfs4state.c | 137 ++++++++++++++++++++++++++--------------------------
> 1 file changed, 68 insertions(+), 69 deletions(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index 07df4511ba23..eb1bd1aae8f5 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -1775,6 +1775,73 @@ static struct nfs4_stid *find_one_sb_stid(struct nfs4_client *clp,
> return stid;
> }
>
> +static void revoke_ol_stid(struct nfs4_client *clp,
> + struct nfs4_ol_stateid *stp)
> +{
> + struct nfs4_stid *stid = &stp->st_stid;
> +
> + lockdep_assert_held(&stp->st_mutex);
> + spin_lock(&clp->cl_lock);
> + if (stid->sc_status == 0) {
> + stid->sc_status |= SC_STATUS_ADMIN_REVOKED;
> + atomic_inc(&clp->cl_admin_revoked);
> + spin_unlock(&clp->cl_lock);
> + if (stid->sc_type == SC_TYPE_LOCK) {
> + struct nfs4_lockowner *lo =
> + lockowner(stp->st_stateowner);
> + struct nfsd_file *nf;
> +
> + nf = find_any_file(stp->st_stid.sc_file);
> + if (nf) {
> + get_file(nf->nf_file);
> + filp_close(nf->nf_file, (fl_owner_t)lo);
> + nfsd_file_put(nf);
> + }
> + }
> + release_all_access(stp);
> + } else
> + spin_unlock(&clp->cl_lock);
> +}
> +
> +static void revoke_one_stid(struct nfs4_client *clp, struct nfs4_stid *stid)
> +{
> + struct nfs4_ol_stateid *stp;
> + struct nfs4_delegation *dp;
> +
> + switch (stid->sc_type) {
> + case SC_TYPE_OPEN:
> + stp = openlockstateid(stid);
> + mutex_lock_nested(&stp->st_mutex, OPEN_STATEID_MUTEX);
> + revoke_ol_stid(clp, stp);
> + mutex_unlock(&stp->st_mutex);
> + break;
> + case SC_TYPE_LOCK:
> + stp = openlockstateid(stid);
> + mutex_lock_nested(&stp->st_mutex, LOCK_STATEID_MUTEX);
> + revoke_ol_stid(clp, stp);
> + mutex_unlock(&stp->st_mutex);
> + break;
> + case SC_TYPE_DELEG:
> + /*
> + * Extra reference guards against concurrent FREE_STATEID.
> + */
> + refcount_inc(&stid->sc_count);
> + dp = delegstateid(stid);
> + spin_lock(&state_lock);
> + if (!unhash_delegation_locked(dp, SC_STATUS_ADMIN_REVOKED))
> + dp = NULL;
> + spin_unlock(&state_lock);
> + if (dp)
> + revoke_delegation(dp);
> + else
> + nfs4_put_stid(stid);
> + break;
> + case SC_TYPE_LAYOUT:
> + nfsd4_close_layout(layoutstateid(stid));
> + break;
> + }
> +}
> +
> /**
> * nfsd4_revoke_states - revoke all nfsv4 states associated with given filesystem
> * @nn: used to identify instance of nfsd (there is one per net namespace)
> @@ -1805,76 +1872,8 @@ void nfsd4_revoke_states(struct nfsd_net *nn, struct super_block *sb)
> struct nfs4_stid *stid = find_one_sb_stid(clp, sb,
> sc_types);
> if (stid) {
> - struct nfs4_ol_stateid *stp;
> - struct nfs4_delegation *dp;
> - struct nfs4_layout_stateid *ls;
> -
> spin_unlock(&nn->client_lock);
> - switch (stid->sc_type) {
> - case SC_TYPE_OPEN:
> - stp = openlockstateid(stid);
> - mutex_lock_nested(&stp->st_mutex,
> - OPEN_STATEID_MUTEX);
> -
> - spin_lock(&clp->cl_lock);
> - if (stid->sc_status == 0) {
> - stid->sc_status |=
> - SC_STATUS_ADMIN_REVOKED;
> - atomic_inc(&clp->cl_admin_revoked);
> - spin_unlock(&clp->cl_lock);
> - release_all_access(stp);
> - } else
> - spin_unlock(&clp->cl_lock);
> - mutex_unlock(&stp->st_mutex);
> - break;
> - case SC_TYPE_LOCK:
> - stp = openlockstateid(stid);
> - mutex_lock_nested(&stp->st_mutex,
> - LOCK_STATEID_MUTEX);
> - spin_lock(&clp->cl_lock);
> - if (stid->sc_status == 0) {
> - struct nfs4_lockowner *lo =
> - lockowner(stp->st_stateowner);
> - struct nfsd_file *nf;
> -
> - stid->sc_status |=
> - SC_STATUS_ADMIN_REVOKED;
> - atomic_inc(&clp->cl_admin_revoked);
> - spin_unlock(&clp->cl_lock);
> - nf = find_any_file(stp->st_stid.sc_file);
> - if (nf) {
> - get_file(nf->nf_file);
> - filp_close(nf->nf_file,
> - (fl_owner_t)lo);
> - nfsd_file_put(nf);
> - }
> - release_all_access(stp);
> - } else
> - spin_unlock(&clp->cl_lock);
> - mutex_unlock(&stp->st_mutex);
> - break;
> - case SC_TYPE_DELEG:
> - /* Extra reference guards against concurrent
> - * FREE_STATEID; revoke_delegation() consumes
> - * it, otherwise release it directly.
> - */
> - refcount_inc(&stid->sc_count);
> - dp = delegstateid(stid);
> - spin_lock(&nn->deleg_lock);
> - if (!unhash_delegation_locked(
> - dp, SC_STATUS_ADMIN_REVOKED))
> - dp = NULL;
> - spin_unlock(&nn->deleg_lock);
> - if (dp)
> - revoke_delegation(dp);
> - else
> - nfs4_put_stid(stid);
> - break;
> - case SC_TYPE_LAYOUT:
> - ls = layoutstateid(stid);
> - nfsd4_close_layout(ls);
> - break;
> - }
> + revoke_one_stid(clp, stid);
> nfs4_put_stid(stid);
> spin_lock(&nn->client_lock);
> if (clp->cl_minorversion == 0)
Nice little cleanup on its own. This could be merged ahead of the rest
of the series.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
next prev parent reply other threads:[~2026-03-27 12:00 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 17:55 [PATCH v5 0/7] Automatic NFSv4 state revocation on filesystem unmount Chuck Lever
2026-03-26 17:55 ` [PATCH v5 1/7] NFSD: Extract revoke_one_stid() utility function Chuck Lever
2026-03-27 5:26 ` kernel test robot
2026-03-27 5:56 ` kernel test robot
2026-03-27 10:08 ` kernel test robot
2026-03-27 11:13 ` kernel test robot
2026-03-27 12:00 ` Jeff Layton [this message]
2026-03-27 12:21 ` Jeff Layton
2026-03-27 14:18 ` Chuck Lever
2026-03-26 17:55 ` [PATCH v5 2/7] NFSD: Add NFSD_CMD_UNLOCK_IP netlink command Chuck Lever
2026-03-27 12:06 ` Jeff Layton
2026-03-27 15:19 ` Chuck Lever
2026-03-27 15:52 ` Jeff Layton
2026-03-27 16:02 ` Chuck Lever
2026-03-26 17:55 ` [PATCH v5 3/7] NFSD: Add NFSD_CMD_UNLOCK_FILESYSTEM " Chuck Lever
2026-03-26 17:55 ` [PATCH v5 4/7] NFSD: Replace idr_for_each_entry_ul in find_one_sb_stid() Chuck Lever
2026-03-26 17:55 ` [PATCH v5 5/7] NFSD: Track svc_export in nfs4_stid Chuck Lever
2026-03-26 17:55 ` [PATCH v5 6/7] NFSD: Add NFSD_CMD_UNLOCK_EXPORT netlink command Chuck Lever
2026-03-26 17:55 ` [PATCH v5 7/7] NFSD: Close cached file handles when revoking export state Chuck Lever
2026-03-27 12:03 ` [PATCH v5 0/7] Automatic NFSv4 state revocation on filesystem unmount Jeff Layton
2026-03-27 13:29 ` Chuck Lever
2026-03-27 12:18 ` Jeff Layton
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=884708aef3b2cf3574b4c7db6cc9f82a53a66d9d.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=cel@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=linux-fsdevel@vger.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