From: NeilBrown <neilb@suse.de>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 04/11] VFS: use d_alloc_parallel() in lookup_one_qstr_excl()
Date: Fri, 20 Dec 2024 13:54:22 +1100 [thread overview]
Message-ID: <20241220030830.272429-5-neilb@suse.de> (raw)
In-Reply-To: <20241220030830.272429-1-neilb@suse.de>
lookup_one_qstr_excl() is used for lookups prior to directory
modifications, whether create, unlink, rename, or whatever.
To prepare for allowing modification to happen in parallel, change
lookup_one_qstr_excl() to use d_alloc_parallel().
If any for the "intent" LOOKUP flags are passed, the caller must ensure
d_lookup_done() is called at an appropriate time. If none are passed
then we can be sure ->lookup() will do a real lookup and d_lookup_done()
is called internally.
Signed-off-by: NeilBrown <neilb@suse.de>
---
fs/namei.c | 21 ++++++++++++++-------
fs/smb/server/vfs.c | 1 +
include/linux/namei.h | 3 +++
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 174e6693304e..395bfbc8fc92 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1664,11 +1664,9 @@ 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.
+ * Parent directory has inode locked exclusive.
+ * If @flags contains any LOOKUP_INTENT_FLAGS then d_lookup_done()
+ * must be called after the intended operation is performed - or aborted.
*/
struct dentry *lookup_one_qstr_excl(const struct qstr *name,
struct dentry *base,
@@ -1685,15 +1683,22 @@ 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))
+ dentry = d_alloc_parallel(base, name);
+ if (unlikely(IS_ERR_OR_NULL(dentry)))
return ERR_PTR(-ENOMEM);
+ if (!d_in_lookup(dentry))
+ /* Raced with another thread which did the lookup */
+ return dentry;
old = dir->i_op->lookup(dir, dentry, flags);
if (unlikely(old)) {
+ d_lookup_done(dentry);
dput(dentry);
dentry = old;
}
+ if ((flags & LOOKUP_INTENT_FLAGS) == 0)
+ /* ->lookup must have given final answer */
+ d_lookup_done(dentry);
return dentry;
}
EXPORT_SYMBOL(lookup_one_qstr_excl);
@@ -4112,6 +4117,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
}
return dentry;
fail:
+ d_lookup_done(dentry);
dput(dentry);
dentry = ERR_PTR(error);
unlock:
@@ -5340,6 +5346,7 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd,
rd.flags = flags;
error = vfs_rename(&rd);
exit5:
+ d_lookup_done(new_dentry);
dput(new_dentry);
exit4:
dput(old_dentry);
diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
index dfb0eee5f5f3..83131f08bfb4 100644
--- a/fs/smb/server/vfs.c
+++ b/fs/smb/server/vfs.c
@@ -772,6 +772,7 @@ int ksmbd_vfs_rename(struct ksmbd_work *work, const struct path *old_path,
ksmbd_debug(VFS, "vfs_rename failed err %d\n", err);
out4:
+ d_lookup_done(new_dentry);
dput(new_dentry);
out3:
dput(old_parent);
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 8ec8fed3bce8..15118992f745 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -34,6 +34,9 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT};
#define LOOKUP_EXCL 0x0400 /* ... in exclusive creation */
#define LOOKUP_RENAME_TARGET 0x0800 /* ... in destination of rename() */
+#define LOOKUP_INTENT_FLAGS (LOOKUP_OPEN | LOOKUP_CREATE | LOOKUP_EXCL | \
+ LOOKUP_RENAME_TARGET)
+
/* internal use only */
#define LOOKUP_PARENT 0x0010
--
2.47.0
next prev parent reply other threads:[~2024-12-20 3:09 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 2:54 [PATCH 00/11 RFC] Allow concurrent changes in a directory NeilBrown
2024-12-20 2:54 ` [PATCH 01/11] VFS: introduce vfs_mkdir_return() NeilBrown
2024-12-23 5:04 ` Al Viro
2024-12-23 7:26 ` NeilBrown
2024-12-20 2:54 ` [PATCH 02/11] VFS: add _shared versions of the various directory modifying inode_operations NeilBrown
2024-12-23 5:08 ` Al Viro
2024-12-20 2:54 ` [PATCH 03/11] VFS: use global wait-queue table for d_alloc_parallel() NeilBrown
2024-12-20 2:54 ` NeilBrown [this message]
2024-12-20 2:54 ` [PATCH 05/11] VFS: change kern_path_locked() and user_path_locked_at() to never return negative dentry NeilBrown
2024-12-20 2:54 ` [PATCH 06/11] VFS: introduce done_lookup_and_lock() NeilBrown
2024-12-20 2:54 ` [PATCH 07/11] VFS: introduce lookup_and_lock() NeilBrown
2024-12-20 2:54 ` [PATCH 08/11] VFS: add inode_dir_lock/unlock NeilBrown
2024-12-21 1:21 ` Hillf Danton
2024-12-23 3:10 ` NeilBrown
2024-12-23 11:12 ` Hillf Danton
2024-12-23 20:36 ` NeilBrown
2024-12-24 10:26 ` Hillf Danton
2024-12-20 2:54 ` [PATCH 09/11] VFS: re-pack DENTRY_ flags NeilBrown
2024-12-20 2:54 ` [PATCH 10/11] VFS: take a shared lock for create/remove directory operations NeilBrown
2024-12-23 5:19 ` Al Viro
2024-12-23 7:11 ` NeilBrown
2024-12-23 7:26 ` Al Viro
2024-12-23 20:40 ` NeilBrown
2024-12-20 2:54 ` [PATCH 11/11] nfsd: use lookup_and_lock_one() NeilBrown
2024-12-20 20:55 ` [PATCH 00/11 RFC] Allow concurrent changes in a directory Andreas Dilger
2024-12-23 5:22 ` Al Viro
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=20241220030830.272429-5-neilb@suse.de \
--to=neilb@suse.de \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.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