Skip to content

Commit

Permalink
nfsd: Use the filehandle to look up the struct nfs4_file instead of i…
Browse files Browse the repository at this point in the history
…node

This makes more sense anyway since an inode pointer value can change
even when the filehandle doesn't.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Trond Myklebust authored and J. Bruce Fields committed Jul 23, 2014
1 parent e2cf80d commit ca94321
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,22 @@ static unsigned int ownerstr_hashval(u32 clientid, struct xdr_netobj *ownername)
#define FILE_HASH_BITS 8
#define FILE_HASH_SIZE (1 << FILE_HASH_BITS)

static unsigned int file_hashval(struct inode *ino)
static unsigned int nfsd_fh_hashval(struct knfsd_fh *fh)
{
/* XXX: why are we hashing on inode pointer, anyway? */
return hash_ptr(ino, FILE_HASH_BITS);
return jhash2(fh->fh_base.fh_pad, XDR_QUADLEN(fh->fh_size), 0);
}

static unsigned int file_hashval(struct knfsd_fh *fh)
{
return nfsd_fh_hashval(fh) & (FILE_HASH_SIZE - 1);
}

static bool nfsd_fh_match(struct knfsd_fh *fh1, struct knfsd_fh *fh2)
{
return fh1->fh_size == fh2->fh_size &&
!memcmp(fh1->fh_base.fh_pad,
fh2->fh_base.fh_pad,
fh1->fh_size);
}

static struct hlist_head file_hashtbl[FILE_HASH_SIZE];
Expand Down Expand Up @@ -2836,7 +2848,7 @@ static struct nfs4_file *nfsd4_alloc_file(void)
static void nfsd4_init_file(struct nfs4_file *fp, struct inode *ino,
struct knfsd_fh *fh)
{
unsigned int hashval = file_hashval(ino);
unsigned int hashval = file_hashval(fh);

lockdep_assert_held(&state_lock);

Expand Down Expand Up @@ -3023,15 +3035,15 @@ find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open,

/* search file_hashtbl[] for file */
static struct nfs4_file *
find_file_locked(struct inode *ino)
find_file_locked(struct knfsd_fh *fh)
{
unsigned int hashval = file_hashval(ino);
unsigned int hashval = file_hashval(fh);
struct nfs4_file *fp;

lockdep_assert_held(&state_lock);

hlist_for_each_entry(fp, &file_hashtbl[hashval], fi_hash) {
if (fp->fi_inode == ino) {
if (nfsd_fh_match(&fp->fi_fhandle, fh)) {
get_nfs4_file(fp);
return fp;
}
Expand All @@ -3040,12 +3052,12 @@ find_file_locked(struct inode *ino)
}

static struct nfs4_file *
find_file(struct inode *ino)
find_file(struct knfsd_fh *fh)
{
struct nfs4_file *fp;

spin_lock(&state_lock);
fp = find_file_locked(ino);
fp = find_file_locked(fh);
spin_unlock(&state_lock);
return fp;
}
Expand All @@ -3056,7 +3068,7 @@ find_or_add_file(struct inode *ino, struct nfs4_file *new, struct knfsd_fh *fh)
struct nfs4_file *fp;

spin_lock(&state_lock);
fp = find_file_locked(ino);
fp = find_file_locked(fh);
if (fp == NULL) {
nfsd4_init_file(new, ino, fh);
fp = new;
Expand All @@ -3073,11 +3085,10 @@ find_or_add_file(struct inode *ino, struct nfs4_file *new, struct knfsd_fh *fh)
static __be32
nfs4_share_conflict(struct svc_fh *current_fh, unsigned int deny_type)
{
struct inode *ino = current_fh->fh_dentry->d_inode;
struct nfs4_file *fp;
__be32 ret = nfs_ok;

fp = find_file(ino);
fp = find_file(&current_fh->fh_handle);
if (!fp)
return ret;
/* Check for conflicting share reservations */
Expand Down

0 comments on commit ca94321

Please sign in to comment.