Skip to content

Commit 23df177

Browse files
neilbrownchucklever
authored andcommitted
nfsd: perform all find_openstateowner_str calls in the one place.
Currently find_openstateowner_str look ups are done both in nfsd4_process_open1() and alloc_init_open_stateowner() - the latter possibly being a surprise based on its name. It would be easier to follow, and more conformant to common patterns, if the lookup was all in the one place. So replace alloc_init_open_stateowner() with find_or_alloc_open_stateowner() and use the latter in nfsd4_process_open1() without any calls to find_openstateowner_str(). This means all finds are find_openstateowner_str_locked() and find_openstateowner_str() is no longer needed. So discard find_openstateowner_str() and rename find_openstateowner_str_locked() to find_openstateowner_str(). Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent dd5a440 commit 23df177

File tree

1 file changed

+40
-53
lines changed

1 file changed

+40
-53
lines changed

fs/nfsd/nfs4state.c

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner)
541541
}
542542

543543
static struct nfs4_openowner *
544-
find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open,
544+
find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open,
545545
struct nfs4_client *clp)
546546
{
547547
struct nfs4_stateowner *so;
@@ -558,18 +558,6 @@ find_openstateowner_str_locked(unsigned int hashval, struct nfsd4_open *open,
558558
return NULL;
559559
}
560560

561-
static struct nfs4_openowner *
562-
find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open,
563-
struct nfs4_client *clp)
564-
{
565-
struct nfs4_openowner *oo;
566-
567-
spin_lock(&clp->cl_lock);
568-
oo = find_openstateowner_str_locked(hashval, open, clp);
569-
spin_unlock(&clp->cl_lock);
570-
return oo;
571-
}
572-
573561
static inline u32
574562
opaque_hashval(const void *ptr, int nbytes)
575563
{
@@ -4866,34 +4854,46 @@ nfsd4_find_and_lock_existing_open(struct nfs4_file *fp, struct nfsd4_open *open)
48664854
}
48674855

48684856
static struct nfs4_openowner *
4869-
alloc_init_open_stateowner(unsigned int strhashval, struct nfsd4_open *open,
4870-
struct nfsd4_compound_state *cstate)
4857+
find_or_alloc_open_stateowner(unsigned int strhashval, struct nfsd4_open *open,
4858+
struct nfsd4_compound_state *cstate)
48714859
{
48724860
struct nfs4_client *clp = cstate->clp;
4873-
struct nfs4_openowner *oo, *ret;
4861+
struct nfs4_openowner *oo, *new = NULL;
48744862

4875-
oo = alloc_stateowner(openowner_slab, &open->op_owner, clp);
4876-
if (!oo)
4877-
return NULL;
4878-
oo->oo_owner.so_ops = &openowner_ops;
4879-
oo->oo_owner.so_is_open_owner = 1;
4880-
oo->oo_owner.so_seqid = open->op_seqid;
4881-
oo->oo_flags = 0;
4882-
if (nfsd4_has_session(cstate))
4883-
oo->oo_flags |= NFS4_OO_CONFIRMED;
4884-
oo->oo_time = 0;
4885-
oo->oo_last_closed_stid = NULL;
4886-
INIT_LIST_HEAD(&oo->oo_close_lru);
4863+
retry:
48874864
spin_lock(&clp->cl_lock);
4888-
ret = find_openstateowner_str_locked(strhashval, open, clp);
4889-
if (ret == NULL) {
4890-
hash_openowner(oo, clp, strhashval);
4891-
ret = oo;
4892-
} else
4893-
nfs4_free_stateowner(&oo->oo_owner);
4894-
4865+
oo = find_openstateowner_str(strhashval, open, clp);
4866+
if (!oo && new) {
4867+
hash_openowner(new, clp, strhashval);
4868+
spin_unlock(&clp->cl_lock);
4869+
return new;
4870+
}
48954871
spin_unlock(&clp->cl_lock);
4896-
return ret;
4872+
4873+
if (oo && !(oo->oo_flags & NFS4_OO_CONFIRMED)) {
4874+
/* Replace unconfirmed owners without checking for replay. */
4875+
release_openowner(oo);
4876+
oo = NULL;
4877+
}
4878+
if (oo) {
4879+
if (new)
4880+
nfs4_free_stateowner(&new->oo_owner);
4881+
return oo;
4882+
}
4883+
4884+
new = alloc_stateowner(openowner_slab, &open->op_owner, clp);
4885+
if (!new)
4886+
return NULL;
4887+
new->oo_owner.so_ops = &openowner_ops;
4888+
new->oo_owner.so_is_open_owner = 1;
4889+
new->oo_owner.so_seqid = open->op_seqid;
4890+
new->oo_flags = 0;
4891+
if (nfsd4_has_session(cstate))
4892+
new->oo_flags |= NFS4_OO_CONFIRMED;
4893+
new->oo_time = 0;
4894+
new->oo_last_closed_stid = NULL;
4895+
INIT_LIST_HEAD(&new->oo_close_lru);
4896+
goto retry;
48974897
}
48984898

48994899
static struct nfs4_ol_stateid *
@@ -5342,27 +5342,14 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
53425342
clp = cstate->clp;
53435343

53445344
strhashval = ownerstr_hashval(&open->op_owner);
5345-
oo = find_openstateowner_str(strhashval, open, clp);
5345+
oo = find_or_alloc_open_stateowner(strhashval, open, cstate);
53465346
open->op_openowner = oo;
5347-
if (!oo) {
5348-
goto new_owner;
5349-
}
5350-
if (!(oo->oo_flags & NFS4_OO_CONFIRMED)) {
5351-
/* Replace unconfirmed owners without checking for replay. */
5352-
release_openowner(oo);
5353-
open->op_openowner = NULL;
5354-
goto new_owner;
5355-
}
5347+
if (!oo)
5348+
return nfserr_jukebox;
53565349
status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid);
53575350
if (status)
53585351
return status;
5359-
goto alloc_stateid;
5360-
new_owner:
5361-
oo = alloc_init_open_stateowner(strhashval, open, cstate);
5362-
if (oo == NULL)
5363-
return nfserr_jukebox;
5364-
open->op_openowner = oo;
5365-
alloc_stateid:
5352+
53665353
open->op_stp = nfs4_alloc_open_stateid(clp);
53675354
if (!open->op_stp)
53685355
return nfserr_jukebox;

0 commit comments

Comments
 (0)