From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Scott Mayhew <smayhew@redhat.com>,
Trond Myklebust <trond.myklebust@hammerspace.com>,
Sasha Levin <sashal@kernel.org>,
trondmy@kernel.org, anna@kernel.org, linux-nfs@vger.kernel.org
Subject: [PATCH AUTOSEL 6.9 04/21] nfs: don't invalidate dentries on transient errors
Date: Sun, 23 Jun 2024 09:43:37 -0400 [thread overview]
Message-ID: <20240623134405.809025-4-sashal@kernel.org> (raw)
In-Reply-To: <20240623134405.809025-1-sashal@kernel.org>
From: Scott Mayhew <smayhew@redhat.com>
[ Upstream commit 0c8c7c559740d2d8b66048162af6c4dba8f0c88c ]
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 <smayhew@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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 bdd6cb33a3708..375c08fdcf2f3 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.43.0
next prev parent reply other threads:[~2024-06-23 13:44 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-23 13:43 [PATCH AUTOSEL 6.9 01/21] NFSv4: Fix memory leak in nfs4_set_security_label Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 02/21] nfs: propagate readlink errors in nfs_symlink_filler Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 03/21] nfs: Avoid flushing many pages with NFS_FILE_SYNC Sasha Levin
2024-06-23 13:43 ` Sasha Levin [this message]
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 05/21] cachefiles: add consistency check for copen/cread Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 06/21] cachefiles: Set object to close if ondemand_id < 0 in copen Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 07/21] cachefiles: make on-demand read killable Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 08/21] fs/file: fix the check in find_next_fd() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 09/21] vfio: Create vfio_fs_type with inode per device Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 10/21] vfio/pci: Use unmap_mapping_range() Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 11/21] mei: demote client disconnect warning on suspend to debug Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 12/21] parport: amiga: Mark driver struct with __refdata to prevent section mismatch Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 13/21] iomap: Fix iomap_adjust_read_range for plen calculation Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 14/21] drm/exynos: dp: drop driver owner initialization Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 15/21] drm: panel-orientation-quirks: Add quirk for Aya Neo KUN Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 16/21] drm: renesas: shmobile: Call drm_atomic_helper_shutdown() at shutdown time Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 17/21] drm/mediatek: " Sasha Levin
2024-06-23 13:43 ` Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 18/21] nvme: avoid double free special payload Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 19/21] nvmet: always initialize cqe.result Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 20/21] vfio/pci: Insert full vma on mmap'd MMIO fault Sasha Levin
2024-06-23 13:43 ` [PATCH AUTOSEL 6.9 21/21] loop: Disable fallocate() zero and discard if not supported Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240623134405.809025-4-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=anna@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=smayhew@redhat.com \
--cc=stable@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.