From: NeilBrown <neilb@ownmail.net>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 3/8] vfs: don't call ->atomic_open with hashed negative in non-O_CREAT case.
Date: Wed, 2 Dec 2026 17:05:03 +1100 [thread overview]
Message-ID: <20261202060607.2627366-4-neilb@ownmail.net> (raw)
In-Reply-To: <20261202060607.2627366-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
If lookup_fast_for_open() finds a hashed-negative dentry and O_CREAT
wasn't requested, it will be returned to open_last_lookups() which will
bypass lookup_open() and no call to nfs_atomic_open() will be attempted.
However if it doesn't find a hashed dentry, but lookup_open() does find
a hashed-negative, then that dentry *will* be passed to ->atomic_open.
This is inconsistent and somewhat problematic.
When O_CREAT was requested (even if it isn't passed to ->atomic_create
due to permission issues), ->atomic_open will have exclusive access
to the dentry.
When the dentry is d_in_lookup(), ->atomic_open again has exclusive
access.
The dentry cannot be positive (that case is handled in lookup_open())
but if it is negative but O_CREAT wasn't requested then ->atomic_open
will not have exclusive access. NFS currently has code to handle this
which should not be necessary.
To provide a more consistent context for ->atomic_open handle the
hashed-negative-without-O_CREAT case in lookup_open().
Signed-off-by: NeilBrown <neil@brown.name>
---
Documentation/filesystems/vfs.rst | 13 +++++--------
fs/namei.c | 4 ++++
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
index c1f3ea7aad67..d1d32540e85f 100644
--- a/Documentation/filesystems/vfs.rst
+++ b/Documentation/filesystems/vfs.rst
@@ -648,14 +648,11 @@ otherwise noted.
needs lookup. Cached positive dentries are still handled by
f_op->open().
- If the dentry provided is negative (not in-lookup) and O_CREAT
- isn't set, then there is no guarantee of exclusive access to the
- dentry - another thread might call ->atomic_open() on the same
- dentry at the same time. If needed, a filesystem can ensure this
- doesn't happen by returning 0 from ->d_revalidate when that is
- called with LOOKUP_OPEN on a negative dentry. This will ensure
- that ->atomic_open() only receives an in-lookup dentry, which
- always ensures exclusive access.
+ It is guaranteed that this method has exclusive access to the
+ dentry. If it is not in-lookup, then O_CREAT was requested
+ and the parent is locked exclusively. This will be the case
+ even if O_CREAT isn't still set in open_flag (it may be cleared
+ if permissions checks show that creation is not permitted).
``tmpfile``
called in the end of O_TMPFILE open(). Optional, equivalent to
diff --git a/fs/namei.c b/fs/namei.c
index bff4dfaf6721..441560ba755a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4608,6 +4608,10 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
if (dentry->d_inode) {
/* Cached positive dentry: will open in do_open(). */
goto out;
+ } else if (!d_in_lookup(dentry) && !(open_flag & O_CREAT)) {
+ /* Cached negative dentry without O_CREAT */
+ error = -ENOENT;
+ goto out_dput;
}
if (open_flag & O_CREAT)
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2026-12-02 6:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 6:05 [PATCH 0/8] vfs: improvements for atomic_open and vfs_lookup_open NeilBrown
2026-12-02 6:05 ` [PATCH 1/8] vfs: revise and expand documentation for atomic_open NeilBrown
2026-12-02 6:05 ` [PATCH 2/8] vfs: only set op.mode when O_CREAT in vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` NeilBrown [this message]
2026-12-02 6:05 ` [PATCH 4/8] vfs: add some allowed open flags to vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 5/8] vfs: O_NONBLOCK|O_CREAT open shouldn't wait for directory delegation NeilBrown
2026-12-02 6:05 ` [PATCH 6/8] vfs: don't return -ENODEV from vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 7/8] vfs: change vfs_lookup_open() to use do_open(), not vfs_open() NeilBrown
2026-12-02 6:05 ` [PATCH 8/8] vfs: add MAY_SERVE_FILE and FMODE_SERVE_FILE NeilBrown
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=20261202060607.2627366-4-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
/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
all inboxes | Powered by JetHome®