Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp102209lqb; Thu, 23 May 2024 12:01:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/XlEqtmqr9rJ91btZvAmVUUjgVHgmb9DtCrANmUjCgYlGGlWWxf/CMn52W5psufA3c9LeIoVtFBhcBBQYotoAxtDOZePfe7SrEi32lA== X-Google-Smtp-Source: AGHT+IHbf+B9nMTXcApcZX+f3AZDJ6Yx1udnRV7PPI00k/yC9Bin45QMj/RCP0Vk/XU6K1v+QAt6 X-Received: by 2002:a05:6a21:3e05:b0:1af:5d8e:c6c with SMTP id adf61e73a8af0-1b212d5df8emr365711637.18.1716490899650; Thu, 23 May 2024 12:01:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716490899; cv=pass; d=google.com; s=arc-20160816; b=YceN2LwiL1guWUKxeJ/uUrmmBL0YTMmi/QYuzAwIiVPyTIwWI2B/d80LHPRQLQ0RZ3 /OOzDi5zvMP6Pqu6Ct5OP3WE/YS7sjXlLTG2ByFLpyO2EBWVWHP40um7AbhnKpIR4+Zc 41LCtkOdnkTJtHP9V8eTJNZxtVdXgKX11ezOiQpzG880Omm6cbsPe5xzdu4mMWoaX2NF /TFecsma39BPSUquk8rVKdOGBxIVQqhSCT5HvM6zyh4MF/J9u7+CUNS9PQSYKggCyVbF Xi7Tz9613p4wut5AWVTofCPEdpWgJ+LeXmckq2YaarmbE/Klm8ZoUY3vAsOQObd1VLWg 6NKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=pVcwprGsi46JOmwphUQnW6rYgzdEMAR+mAz8mON6hb4=; fh=3OHvFreu53haXMkTsxmolkoaPUdGf/bgDQhRZso17kM=; b=U5aZ/uH7Pav7k5yjAmPj/WxQmDRVs7BKJ850tY1paw/7rEEAmhM6wRQCuNf9fkNbjy tlT8KiX06X6MozFmjpXAshLPCzoEOpdEBeTSxjcV35QQYlvrJwMUf4nvxqMWNxJiQIhg 4+2tFRLQkIAAAyDJy81csj6NbZ6CBrmfv3OuCAebAtQZfs3+qQDWytdVgBUAZbLb6X0H xmMvERXzhhDN2VzZS+9EIuRlbUNT4VNCVBUpgD68a2JAn0tgW2/sRHplFVOp+y9BaIHm g+PvTi2GDx0KvJmP20MKAHukMbxYgvCIX84vL2yELLu/L5Bqdha4b8etPaVVgR2hIxj6 GlYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HwZZe1Oh; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-634103011a0si2487711a12.371.2024.05.23.12.01.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 12:01:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HwZZe1Oh; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-nfs+bounces-3356-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3356-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2AC5628356E for ; Thu, 23 May 2024 19:01:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 003586E2BE; Thu, 23 May 2024 19:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HwZZe1Oh" X-Original-To: linux-nfs@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9F9C42067 for ; Thu, 23 May 2024 19:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716490890; cv=none; b=im8AUBsqn1IFCadOs6edSdEUaSY/9DkpUQroot8F5rRvQrcg+G3K5G+/DCL++FOtBkZAVXEAzuknDN5hpkg9VCbE+aq4h520jwYWzl0LOH+KMhUs49H0jjDhe9U8lRgK3v0l+LO8OxeVp6b9lC5LiaX1qcL3VbJRXeHY//H2w5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716490890; c=relaxed/simple; bh=eZki9i4ijwJoM9CpoeWMVZW1LuYNR5ENvbsdJiQ16WI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=cazEba9CRlwheSH/4RzCsJgT/XRaW6CwV2nQgSxRdTvnuzsgncqBk13cP9DGtMJiQ5VKmsnNXy31u1ZxTYVXNrO5icBrv3aEwbQj5NAehdUDNdob2vZZxtTQlvenSTMT5lUkblHS2ELJ8zTsU90HBQUWCeZ6u6MKzKdiW+zxBzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HwZZe1Oh; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716490887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=pVcwprGsi46JOmwphUQnW6rYgzdEMAR+mAz8mON6hb4=; b=HwZZe1OhJ9uoTMB06jLUsob1ypvGzzw6loFpG4IW7dKWptAD6Yjn+htOGjbI+sNrf5EK4C aWMhvMk9bq12C5JczpsMIsgSTjBokw/T2CJKaDVklH2v/4+lxoqoAXAet1IlX9VNkq9JSH hZ7NNzLRBNJyuHkDbnK/QmPOnCjmqDs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-49-R1D4ZiIFOLOAsKV1Pj7UMg-1; Thu, 23 May 2024 15:01:24 -0400 X-MC-Unique: R1D4ZiIFOLOAsKV1Pj7UMg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8E5429AA2C1; Thu, 23 May 2024 19:01:23 +0000 (UTC) Received: from aion.redhat.com (unknown [10.22.33.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 991D5C15BED; Thu, 23 May 2024 19:01:23 +0000 (UTC) Received: from aion.redhat.com (localhost [IPv6:::1]) by aion.redhat.com (Postfix) with ESMTP id 055CD14C596; Thu, 23 May 2024 15:01:23 -0400 (EDT) From: Scott Mayhew To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: neilb@suse.de, linux-nfs@vger.kernel.org Subject: [PATCH v2] nfs: don't invalidate dentries on transient errors Date: Thu, 23 May 2024 15:01:22 -0400 Message-ID: <20240523190122.548964-1-smayhew@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 This is a slight variation on a patch previously proposed by Neil Brown that never got merged. Prior to commit 5ceb9d7fdaaf ("NFS: Refactor nfs_lookup_revalidate()"), any error from nfs_lookup_verify_inode() other than -ESTALE would result in nfs_lookup_revalidate() returning that error (-ESTALE is mapped to zero). Since that commit, all errors result in nfs_lookup_revalidate() returning zero, resulting in dentries being invalidated where they previously were not (particularly in the case of -ERESTARTSYS). Fix it by passing the actual error code to nfs_lookup_revalidate_done(), and leaving the decision on whether to map the error code to zero or one to nfs_lookup_revalidate_done(). A simple reproducer is to run the following python code in a subdirectory of an NFS mount (not in the root of the NFS mount): ---8<--- import os import multiprocessing import time if __name__=="__main__": multiprocessing.set_start_method("spawn") count = 0 while True: try: os.getcwd() pool = multiprocessing.Pool(10) pool.close() pool.terminate() count += 1 except Exception as e: print(f"Failed after {count} iterations") print(e) break ---8<--- Prior to commit 5ceb9d7fdaaf, the above code would run indefinitely. After commit 5ceb9d7fdaaf, it fails almost immediately with -ENOENT. Signed-off-by: Scott Mayhew --- v2: Don't skip the special handling of root dentries on error <= 0 in nfs_lookup_revalidate_done(). fs/nfs/dir.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index ac505671efbd..feed8d89bee1 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c @@ -1625,7 +1625,16 @@ nfs_lookup_revalidate_done(struct inode *dir, struct dentry *dentry, switch (error) { case 1: break; - case 0: + case -ETIMEDOUT: + if (inode && (IS_ROOT(dentry) || + NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL)) + error = 1; + break; + case -ESTALE: + case -ENOENT: + error = 0; + fallthrough; + default: /* * We can't d_drop the root of a disconnected tree: * its d_hash is on the s_anon list and d_drop() would hide @@ -1680,18 +1689,8 @@ static int nfs_lookup_revalidate_dentry(struct inode *dir, dir_verifier = nfs_save_change_attribute(dir); ret = NFS_PROTO(dir)->lookup(dir, dentry, fhandle, fattr); - if (ret < 0) { - switch (ret) { - case -ESTALE: - case -ENOENT: - ret = 0; - break; - case -ETIMEDOUT: - if (NFS_SERVER(inode)->flags & NFS_MOUNT_SOFTREVAL) - ret = 1; - } + if (ret < 0) goto out; - } /* Request help from readdirplus */ nfs_lookup_advise_force_readdirplus(dir, flags); @@ -1735,7 +1734,7 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, unsigned int flags) { struct inode *inode; - int error; + int error = 0; nfs_inc_stats(dir, NFSIOS_DENTRYREVALIDATE); inode = d_inode(dentry); @@ -1780,7 +1779,7 @@ nfs_do_lookup_revalidate(struct inode *dir, struct dentry *dentry, out_bad: if (flags & LOOKUP_RCU) return -ECHILD; - return nfs_lookup_revalidate_done(dir, dentry, inode, 0); + return nfs_lookup_revalidate_done(dir, dentry, inode, error); } static int -- 2.44.0