From: NeilBrown <neil@brown.name>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 05/16] VFS: use d_alloc_parallel() in lookup_one_qstr_excl().
Date: Fri, 22 Aug 2025 10:00:23 +1000 [thread overview]
Message-ID: <20250822000818.1086550-6-neil@brown.name> (raw)
In-Reply-To: <20250822000818.1086550-1-neil@brown.name>
lookup_one_qstr_excl() is used for lookups prior to directory
modifications, whether create, remove or rename.
To prepare for allowing modification to happen in parallel, change
lookup_one_qstr_excl() to use d_alloc_parallel().
As a result, ->lookup is now only ever called with a d_in_lookup()
dentry. Consequently we can remove the d_in_lookup() check from
d_add_ci() which is only used in ->lookup.
If LOOKUP_EXCL or LOOKUP_RENAME_TARGET is passed, the caller must ensure
d_lookup_done() is called at an appropriate time, and must not assume
that it can test for positive or negative dentries without confirming
that the dentry is no longer d_in_lookup() - unless it is filesystem
code acting on itself and *knows* that ->lookup() always completes the
lookup (currently true for all filesystems other than NFS).
Signed-off-by: NeilBrown <neil@brown.name>
---
Documentation/filesystems/porting.rst | 12 +++++++++++
fs/dcache.c | 16 ++++----------
fs/namei.c | 30 ++++++++++++++++++---------
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/Documentation/filesystems/porting.rst b/Documentation/filesystems/porting.rst
index 96107c15e928..1d3c1e9b6cf3 100644
--- a/Documentation/filesystems/porting.rst
+++ b/Documentation/filesystems/porting.rst
@@ -1291,3 +1291,15 @@ parameters for the file system to set this state.
d_alloc_parallel() signature has changed - it no longer receives a
waitqueue_head. It uses one from an internal table when needed.
+
+---
+
+** mandatory**
+
+kern_path_create() and user_path_create() can return a d_in_lookup()
+dentry as can lookup_one_qstr_excl() if passed "O_CREATE|O_EXCL" or
+"O_RENAME_TARGET". This can currently only happen if the target
+filesystem is NFS.
+
+inode_operations.lookup() is now only ever called with a d_in_lookup()
+dentry (i.e. DCACHE_PAR_LOOKUP will be set).
diff --git a/fs/dcache.c b/fs/dcache.c
index df9306c63581..034726ab058e 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2136,18 +2136,10 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
iput(inode);
return found;
}
- if (d_in_lookup(dentry)) {
- found = d_alloc_parallel(dentry->d_parent, name);
- if (IS_ERR(found) || !d_in_lookup(found)) {
- iput(inode);
- return found;
- }
- } else {
- found = d_alloc(dentry->d_parent, name);
- if (!found) {
- iput(inode);
- return ERR_PTR(-ENOMEM);
- }
+ found = d_alloc_parallel(dentry->d_parent, name);
+ if (IS_ERR(found) || !d_in_lookup(found)) {
+ iput(inode);
+ return found;
}
res = d_splice_alias(inode, found);
if (res) {
diff --git a/fs/namei.c b/fs/namei.c
index 7a2d72ee1af1..b785bf7a9344 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1666,13 +1666,14 @@ static struct dentry *lookup_dcache(const struct qstr *name,
}
/*
- * Parent directory has inode locked exclusive. This is one
- * and only case when ->lookup() gets called on non in-lookup
- * dentries - as the matter of fact, this only gets called
- * when directory is guaranteed to have no in-lookup children
- * at all.
- * Will return -ENOENT if name isn't found and LOOKUP_CREATE wasn't passed.
- * Will return -EEXIST if name is found and LOOKUP_EXCL was passed.
+ * Parent directory has inode locked.
+ * d_lookup_done() must be called before the dentry is dput()
+ * if LOOKUP_EXCL or LOOKUP_RENAME_TARGET is set.
+ * If the dentry is not d_in_lookup():
+ * Will return -ENOENT if name isn't found and LOOKUP_CREATE wasn't passed.
+ * Will return -EEXIST if name is found and LOOKUP_EXCL was passed.
+ * If it is d_in_lookup() then these conditions can only be checked by the
+ * file system when carrying out the intent (create or rename).
*/
struct dentry *lookup_one_qstr_excl(const struct qstr *name,
struct dentry *base, unsigned int flags)
@@ -1690,18 +1691,27 @@ struct dentry *lookup_one_qstr_excl(const struct qstr *name,
if (unlikely(IS_DEADDIR(dir)))
return ERR_PTR(-ENOENT);
- dentry = d_alloc(base, name);
- if (unlikely(!dentry))
- return ERR_PTR(-ENOMEM);
+ dentry = d_alloc_parallel(base, name);
+ if (unlikely(IS_ERR(dentry)))
+ return dentry;
+ if (unlikely(!d_in_lookup(dentry)))
+ /* Raced with another thread which did the lookup */
+ goto found;
old = dir->i_op->lookup(dir, dentry, flags);
if (unlikely(old)) {
+ d_lookup_done(dentry);
dput(dentry);
dentry = old;
}
found:
if (IS_ERR(dentry))
return dentry;
+ if (d_in_lookup(dentry))
+ /* We cannot check for errors - the caller will have to
+ * wait for any create-etc attempt to get relevant errors.
+ */
+ return dentry;
if (d_is_negative(dentry) && !(flags & LOOKUP_CREATE)) {
dput(dentry);
return ERR_PTR(-ENOENT);
--
2.50.0.107.gf914562f5916.dirty
next prev parent reply other threads:[~2025-08-22 0:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 0:00 [PATCH v2 00/16] VFS: prepare for changes to directory locking NeilBrown
2025-08-22 0:00 ` [PATCH v2 01/16] VFS: discard err2 in filename_create() NeilBrown
2025-08-22 0:00 ` [PATCH v2 02/16] VFS: unify old_mnt_idmap and new_mnt_idmap in renamedata NeilBrown
2025-08-22 0:00 ` [PATCH v2 03/16] Introduce wake_up_key() NeilBrown
2025-08-22 12:50 ` kernel test robot
2025-08-22 0:00 ` [PATCH v2 04/16] VFS: use global wait-queue table for d_alloc_parallel() NeilBrown
2025-08-22 0:00 ` NeilBrown [this message]
2025-08-22 0:00 ` [PATCH v2 06/16] VFS: introduce start_dirop() NeilBrown
2025-08-22 0:00 ` [PATCH v2 07/16] VFS: introduce end_dirop() and end_dirop_mkdir() NeilBrown
2025-08-22 9:30 ` Amir Goldstein
2025-08-22 14:08 ` kernel test robot
2025-08-22 0:00 ` [PATCH v2 08/16] VFS: implement simple_start_creating() with start_dirop() NeilBrown
2025-08-22 15:53 ` kernel test robot
2025-08-22 0:00 ` [PATCH v2 09/16] VFS: introduce simple_end_creating() and simple_failed_creating() NeilBrown
2025-08-22 0:00 ` [PATCH v2 10/16] Use simple_start_creating() in various places NeilBrown
2025-08-22 0:00 ` [PATCH v2 11/16] VFS/nfsd/cachefiles: add start_creating() and end_creating() NeilBrown
2025-08-22 0:00 ` [PATCH v2 12/16] nfsd: move name lookup out of nfsd4_list_rec_dir() NeilBrown
2025-08-22 0:00 ` [PATCH v2 13/16] VFS/nfsd/cachefiles: introduce start_removing() NeilBrown
2025-08-22 0:00 ` [PATCH v2 14/16] VFS: introduce start_creating_noperm() and start_removing_noperm() NeilBrown
2025-08-22 0:00 ` [PATCH v2 15/16] VFS: introduce start_removing_dentry() NeilBrown
2025-08-22 9:44 ` Amir Goldstein
2025-08-22 0:00 ` [PATCH v2 16/16] VFS: add start_creating_killable() and start_removing_killable() 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=20250822000818.1086550-6-neil@brown.name \
--to=neil@brown.name \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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®