Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3350554pxf; Mon, 15 Mar 2021 07:44:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzM3jmTtcmou3B5YYa66f08bK6Ivr8vuEQARPRiy6GrvMULDtSebbmtnZ5RkAkozs+UbUUX X-Received: by 2002:a05:6402:1157:: with SMTP id g23mr30310229edw.303.1615819477566; Mon, 15 Mar 2021 07:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615819477; cv=none; d=google.com; s=arc-20160816; b=IRexqBWWDV8n4TGkDniCurOJYC0ELn/ooN5q5eBlk896Mih3MdsvT0rOm7V74TStvD 3yiFVoQagtTsz8OlW31dcP9Xz0ar5X/qECzEmaZ1VdD0FLx4Il+FqDOlMPtEU1m77gB2 cF2Ff3+t+4nMPQbGtvCVoHFfXQ3UnzXQPJfztNpspU3RO9t7dupzVECIWbQOCkdV6J+H 47kVK0OPt9dvj/Z6Kt7m36O5syuY2t/abnXBG4GyYrpVVp5PeqT1Cq1Jou943qmRvaqL i8Jwaa3spJ5/mNoQ/RnTggUiRjNtA4GW8fosk5IcYhgqx3nTaTefa52cOTmKurWP17up oeEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+esE+YrDkq2Zj4FRrZ0eicBvZjF7CjNPdoIrvuNUqhA=; b=pqksaSSsfmjb+Cxshx4WUexCfpT6il0kwD66cq10FMEVVTt7Id4Ckup0IMN+H89QFS OQy56ok5NKo2T5iqENXsTeVVCreh/sGGP6G7W+3HdKoPF+YfpWCkk+SjXGINsXUiv3C8 BWwcVFZdw3kiDV7Fm1hW8qTgwhCfoJIUde5kW38PY6zWu1DHTKvu9wr4+HkuCDKWPOy4 yvi1882R+qjBL272jCZZjAbjQwUiAqi7FRNQn4fo3zibIemjCEjpRcASZmJMnyMRioCt k8WlM5Qt84jlvaLNIdpIpN6Vt0Alie/cEcq2vLVdupruwRfuQVKqy9JnyNGJQX6ZgkPR RdQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F9X3FLhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v25si11615340ejw.423.2021.03.15.07.44.13; Mon, 15 Mar 2021 07:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F9X3FLhk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238377AbhCOOmf (ORCPT + 99 others); Mon, 15 Mar 2021 10:42:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:49544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234262AbhCOODI (ORCPT ); Mon, 15 Mar 2021 10:03:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 048CA64DAD; Mon, 15 Mar 2021 14:03:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816988; bh=cZ83mKjCJXO+pr922AHWsqr7sJPYruQK8+WdF2VCpl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F9X3FLhk34ppN3FQC7nLGht0YZOS0dpKf1Lj2wslumEmmLFomrdpljqbSMI/LxjVn Y4U4X7UgWXqvamkCDlzzDS2Ya9gEXYIcV+5LDWjbUQv2Kdd7FFfMXJgRvzLIy2Tp31 1/+9aDpvZZ1dnBqJPOn85dEAuOQWvY8j9119uNEY= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Jansen , Trond Myklebust , Anna Schumaker , Sasha Levin Subject: [PATCH 5.11 246/306] NFS: Dont revalidate the directory permissions on a lookup failure Date: Mon, 15 Mar 2021 14:55:09 +0100 Message-Id: <20210315135515.959029673@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Trond Myklebust [ Upstream commit 82e7ca1334ab16e2e04fafded1cab9dfcdc11b40 ] There should be no reason to expect the directory permissions to change just because the directory contents changed or a negative lookup timed out. So let's avoid doing a full call to nfs_mark_for_revalidate() in that case. Furthermore, if this is a negative dentry, and we haven't actually done a new lookup, then we have no reason yet to believe the directory has changed at all. So let's remove the gratuitous directory inode invalidation altogether when called from nfs_lookup_revalidate_negative(). Reported-by: Geert Jansen Fixes: 5ceb9d7fdaaf ("NFS: Refactor nfs_lookup_revalidate()") Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- fs/nfs/dir.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ef827ae193d2..7bcc6fcf1096 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1401,6 +1401,15 @@ int nfs_lookup_verify_inode(struct inode *inode, unsigned int flags) goto out; } +static void nfs_mark_dir_for_revalidate(struct inode *inode) +{ + struct nfs_inode *nfsi = NFS_I(inode); + + spin_lock(&inode->i_lock); + nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE; + spin_unlock(&inode->i_lock); +} + /* * We judge how long we want to trust negative * dentries by looking at the parent inode mtime. @@ -1435,7 +1444,6 @@ nfs_lookup_revalidate_done(struct inode *dir, struct dentry *dentry, __func__, dentry); return 1; case 0: - nfs_mark_for_revalidate(dir); if (inode && S_ISDIR(inode->i_mode)) { /* Purge readdir caches. */ nfs_zap_caches(inode); @@ -1525,6 +1533,13 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry, nfs_free_fattr(fattr); nfs_free_fhandle(fhandle); nfs4_label_free(label); + + /* + * If the lookup failed despite the dentry change attribute being + * a match, then we should revalidate the directory cache. + */ + if (!ret && nfs_verify_change_attribute(dir, dentry->d_time)) + nfs_mark_dir_for_revalidate(dir); return nfs_lookup_revalidate_done(dir, dentry, inode, ret); } @@ -1567,7 +1582,7 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, error = nfs_lookup_verify_inode(inode, flags); if (error) { if (error == -ESTALE) - nfs_zap_caches(dir); + nfs_mark_dir_for_revalidate(dir); goto out_bad; } nfs_advise_use_readdirplus(dir); @@ -2064,7 +2079,6 @@ nfs_add_or_obtain(struct dentry *dentry, struct nfs_fh *fhandle, dput(parent); return d; out_error: - nfs_mark_for_revalidate(dir); d = ERR_PTR(error); goto out; } -- 2.30.1