nfsd: allow SC_STATUS_FREEABLE when searching via nfs4_lookup_stateid()
authorJeff Layton <jlayton@kernel.org>
Thu, 13 Feb 2025 14:08:29 +0000 (09:08 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 10 Mar 2025 13:11:00 +0000 (09:11 -0400)
The pynfs DELEG8 test fails when run against nfsd. It acquires a
delegation and then lets the lease time out. It then tries to use the
deleg stateid and expects to see NFS4ERR_DELEG_REVOKED, but it gets
bad NFS4ERR_BAD_STATEID instead.

When a delegation is revoked, it's initially marked with
SC_STATUS_REVOKED, or SC_STATUS_ADMIN_REVOKED and later, it's marked
with the SC_STATUS_FREEABLE flag, which denotes that it is waiting for
s FREE_STATEID call.

nfs4_lookup_stateid() accepts a statusmask that includes the status
flags that a found stateid is allowed to have. Currently, that mask
never includes SC_STATUS_FREEABLE, which means that revoked delegations
are (almost) never found.

Add SC_STATUS_FREEABLE to the always-allowed status flags, and remove it
from nfsd4_delegreturn() since it's now always implied.

Fixes: 8dd91e8d31fe ("nfsd: fix race between laundromat and free_stateid")
Cc: stable@vger.kernel.org
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4state.c

index b42e2ab7a042239c1809ead5f39195ed8675d088..09db729f1219cdbd8208fc00acee62fb085fb90d 100644 (file)
@@ -7057,7 +7057,7 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate,
                 */
                statusmask |= SC_STATUS_REVOKED;
 
-       statusmask |= SC_STATUS_ADMIN_REVOKED;
+       statusmask |= SC_STATUS_ADMIN_REVOKED | SC_STATUS_FREEABLE;
 
        if (ZERO_STATEID(stateid) || ONE_STATEID(stateid) ||
                CLOSE_STATEID(stateid))
@@ -7712,9 +7712,7 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
                return status;
 
-       status = nfsd4_lookup_stateid(cstate, stateid, SC_TYPE_DELEG,
-                                     SC_STATUS_REVOKED | SC_STATUS_FREEABLE,
-                                     &s, nn);
+       status = nfsd4_lookup_stateid(cstate, stateid, SC_TYPE_DELEG, SC_STATUS_REVOKED, &s, nn);
        if (status)
                goto out;
        dp = delegstateid(s);