Commit 599e0a22 authored by J. Bruce Fields's avatar J. Bruce Fields

knfsd: cleanup of nfsd4 cmp_* functions

Benny Halevy suggested renaming cmp_* to same_* to make the meaning of
the return value clearer.

Fix some nearby style deviations while we're at it, including a small
swath of creative indentation in nfs4_preprocess_seqid_op().
Signed-off-by: default avatar"J. Bruce Fields" <bfields@citi.umich.edu>
Acked-by: default avatarNeil Brown <neilb@suse.de>
parent 3b398f0e
...@@ -462,26 +462,28 @@ copy_cred(struct svc_cred *target, struct svc_cred *source) { ...@@ -462,26 +462,28 @@ copy_cred(struct svc_cred *target, struct svc_cred *source) {
} }
static inline int static inline int
same_name(const char *n1, const char *n2) { same_name(const char *n1, const char *n2)
{
return 0 == memcmp(n1, n2, HEXDIR_LEN); return 0 == memcmp(n1, n2, HEXDIR_LEN);
} }
static int static int
cmp_verf(nfs4_verifier *v1, nfs4_verifier *v2) { same_verf(nfs4_verifier *v1, nfs4_verifier *v2)
return(!memcmp(v1->data,v2->data,sizeof(v1->data))); {
return 0 == memcmp(v1->data, v2->data, sizeof(v1->data));
} }
static int static int
cmp_clid(clientid_t * cl1, clientid_t * cl2) { same_clid(clientid_t *cl1, clientid_t *cl2)
return((cl1->cl_boot == cl2->cl_boot) && {
(cl1->cl_id == cl2->cl_id)); return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id);
} }
/* XXX what about NGROUP */ /* XXX what about NGROUP */
static int static int
cmp_creds(struct svc_cred *cr1, struct svc_cred *cr2){ same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
return(cr1->cr_uid == cr2->cr_uid); {
return cr1->cr_uid == cr2->cr_uid;
} }
static void static void
...@@ -546,7 +548,7 @@ find_confirmed_client(clientid_t *clid) ...@@ -546,7 +548,7 @@ find_confirmed_client(clientid_t *clid)
unsigned int idhashval = clientid_hashval(clid->cl_id); unsigned int idhashval = clientid_hashval(clid->cl_id);
list_for_each_entry(clp, &conf_id_hashtbl[idhashval], cl_idhash) { list_for_each_entry(clp, &conf_id_hashtbl[idhashval], cl_idhash) {
if (cmp_clid(&clp->cl_clientid, clid)) if (same_clid(&clp->cl_clientid, clid))
return clp; return clp;
} }
return NULL; return NULL;
...@@ -559,7 +561,7 @@ find_unconfirmed_client(clientid_t *clid) ...@@ -559,7 +561,7 @@ find_unconfirmed_client(clientid_t *clid)
unsigned int idhashval = clientid_hashval(clid->cl_id); unsigned int idhashval = clientid_hashval(clid->cl_id);
list_for_each_entry(clp, &unconf_id_hashtbl[idhashval], cl_idhash) { list_for_each_entry(clp, &unconf_id_hashtbl[idhashval], cl_idhash) {
if (cmp_clid(&clp->cl_clientid, clid)) if (same_clid(&clp->cl_clientid, clid))
return clp; return clp;
} }
return NULL; return NULL;
...@@ -753,7 +755,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -753,7 +755,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
* or different ip_address * or different ip_address
*/ */
status = nfserr_clid_inuse; status = nfserr_clid_inuse;
if (!cmp_creds(&conf->cl_cred, &rqstp->rq_cred) if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)
|| conf->cl_addr != sin->sin_addr.s_addr) { || conf->cl_addr != sin->sin_addr.s_addr) {
dprintk("NFSD: setclientid: string in use by client" dprintk("NFSD: setclientid: string in use by client"
"at %u.%u.%u.%u\n", NIPQUAD(conf->cl_addr)); "at %u.%u.%u.%u\n", NIPQUAD(conf->cl_addr));
...@@ -779,7 +781,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -779,7 +781,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
gen_confirm(new); gen_confirm(new);
gen_callback(new, setclid); gen_callback(new, setclid);
add_to_unconfirmed(new, strhashval); add_to_unconfirmed(new, strhashval);
} else if (cmp_verf(&conf->cl_verifier, &clverifier)) { } else if (same_verf(&conf->cl_verifier, &clverifier)) {
/* /*
* CASE 1: * CASE 1:
* cl_name match, confirmed, principal match * cl_name match, confirmed, principal match
...@@ -830,7 +832,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, ...@@ -830,7 +832,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
gen_confirm(new); gen_confirm(new);
gen_callback(new, setclid); gen_callback(new, setclid);
add_to_unconfirmed(new, strhashval); add_to_unconfirmed(new, strhashval);
} else if (!cmp_verf(&conf->cl_confirm, &unconf->cl_confirm)) { } else if (!same_verf(&conf->cl_confirm, &unconf->cl_confirm)) {
/* /*
* CASE3: * CASE3:
* confirmed found (name, principal match) * confirmed found (name, principal match)
...@@ -910,16 +912,16 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp, ...@@ -910,16 +912,16 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
goto out; goto out;
if ((conf && unconf) && if ((conf && unconf) &&
(cmp_verf(&unconf->cl_confirm, &confirm)) && (same_verf(&unconf->cl_confirm, &confirm)) &&
(cmp_verf(&conf->cl_verifier, &unconf->cl_verifier)) && (same_verf(&conf->cl_verifier, &unconf->cl_verifier)) &&
(same_name(conf->cl_recdir,unconf->cl_recdir)) && (same_name(conf->cl_recdir,unconf->cl_recdir)) &&
(!cmp_verf(&conf->cl_confirm, &unconf->cl_confirm))) { (!same_verf(&conf->cl_confirm, &unconf->cl_confirm))) {
/* CASE 1: /* CASE 1:
* unconf record that matches input clientid and input confirm. * unconf record that matches input clientid and input confirm.
* conf record that matches input clientid. * conf record that matches input clientid.
* conf and unconf records match names, verifiers * conf and unconf records match names, verifiers
*/ */
if (!cmp_creds(&conf->cl_cred, &unconf->cl_cred)) if (!same_creds(&conf->cl_cred, &unconf->cl_cred))
status = nfserr_clid_inuse; status = nfserr_clid_inuse;
else { else {
/* XXX: We just turn off callbacks until we can handle /* XXX: We just turn off callbacks until we can handle
...@@ -933,7 +935,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp, ...@@ -933,7 +935,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
} }
} else if ((conf && !unconf) || } else if ((conf && !unconf) ||
((conf && unconf) && ((conf && unconf) &&
(!cmp_verf(&conf->cl_verifier, &unconf->cl_verifier) || (!same_verf(&conf->cl_verifier, &unconf->cl_verifier) ||
!same_name(conf->cl_recdir, unconf->cl_recdir)))) { !same_name(conf->cl_recdir, unconf->cl_recdir)))) {
/* CASE 2: /* CASE 2:
* conf record that matches input clientid. * conf record that matches input clientid.
...@@ -941,18 +943,18 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp, ...@@ -941,18 +943,18 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
* unconf->cl_name or unconf->cl_verifier don't match the * unconf->cl_name or unconf->cl_verifier don't match the
* conf record. * conf record.
*/ */
if (!cmp_creds(&conf->cl_cred,&rqstp->rq_cred)) if (!same_creds(&conf->cl_cred, &rqstp->rq_cred))
status = nfserr_clid_inuse; status = nfserr_clid_inuse;
else else
status = nfs_ok; status = nfs_ok;
} else if (!conf && unconf } else if (!conf && unconf
&& cmp_verf(&unconf->cl_confirm, &confirm)) { && same_verf(&unconf->cl_confirm, &confirm)) {
/* CASE 3: /* CASE 3:
* conf record not found. * conf record not found.
* unconf record found. * unconf record found.
* unconf->cl_confirm matches input confirm * unconf->cl_confirm matches input confirm
*/ */
if (!cmp_creds(&unconf->cl_cred, &rqstp->rq_cred)) { if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred)) {
status = nfserr_clid_inuse; status = nfserr_clid_inuse;
} else { } else {
unsigned int hash = unsigned int hash =
...@@ -967,8 +969,8 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp, ...@@ -967,8 +969,8 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
conf = unconf; conf = unconf;
status = nfs_ok; status = nfs_ok;
} }
} else if ((!conf || (conf && !cmp_verf(&conf->cl_confirm, &confirm))) } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm)))
&& (!unconf || (unconf && !cmp_verf(&unconf->cl_confirm, && (!unconf || (unconf && !same_verf(&unconf->cl_confirm,
&confirm)))) { &confirm)))) {
/* CASE 4: /* CASE 4:
* conf record not found, or if conf, conf->cl_confirm does not * conf record not found, or if conf, conf->cl_confirm does not
...@@ -1207,10 +1209,12 @@ move_to_close_lru(struct nfs4_stateowner *sop) ...@@ -1207,10 +1209,12 @@ move_to_close_lru(struct nfs4_stateowner *sop)
} }
static int static int
cmp_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner, clientid_t *clid) { same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner,
return ((sop->so_owner.len == owner->len) && clientid_t *clid)
!memcmp(sop->so_owner.data, owner->data, owner->len) && {
(sop->so_client->cl_clientid.cl_id == clid->cl_id)); return (sop->so_owner.len == owner->len) &&
0 == memcmp(sop->so_owner.data, owner->data, owner->len) &&
(sop->so_client->cl_clientid.cl_id == clid->cl_id);
} }
static struct nfs4_stateowner * static struct nfs4_stateowner *
...@@ -1219,7 +1223,7 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open) ...@@ -1219,7 +1223,7 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open)
struct nfs4_stateowner *so = NULL; struct nfs4_stateowner *so = NULL;
list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) { list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) {
if (cmp_owner_str(so, &open->op_owner, &open->op_clientid)) if (same_owner_str(so, &open->op_owner, &open->op_clientid))
return so; return so;
} }
return NULL; return NULL;
...@@ -2181,21 +2185,20 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei ...@@ -2181,21 +2185,20 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
lkflg = setlkflg(lock->lk_type); lkflg = setlkflg(lock->lk_type);
if (lock->lk_is_new) { if (lock->lk_is_new) {
if (!sop->so_is_open_owner) if (!sop->so_is_open_owner)
return nfserr_bad_stateid; return nfserr_bad_stateid;
if (!cmp_clid(&clp->cl_clientid, lockclid)) if (!same_clid(&clp->cl_clientid, lockclid))
return nfserr_bad_stateid; return nfserr_bad_stateid;
/* stp is the open stateid */ /* stp is the open stateid */
status = nfs4_check_openmode(stp, lkflg); status = nfs4_check_openmode(stp, lkflg);
if (status) if (status)
return status; return status;
} else { } else {
/* stp is the lock stateid */ /* stp is the lock stateid */
status = nfs4_check_openmode(stp->st_openstp, lkflg); status = nfs4_check_openmode(stp->st_openstp, lkflg);
if (status) if (status)
return status; return status;
} }
} }
if ((flags & CHECK_FH) && nfs4_check_fh(current_fh, stp)) { if ((flags & CHECK_FH) && nfs4_check_fh(current_fh, stp)) {
...@@ -2561,7 +2564,7 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid, ...@@ -2561,7 +2564,7 @@ find_lockstateowner_str(struct inode *inode, clientid_t *clid,
struct nfs4_stateowner *op; struct nfs4_stateowner *op;
list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) { list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) {
if (cmp_owner_str(op, owner, clid)) if (same_owner_str(op, owner, clid))
return op; return op;
} }
return NULL; return NULL;
...@@ -3025,7 +3028,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, ...@@ -3025,7 +3028,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
INIT_LIST_HEAD(&matches); INIT_LIST_HEAD(&matches);
for (i = 0; i < LOCK_HASH_SIZE; i++) { for (i = 0; i < LOCK_HASH_SIZE; i++) {
list_for_each_entry(sop, &lock_ownerid_hashtbl[i], so_idhash) { list_for_each_entry(sop, &lock_ownerid_hashtbl[i], so_idhash) {
if (!cmp_owner_str(sop, owner, clid)) if (!same_owner_str(sop, owner, clid))
continue; continue;
list_for_each_entry(stp, &sop->so_stateids, list_for_each_entry(stp, &sop->so_stateids,
st_perstateowner) { st_perstateowner) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment