Linux NFS development
 help / color / mirror / Atom feed
From: Jimmy Zuber <jamz@amazon.com>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: <linux-nfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH] NFS: Fix stale negative cache on failed nfs_mkdir()
Date: Wed, 19 Aug 2026 01:51:11 +0000	[thread overview]
Message-ID: <20260819015111.2743908-1-jamz@amazon.com> (raw)

Since commit 8376583b84a1 ("nfs: change mkdir inode_operation to return
alternate dentry if needed"), nfs_mkdir() no longer drops the dentry on
RPC failure.  A negative cache value can then result in spurious ENOENT
results for further operations within that directory, such as open or
stat.

We observed this breaking some applications where an EEXIST on mkdir
caused the application to assume the directory to exist, only to fail
operations within that directory due to the retained negative cache
entry.  The other create paths, nfs_create() and nfs_mknod(), still drop
the dentry on failure.  This patch restores the previous behavior.

Fixes: 8376583b84a1 ("nfs: change mkdir inode_operation to return alternate dentry if needed")
Cc: stable@vger.kernel.org # v6.15+
Signed-off-by: Jimmy Zuber <jamz@amazon.com>
---

We reproduced this against a local knfsd export over NFSv4.1.  The export is
mounted several times with "nosharecache" so that each mount acts as an
independent client with its own dcache:

  # /etc/exports
  /srv/nfs 127.0.0.1(rw,sync,no_subtree_check,no_root_squash,fsid=0)

  for i in $(seq 0 5); do
      mount -t nfs4 -o vers=4.1,nosharecache,acdirmin=30,acdirmax=60 \
          127.0.0.1:/ /mnt/nfs$i
  done

For each of 40 new cache/<id> directories, every mount stats the directory to
seed a negative entry, then all mounts race to mkdir it.  The winner writes a
file and renames it, and the losers that got EEXIST then read that file back.
On a vanilla v6.17 kernel, the 200 loser reads were:

  unpatched:   read OK   0 / ENOENT 200
  patched:     read OK 200 / ENOENT   0

 fs/nfs/dir.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index d812179..f0b493a 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -2437,6 +2437,8 @@ struct dentry *nfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	trace_nfs_mkdir_enter(dir, dentry);
 	ret = NFS_PROTO(dir)->mkdir(dir, dentry, &attr);
 	trace_nfs_mkdir_exit(dir, dentry, PTR_ERR_OR_ZERO(ret));
+	if (IS_ERR(ret))
+		d_drop(dentry);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(nfs_mkdir);
-- 
2.51.0


                 reply	other threads:[~2026-08-19  1:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260819015111.2743908-1-jamz@amazon.com \
    --to=jamz@amazon.com \
    --cc=anna@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox