From: NeilBrown <neil@brown.name>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/7] VFS: add dentry_lookup_killable()
Date: Mon, 21 Jul 2025 18:00:01 +1000 [thread overview]
Message-ID: <20250721084412.370258-6-neil@brown.name> (raw)
In-Reply-To: <20250721084412.370258-1-neil@brown.name>
btrfs/ioctl.c uses a "killable" lock on the directory when creating an
destroying subvols. overlayfs also does this.
This patch adds dentry_lookup_killable() for these users.
Possibly all dentry_lookup should be killable as there is no down-side,
but that can come in a later patch.
Signed-off-by: NeilBrown <neil@brown.name>
---
fs/namei.c | 37 +++++++++++++++++++++++++++++++++++++
include/linux/namei.h | 3 +++
2 files changed, 40 insertions(+)
diff --git a/fs/namei.c b/fs/namei.c
index f292df61565a..46657736c7a0 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1799,6 +1799,43 @@ struct dentry *dentry_lookup(struct mnt_idmap *idmap,
}
EXPORT_SYMBOL(dentry_lookup);
+/**
+ * dentry_lookup_killable - lookup and lock a name prior to dir ops
+ * @last: the name in the given directory
+ * @base: the directory in which the name is to be found
+ * @lookup_flags: %LOOKUP_xxx flags
+ *
+ * The name is looked up and necessary locks are taken so that
+ * the name can be created or removed.
+ * The "necessary locks" are currently the inode node lock on @base.
+ * If a fatal signal arrives or is already pending the operation is aborted.
+ * The name @last is NOT expected to already have the hash calculated.
+ * Permission checks are performed to ensure %MAY_EXEC access to @base.
+ * Returns: the dentry, suitably locked, or an ERR_PTR().
+ */
+struct dentry *dentry_lookup_killable(struct mnt_idmap *idmap,
+ struct qstr *last,
+ struct dentry *base,
+ unsigned int lookup_flags)
+{
+ struct dentry *dentry;
+ int err;
+
+ err = lookup_one_common(idmap, last, base);
+ if (err < 0)
+ return ERR_PTR(err);
+
+ err = down_write_killable_nested(&base->d_inode->i_rwsem, I_MUTEX_PARENT);
+ if (err)
+ return ERR_PTR(err);
+
+ dentry = lookup_one_qstr_excl(last, base, lookup_flags);
+ if (IS_ERR(dentry))
+ inode_unlock(base->d_inode);
+ return dentry;
+}
+EXPORT_SYMBOL(dentry_lookup_killable);
+
/**
* done_dentry_lookup - finish a lookup used for create/delete
* @dentry: the target dentry
diff --git a/include/linux/namei.h b/include/linux/namei.h
index 6d2cf4af5f16..8eade32623d8 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -83,6 +83,9 @@ struct dentry *lookup_one_positive_unlocked(struct mnt_idmap *idmap,
struct dentry *dentry_lookup(struct mnt_idmap *idmap,
struct qstr *last, struct dentry *base,
unsigned int lookup_flags);
+struct dentry *dentry_lookup_killable(struct mnt_idmap *idmap,
+ struct qstr *last, struct dentry *base,
+ unsigned int lookup_flags);
struct dentry *dentry_lookup_noperm(struct qstr *name, struct dentry *base,
unsigned int lookup_flags);
struct dentry *dentry_lookup_hashed(struct qstr *last, struct dentry *base,
--
2.49.0
next prev parent reply other threads:[~2025-07-21 8:45 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 7:59 [PATCH 0/7 RFC] New APIs for name lookup and lock for directory operations NeilBrown
2025-07-21 7:59 ` [PATCH 1/7] VFS: unify old_mnt_idmap and new_mnt_idmap in renamedata NeilBrown
2025-07-21 13:06 ` Jeff Layton
2025-07-21 7:59 ` [PATCH 2/7] VFS: introduce done_dentry_lookup() NeilBrown
2025-07-21 13:39 ` Jeff Layton
2025-07-21 23:04 ` NeilBrown
2025-07-21 7:59 ` [PATCH 3/7] VFS: Change vfs_mkdir() to unlock on failure NeilBrown
2025-07-21 14:46 ` Jeff Layton
2025-07-21 23:08 ` NeilBrown
2025-07-21 8:00 ` [PATCH 4/7] VFS: introduce dentry_lookup() and friends NeilBrown
2025-07-21 10:20 ` Amir Goldstein
2025-07-21 23:27 ` NeilBrown
2025-07-23 15:17 ` Amir Goldstein
2025-07-21 8:00 ` NeilBrown [this message]
2025-07-21 8:00 ` [PATCH 6/7] VFS: add rename_lookup() NeilBrown
2025-07-21 8:00 ` [PATCH 7/7] VFS: introduce dentry_lock_in() NeilBrown
2025-07-21 11:32 ` [PATCH 0/7 RFC] New APIs for name lookup and lock for directory operations Amir Goldstein
2025-07-21 23:48 ` 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=20250721084412.370258-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=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
all inboxes | Powered by JetHome®