From: Mateusz Guzik <mjguzik@gmail.com>
To: brauner@kernel.org
Cc: viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Mateusz Guzik <mjguzik@gmail.com>
Subject: [PATCH 02/10] fs: add path_create(), path_move() and path_clone()
Date: Sun, 13 Sep 2026 16:49:09 +0200 [thread overview]
Message-ID: <20260913144918.1606123-3-mjguzik@gmail.com> (raw)
In-Reply-To: <20260913144918.1606123-1-mjguzik@gmail.com>
Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
---
fs/namei.c | 29 +++++++++++++++++++++++++++++
include/linux/path.h | 14 ++++++++++++--
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index ca4f5e3be99a..c8754c7ba8be 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -698,6 +698,35 @@ static __always_inline int lookup_inode_permission_may_exec(struct mnt_idmap *id
return security_inode_permission(inode, mask);
}
+/**
+ * path_create - WRITEME
+ * @path: path to get the reference to
+ * @mnt: WRITEME
+ * @dentry: WRITEME
+ *
+ * Create a path object using the given vfsmount and dentry pair while incrementing
+ * the reference count on both.
+ */
+void path_create(struct path *path, struct vfsmount *mnt, struct dentry *dentry)
+{
+ path->mnt = mntget(mnt);
+ path->dentry = dget(dentry);
+}
+EXPORT_SYMBOL(path_create);
+
+/**
+ * path_clone - WRITEME
+ * @path: path to get the reference to
+ *
+ * Given a path increment the reference count to the dentry and the vfsmount.
+ */
+void path_clone(const struct path *src, struct path *dst)
+{
+ dst->mnt = mntget(src->mnt);
+ dst->dentry = dget(src->dentry);
+}
+EXPORT_SYMBOL(path_clone);
+
/**
* path_get - get a reference to a path
* @path: path to get the reference to
diff --git a/include/linux/path.h b/include/linux/path.h
index 7ea389dc764b..8a621e0e1921 100644
--- a/include/linux/path.h
+++ b/include/linux/path.h
@@ -10,8 +10,18 @@ struct path {
struct dentry *dentry;
} __randomize_layout;
-extern void path_get(const struct path *);
-extern void path_put(const struct path *);
+void path_create(struct path *, struct vfsmount *, struct dentry *);
+void path_clone(const struct path *, struct path *);
+void path_get(const struct path *);
+void path_put(const struct path *);
+
+static inline void path_move(struct path *src, struct path *dst)
+{
+ dst->mnt = src->mnt;
+ dst->dentry = src->dentry;
+ src->mnt = NULL;
+ src->dentry = NULL;
+}
static inline int path_equal(const struct path *path1, const struct path *path2)
{
--
2.53.0
next prev parent reply other threads:[~2026-09-13 14:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-13 14:49 [PATCH 00/10] Towards safer path_* API Mateusz Guzik
2026-09-13 14:49 ` [PATCH 01/10] fs: unexport backing_file_set_user_path() and make it take the ref on its own Mateusz Guzik
2026-09-13 14:49 ` Mateusz Guzik [this message]
2026-09-13 14:51 ` [PATCH 02/10] fs: add path_create(), path_move() and path_clone() Mateusz Guzik
2026-09-13 14:49 ` [PATCH 03/10] fs: use path_clone() in path_init() Mateusz Guzik
2026-09-13 14:49 ` [PATCH 04/10] fs: use path_clone() and path_move() in vfs_open* Mateusz Guzik
2026-09-13 14:49 ` [PATCH 05/10] fs: use path_clone() in backing_file_set_user_path() Mateusz Guzik
2026-09-13 14:49 ` [PATCH 06/10] Coccinelle-based conversion of path_* consumers to use the new primitives Mateusz Guzik
2026-09-13 14:49 ` [PATCH 07/10] autofs: use path_create() Mateusz Guzik
2026-09-13 14:49 ` [PATCH 08/10] fsnotify: use path_clone() Mateusz Guzik
2026-09-13 14:49 ` [PATCH 09/10] proc: " Mateusz Guzik
2026-09-13 14:49 ` [PATCH 10/10] nfsd: " Mateusz Guzik
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=20260913144918.1606123-3-mjguzik@gmail.com \
--to=mjguzik@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.