Commit 81ecc846 authored by Neil Brown's avatar Neil Brown Committed by Linus Torvalds

[PATCH] nfsd4: simplify find functions

Fix "find" functions that use return value redundantly.  Calculate hashes on
demand.  Miscellaneous kernel style.
Signed-off-by: default avatarJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: default avatarNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 46f18093
...@@ -968,8 +968,11 @@ static struct list_head stateid_hashtbl[STATEID_HASH_SIZE]; ...@@ -968,8 +968,11 @@ static struct list_head stateid_hashtbl[STATEID_HASH_SIZE];
/* OPEN Share state helper functions */ /* OPEN Share state helper functions */
static inline struct nfs4_file * static inline struct nfs4_file *
alloc_init_file(unsigned int hashval, struct inode *ino) { alloc_init_file(struct inode *ino)
{
struct nfs4_file *fp; struct nfs4_file *fp;
unsigned int hashval = file_hashval(ino);
if ((fp = kmalloc(sizeof(struct nfs4_file),GFP_KERNEL))) { if ((fp = kmalloc(sizeof(struct nfs4_file),GFP_KERNEL))) {
INIT_LIST_HEAD(&fp->fi_hash); INIT_LIST_HEAD(&fp->fi_hash);
INIT_LIST_HEAD(&fp->fi_perfile); INIT_LIST_HEAD(&fp->fi_perfile);
...@@ -1246,17 +1249,17 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open) ...@@ -1246,17 +1249,17 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open)
} }
/* search file_hashtbl[] for file */ /* search file_hashtbl[] for file */
static int static struct nfs4_file *
find_file(unsigned int hashval, struct inode *ino, struct nfs4_file **fp) { find_file(struct inode *ino)
struct nfs4_file *local = NULL; {
unsigned int hashval = file_hashval(ino);
struct nfs4_file *fp;
list_for_each_entry(local, &file_hashtbl[hashval], fi_hash) { list_for_each_entry(fp, &file_hashtbl[hashval], fi_hash) {
if (local->fi_inode == ino) { if (fp->fi_inode == ino)
*fp = local; return fp;
return(1);
}
} }
return 0; return NULL;
} }
#define TEST_ACCESS(x) ((x > 0 || x < 4)?1:0) #define TEST_ACCESS(x) ((x > 0 || x < 4)?1:0)
...@@ -1303,14 +1306,13 @@ int ...@@ -1303,14 +1306,13 @@ int
nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type) nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
{ {
struct inode *ino = current_fh->fh_dentry->d_inode; struct inode *ino = current_fh->fh_dentry->d_inode;
unsigned int fi_hashval;
struct nfs4_file *fp; struct nfs4_file *fp;
struct nfs4_stateid *stp; struct nfs4_stateid *stp;
dprintk("NFSD: nfs4_share_conflict\n"); dprintk("NFSD: nfs4_share_conflict\n");
fi_hashval = file_hashval(ino); fp = find_file(ino);
if (find_file(fi_hashval, ino, &fp)) { if (fp) {
/* Search for conflicting share reservations */ /* Search for conflicting share reservations */
list_for_each_entry(stp, &fp->fi_perfile, st_perfile) { list_for_each_entry(stp, &fp->fi_perfile, st_perfile) {
if (test_bit(deny_type, &stp->st_deny_bmap) || if (test_bit(deny_type, &stp->st_deny_bmap) ||
...@@ -1706,7 +1708,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf ...@@ -1706,7 +1708,6 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
struct nfs4_stateowner *sop = open->op_stateowner; struct nfs4_stateowner *sop = open->op_stateowner;
struct nfs4_file *fp = NULL; struct nfs4_file *fp = NULL;
struct inode *ino = current_fh->fh_dentry->d_inode; struct inode *ino = current_fh->fh_dentry->d_inode;
unsigned int fi_hashval;
struct nfs4_stateid *stp = NULL; struct nfs4_stateid *stp = NULL;
int status, delegflag = -1; int status, delegflag = -1;
...@@ -1718,15 +1719,16 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf ...@@ -1718,15 +1719,16 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
* and check for delegations in the process of being recalled. * and check for delegations in the process of being recalled.
* If not found, create the nfs4_file struct * If not found, create the nfs4_file struct
*/ */
fi_hashval = file_hashval(ino); fp = find_file(ino);
if (find_file(fi_hashval, ino, &fp)) { if (fp) {
if ((status = nfs4_check_open(fp, sop, open, &stp))) if ((status = nfs4_check_open(fp, sop, open, &stp)))
goto out; goto out;
if ((status = nfs4_check_deleg_recall(fp, open, &delegflag))) if ((status = nfs4_check_deleg_recall(fp, open, &delegflag)))
goto out; goto out;
} else { } else {
status = nfserr_resource; status = nfserr_resource;
if ((fp = alloc_init_file(fi_hashval, ino)) == NULL) fp = alloc_init_file(ino);
if (fp == NULL)
goto out; goto out;
} }
...@@ -2391,8 +2393,15 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd ...@@ -2391,8 +2393,15 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd
#define lockownerid_hashval(id) \ #define lockownerid_hashval(id) \
((id) & LOCK_HASH_MASK) ((id) & LOCK_HASH_MASK)
#define lock_ownerstr_hashval(x, clientid, ownername) \
((file_hashval(x) + (clientid) + opaque_hashval((ownername.data), (ownername.len))) & LOCK_HASH_MASK) static inline unsigned int
lock_ownerstr_hashval(struct inode *inode, u32 cl_id,
struct xdr_netobj *ownername)
{
return (file_hashval(inode) + cl_id
+ opaque_hashval(ownername->data, ownername->len))
& LOCK_HASH_MASK;
}
static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE]; static struct list_head lock_ownerid_hashtbl[LOCK_HASH_SIZE];
static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE]; static struct list_head lock_ownerstr_hashtbl[LOCK_HASH_SIZE];
...@@ -2433,15 +2442,14 @@ find_delegation_stateid(struct inode *ino, stateid_t *stid) ...@@ -2433,15 +2442,14 @@ find_delegation_stateid(struct inode *ino, stateid_t *stid)
struct nfs4_delegation *dp = NULL; struct nfs4_delegation *dp = NULL;
struct nfs4_file *fp = NULL; struct nfs4_file *fp = NULL;
u32 st_id; u32 st_id;
unsigned int fi_hashval;
dprintk("NFSD:find_delegation_stateid stateid=(%08x/%08x/%08x/%08x)\n", dprintk("NFSD:find_delegation_stateid stateid=(%08x/%08x/%08x/%08x)\n",
stid->si_boot, stid->si_stateownerid, stid->si_boot, stid->si_stateownerid,
stid->si_fileid, stid->si_generation); stid->si_fileid, stid->si_generation);
st_id = stid->si_stateownerid; st_id = stid->si_stateownerid;
fi_hashval = file_hashval(ino); fp = find_file(ino);
if (find_file(fi_hashval, ino, &fp)) { if (fp) {
list_for_each_entry(dp, &fp->fi_del_perfile, dl_del_perfile) { list_for_each_entry(dp, &fp->fi_del_perfile, dl_del_perfile) {
if(dp->dl_stateid.si_stateownerid == st_id) { if(dp->dl_stateid.si_stateownerid == st_id) {
dprintk("NFSD: find_delegation dp %p\n",dp); dprintk("NFSD: find_delegation dp %p\n",dp);
...@@ -2525,18 +2533,18 @@ find_lockstateowner(struct xdr_netobj *owner, clientid_t *clid) ...@@ -2525,18 +2533,18 @@ find_lockstateowner(struct xdr_netobj *owner, clientid_t *clid)
return NULL; return NULL;
} }
static int static struct nfs4_stateowner *
find_lockstateowner_str(unsigned int hashval, struct xdr_netobj *owner, clientid_t *clid, struct nfs4_stateowner **op) { find_lockstateowner_str(struct inode *inode, clientid_t *clid,
struct nfs4_stateowner *local = NULL; struct xdr_netobj *owner)
{
unsigned int hashval = lock_ownerstr_hashval(inode, clid->cl_id, owner);
struct nfs4_stateowner *op;
list_for_each_entry(local, &lock_ownerstr_hashtbl[hashval], so_strhash) { list_for_each_entry(op, &lock_ownerstr_hashtbl[hashval], so_strhash) {
if (!cmp_owner_str(local, owner, clid)) if (cmp_owner_str(op, owner, clid))
continue; return op;
*op = local;
return(1);
} }
*op = NULL; return NULL;
return 0;
} }
/* /*
...@@ -2684,7 +2692,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock ...@@ -2684,7 +2692,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
fp = open_stp->st_file; fp = open_stp->st_file;
strhashval = lock_ownerstr_hashval(fp->fi_inode, strhashval = lock_ownerstr_hashval(fp->fi_inode,
open_sop->so_client->cl_clientid.cl_id, open_sop->so_client->cl_clientid.cl_id,
lock->v.new.owner); &lock->v.new.owner);
/* /*
* If we already have this lock owner, the client is in * If we already have this lock owner, the client is in
* error (or our bookeeping is wrong!) * error (or our bookeeping is wrong!)
...@@ -2816,7 +2824,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock ...@@ -2816,7 +2824,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
struct file file; struct file file;
struct file_lock file_lock; struct file_lock file_lock;
struct file_lock *conflicting_lock; struct file_lock *conflicting_lock;
unsigned int strhashval;
int status; int status;
if (nfs4_in_grace()) if (nfs4_in_grace())
...@@ -2858,12 +2865,8 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock ...@@ -2858,12 +2865,8 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
goto out; goto out;
} }
strhashval = lock_ownerstr_hashval(inode, lockt->lt_stateowner = find_lockstateowner_str(inode,
lockt->lt_clientid.cl_id, lockt->lt_owner); &lockt->lt_clientid, &lockt->lt_owner);
find_lockstateowner_str(strhashval, &lockt->lt_owner,
&lockt->lt_clientid,
&lockt->lt_stateowner);
if (lockt->lt_stateowner) if (lockt->lt_stateowner)
file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner; file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner;
file_lock.fl_pid = current->tgid; file_lock.fl_pid = current->tgid;
......
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