Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp558092pxb; Fri, 16 Apr 2021 12:08:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzuOAqvH8qL5vToVboV9ydGoCf91kiLTxJDDsdWz6b87FhDNk8/sKUEEuGueJK8gkIzWFN X-Received: by 2002:a17:906:1dd3:: with SMTP id v19mr9789186ejh.4.1618600096665; Fri, 16 Apr 2021 12:08:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618600096; cv=none; d=google.com; s=arc-20160816; b=c7pMs03O7gfMGkAOfM706bqgcOmP3N7edj+4NR0+2/xR4nvgEHTfixOd2I7gRw7hMA SJr4Qwj7po8kau+0rrmeO06Mf2xcJOHndc+bpm23HLc+2ZseYHWY7CQITrZTjxRAf23G OZlxpfBFTe1jgHH/nUVbMbtQVkqWkwlVWQ5NbbKlNUEXtvRTmwWCaOELZ2UiwWvYP2cJ SjYCTZIPO0ovUj+fRHJlKISugsOz2spjrJlYgoQEjuF4ySPwhJwJ4vi5qUXnCLn+6sJx B4zNvaaa2+eSm63/fDmDLaltPF8Hy+Vj5fdid4kZdI+IA+pOv7GA+WNEevpSksbnSI3Z C08g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-filter; bh=hV+1jp1eO/0OIhKCDjXJw3Q5mJyBAFaZGPmSp3iWy1E=; b=WXgaGFElT+0XsB+/v+FET2Ar5YbjIFjLzH1/dH8GiXFFUCtlgFp6krQvfvFGyQDG+J Q4tPXmgcoBhQBfGbVZs2yfETNnzDROjNlwrEsGVoJAYM5sMPe9uiMBufx1fr9ub60dZN kbLM7OH5Wv8aomPoS1a34XyKIEPbHvTnobFrEFlhqJsqUBXrqmus20z/JAl+ba+fx6s5 h05o2H5x5Wf8AlBn2TEWv01NK7LmdFhbVUoGxpCCcS46olyu3/aabV+qkKRNZ0/8ZIKn GkeeMy9hev4jN/TL2KGs7sNKqwr2+1bJJY6rsDfQQVsZ2Fk0pe1z6XrpF+1fkh+g5D25 IsGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si5308310ejg.216.2021.04.16.12.07.44; Fri, 16 Apr 2021 12:08:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235514AbhDPSAs (ORCPT + 99 others); Fri, 16 Apr 2021 14:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236045AbhDPSAr (ORCPT ); Fri, 16 Apr 2021 14:00:47 -0400 Received: from fieldses.org (fieldses.org [IPv6:2600:3c00:e000:2f7::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96950C061756 for ; Fri, 16 Apr 2021 11:00:21 -0700 (PDT) Received: by fieldses.org (Postfix, from userid 2815) id 0559B6D25; Fri, 16 Apr 2021 14:00:19 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.11.0 fieldses.org 0559B6D25 From: "J. Bruce Fields" To: Chuck Lever Cc: linux-nfs@vger.kernel.org, "J. Bruce Fields" Subject: [PATCH 3/5] nfsd: track filehandle aliasing in nfs4_files Date: Fri, 16 Apr 2021 14:00:16 -0400 Message-Id: <1618596018-9899-3-git-send-email-bfields@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1618596018-9899-1-git-send-email-bfields@redhat.com> References: <1618596018-9899-1-git-send-email-bfields@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: "J. Bruce Fields" It's unusual but possible for multiple filehandles to point to the same file. In that case, we may end up with multiple nfs4_files referencing the same inode. For delegation purposes it will turn out to be useful to flag those cases. Signed-off-by: J. Bruce Fields --- fs/nfsd/nfs4state.c | 37 ++++++++++++++++++++++++++++--------- fs/nfsd/state.h | 2 ++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b0c74dbde07b..c1ba60db671a 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4075,6 +4075,8 @@ static void nfsd4_init_file(struct svc_fh *fh, unsigned int hashval, fp->fi_share_deny = 0; memset(fp->fi_fds, 0, sizeof(fp->fi_fds)); memset(fp->fi_access, 0, sizeof(fp->fi_access)); + fp->fi_aliased = false; + fp->fi_inode = d_inode(fh->fh_dentry); #ifdef CONFIG_NFSD_PNFS INIT_LIST_HEAD(&fp->fi_lo_states); atomic_set(&fp->fi_lo_recalls, 0); @@ -4427,6 +4429,31 @@ find_file_locked(struct svc_fh *fh, unsigned int hashval) return NULL; } +static struct nfs4_file *insert_file(struct nfs4_file *new, struct svc_fh *fh, + unsigned int hashval) +{ + struct nfs4_file *fp; + struct nfs4_file *ret = NULL; + bool alias_found = false; + + spin_lock(&state_lock); + hlist_for_each_entry_rcu(fp, &file_hashtbl[hashval], fi_hash, + lockdep_is_held(&state_lock)) { + if (fh_match(&fp->fi_fhandle, &fh->fh_handle)) { + if (refcount_inc_not_zero(&fp->fi_ref)) + ret = fp; + } else if (d_inode(fh->fh_dentry) == fp->fi_inode) + fp->fi_aliased = alias_found = true; + } + if (likely(ret == NULL)) { + nfsd4_init_file(fh, hashval, new); + new->fi_aliased = alias_found; + ret = new; + } + spin_unlock(&state_lock); + return ret; +} + static struct nfs4_file * find_file(struct svc_fh *fh) { struct nfs4_file *fp; @@ -4450,15 +4477,7 @@ find_or_add_file(struct nfs4_file *new, struct svc_fh *fh) if (fp) return fp; - spin_lock(&state_lock); - fp = find_file_locked(fh, hashval); - if (likely(fp == NULL)) { - nfsd4_init_file(fh, hashval, new); - fp = new; - } - spin_unlock(&state_lock); - - return fp; + return insert_file(new, fh, hashval); } /* diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index af1d9f2e373e..7b10b3eaaa5c 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -512,6 +512,8 @@ struct nfs4_clnt_odstate { */ struct nfs4_file { refcount_t fi_ref; + struct inode * fi_inode; + bool fi_aliased; spinlock_t fi_lock; struct hlist_node fi_hash; /* hash on fi_fhandle */ struct list_head fi_stateids; -- 2.30.2