From patchwork Wed Jul 23 20:17:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4612941 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D9C9AC0514 for ; Wed, 23 Jul 2014 20:17:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 089C220154 for ; Wed, 23 Jul 2014 20:17:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16A402017D for ; Wed, 23 Jul 2014 20:17:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933402AbaGWURw (ORCPT ); Wed, 23 Jul 2014 16:17:52 -0400 Received: from mail-qg0-f43.google.com ([209.85.192.43]:61334 "EHLO mail-qg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933336AbaGWURv (ORCPT ); Wed, 23 Jul 2014 16:17:51 -0400 Received: by mail-qg0-f43.google.com with SMTP id a108so2100065qge.16 for ; Wed, 23 Jul 2014 13:17:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4a7/iB/ca8FzzHTulZ3lcdddBLQO10Bdm5pnUCx+/Ec=; b=VmMs6aWxeID6jdkSEHmwAkArYJCctrr675DJGZDUS+4/2o6DmSqcRAdTdFrlplpVDV W52cTyhCOY8UtnDsD4dPTg6WkF9BsomMVnIDiC2uvZGWee1HCnJQlsWoQgx0XIqqu3zi XAXmvJYeXqTjEZPHsF1IO4sTRdVZKhdkatGfjIVOUlb8/Syckgn9GuVTP+piFkax9lXn ZJMrZ17fu9kRhbBbLsaNSh6wKcXWALaj9ZNBjSpFKL0fgIEojbHy2FRvni4quVko1zYC xwB7zUhbMQYIdIWsWhm6l9iVfnfSV8BtkoqUR2DsqpCSEZ06C/j8f/DDDDTRnljTwoil ck+g== X-Gm-Message-State: ALoCoQnPYVxHd78lmsUD2dwKCVCDA0O7thIP2cASTsPELDx/T5XBFKJJ4WLYvT643PXMSgJWmY2i X-Received: by 10.224.128.9 with SMTP id i9mr6283710qas.50.1406146670522; Wed, 23 Jul 2014 13:17:50 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id l69sm4601235qgd.17.2014.07.23.13.17.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jul 2014 13:17:49 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, trond.myklebust@primarydata.com, hch@infradead.org Subject: [PATCH v2 2/4] nfsd: Use the filehandle to look up the struct nfs4_file instead of inode Date: Wed, 23 Jul 2014 16:17:39 -0400 Message-Id: <1406146661-9794-3-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1406146661-9794-1-git-send-email-jlayton@primarydata.com> References: <1406146661-9794-1-git-send-email-jlayton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Trond Myklebust This makes more sense anyway since an inode pointer value can change even when the filehandle doesn't. Signed-off-by: Trond Myklebust Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 859891f30958..ab96718df3cc 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -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]; @@ -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); @@ -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; } @@ -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; } @@ -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; @@ -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(¤t_fh->fh_handle); if (!fp) return ret; /* Check for conflicting share reservations */