Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 3f29cc8

Browse files
neilbrownchucklever
authored andcommitted
nfsd: split sc_status out of sc_type
sc_type identifies the type of a state - open, lock, deleg, layout - and also the status of a state - closed or revoked. This is a bit untidy and could get worse when "admin-revoked" states are added. So clean it up. With this patch, the type is now all that is stored in sc_type. This is zero when the state is first added to ->cl_stateids (causing it to be ignored), and is then set appropriately once it is fully initialised. It is set under ->cl_lock to ensure atomicity w.r.t lookup. It is now never cleared. sc_type is still a bit-set even though at most one bit is set. This allows lookup functions to be given a bitmap of acceptable types. sc_type is now an unsigned short rather than char. There is no value in restricting to just 8 bits. All the constants now start SC_TYPE_ matching the field in which they are stored. Keeping the existing names and ensuring clear separation from non-type flags would have required something like NFS4_STID_TYPE_CLOSED which is cumbersome. The "NFS4" prefix is redundant was they only appear in NFS4 code, so remove that and change STID to SC to match the field. The status is stored in a separate unsigned short named "sc_status". It has two flags: SC_STATUS_CLOSED and SC_STATUS_REVOKED. CLOSED combines NFS4_CLOSED_STID, NFS4_CLOSED_DELEG_STID, and is used for SC_TYPE_LOCK and SC_TYPE_LAYOUT instead of setting the sc_type to zero. These flags are only ever set, never cleared. For deleg stateids they are set under the global state_lock. For open and lock stateids they are set under ->cl_lock. For layout stateids they are set under ->ls_lock nfs4_unhash_stid() has been removed, and we never set sc_type = 0. This was only used for LOCK and LAYOUT stids and they now use SC_STATUS_CLOSED. Also TRACE_DEFINE_NUM() calls for the various STID #define have been removed because these things are not enums, and so that call is incorrect. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 83e7331 commit 3f29cc8

File tree

4 files changed

+151
-141
lines changed

4 files changed

+151
-141
lines changed

fs/nfsd/nfs4layouts.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate,
236236
nfsd4_init_cb(&ls->ls_recall, clp, &nfsd4_cb_layout_ops,
237237
NFSPROC4_CLNT_CB_LAYOUT);
238238

239-
if (parent->sc_type == NFS4_DELEG_STID)
239+
if (parent->sc_type == SC_TYPE_DELEG)
240240
ls->ls_file = nfsd_file_get(fp->fi_deleg_file);
241241
else
242242
ls->ls_file = find_any_file(fp);
@@ -250,7 +250,7 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate,
250250
}
251251

252252
spin_lock(&clp->cl_lock);
253-
stp->sc_type = NFS4_LAYOUT_STID;
253+
stp->sc_type = SC_TYPE_LAYOUT;
254254
list_add(&ls->ls_perclnt, &clp->cl_lo_states);
255255
spin_unlock(&clp->cl_lock);
256256

@@ -269,13 +269,13 @@ nfsd4_preprocess_layout_stateid(struct svc_rqst *rqstp,
269269
{
270270
struct nfs4_layout_stateid *ls;
271271
struct nfs4_stid *stid;
272-
unsigned char typemask = NFS4_LAYOUT_STID;
272+
unsigned short typemask = SC_TYPE_LAYOUT;
273273
__be32 status;
274274

275275
if (create)
276-
typemask |= (NFS4_OPEN_STID | NFS4_LOCK_STID | NFS4_DELEG_STID);
276+
typemask |= (SC_TYPE_OPEN | SC_TYPE_LOCK | SC_TYPE_DELEG);
277277

278-
status = nfsd4_lookup_stateid(cstate, stateid, typemask, &stid,
278+
status = nfsd4_lookup_stateid(cstate, stateid, typemask, 0, &stid,
279279
net_generic(SVC_NET(rqstp), nfsd_net_id));
280280
if (status)
281281
goto out;
@@ -286,7 +286,7 @@ nfsd4_preprocess_layout_stateid(struct svc_rqst *rqstp,
286286
goto out_put_stid;
287287
}
288288

289-
if (stid->sc_type != NFS4_LAYOUT_STID) {
289+
if (stid->sc_type != SC_TYPE_LAYOUT) {
290290
ls = nfsd4_alloc_layout_stateid(cstate, stid, layout_type);
291291
nfs4_put_stid(stid);
292292

@@ -518,7 +518,7 @@ nfsd4_return_file_layouts(struct svc_rqst *rqstp,
518518
lrp->lrs_present = true;
519519
} else {
520520
trace_nfsd_layoutstate_unhash(&ls->ls_stid.sc_stateid);
521-
nfs4_unhash_stid(&ls->ls_stid);
521+
ls->ls_stid.sc_status |= SC_STATUS_CLOSED;
522522
lrp->lrs_present = false;
523523
}
524524
spin_unlock(&ls->ls_lock);

0 commit comments

Comments
 (0)