]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
VFS: move dentry_create() from fs/open.c to fs/namei.c
authorBenjamin Coddington <bcodding@hammerspace.com>
Thu, 27 Nov 2025 16:02:03 +0000 (11:02 -0500)
committerChristian Brauner <brauner@kernel.org>
Mon, 15 Dec 2025 13:12:41 +0000 (14:12 +0100)
To prepare knfsd's helper dentry_create(), move it to namei.c so that it
can access static functions within.  Callers of dentry_create() can be
viewed as being mostly done with lookup, but still need to perform a few
final checks.  In order to use atomic_open() we want dentry_create() to
be able to access:

- vfs_prepare_mode
- may_o_create
- atomic_open

.. all of which have static declarations.

Signed-off-by: Benjamin Coddington <bcodding@hammerspace.com>
Link: https://patch.msgid.link/42deec53a50e1676e5501f8f1e17967d47b83681.1764259052.git.bcodding@hammerspace.com
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/namei.c
fs/open.c

index bf0f66f0e9b92c106fc92759d22f8158187c29d1..1f21cd85300cc885f60b8c3c10275536b4262a2a 100644 (file)
@@ -4937,6 +4937,44 @@ inline struct dentry *start_creating_user_path(
 }
 EXPORT_SYMBOL(start_creating_user_path);
 
+/**
+ * dentry_create - Create and open a file
+ * @path: path to create
+ * @flags: O_ flags
+ * @mode: mode bits for new file
+ * @cred: credentials to use
+ *
+ * Caller must hold the parent directory's lock, and have prepared
+ * a negative dentry, placed in @path->dentry, for the new file.
+ *
+ * Caller sets @path->mnt to the vfsmount of the filesystem where
+ * the new file is to be created. The parent directory and the
+ * negative dentry must reside on the same filesystem instance.
+ *
+ * On success, returns a "struct file *". Otherwise a ERR_PTR
+ * is returned.
+ */
+struct file *dentry_create(const struct path *path, int flags, umode_t mode,
+                          const struct cred *cred)
+{
+       struct file *f;
+       int error;
+
+       f = alloc_empty_file(flags, cred);
+       if (IS_ERR(f))
+               return f;
+
+       error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
+       if (!error)
+               error = vfs_open(path, f);
+
+       if (unlikely(error)) {
+               fput(f);
+               return ERR_PTR(error);
+       }
+       return f;
+}
+EXPORT_SYMBOL(dentry_create);
 
 /**
  * vfs_mknod - create device node or file
index f328622061c56cffb5f7355340725f261e9ab42a..74c4c1462b3e47f9498bd97483c423cf00650633 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -1141,45 +1141,6 @@ struct file *dentry_open_nonotify(const struct path *path, int flags,
        return f;
 }
 
-/**
- * dentry_create - Create and open a file
- * @path: path to create
- * @flags: O_ flags
- * @mode: mode bits for new file
- * @cred: credentials to use
- *
- * Caller must hold the parent directory's lock, and have prepared
- * a negative dentry, placed in @path->dentry, for the new file.
- *
- * Caller sets @path->mnt to the vfsmount of the filesystem where
- * the new file is to be created. The parent directory and the
- * negative dentry must reside on the same filesystem instance.
- *
- * On success, returns a "struct file *". Otherwise a ERR_PTR
- * is returned.
- */
-struct file *dentry_create(const struct path *path, int flags, umode_t mode,
-                          const struct cred *cred)
-{
-       struct file *f;
-       int error;
-
-       f = alloc_empty_file(flags, cred);
-       if (IS_ERR(f))
-               return f;
-
-       error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
-       if (!error)
-               error = vfs_open(path, f);
-
-       if (unlikely(error)) {
-               fput(f);
-               return ERR_PTR(error);
-       }
-       return f;
-}
-EXPORT_SYMBOL(dentry_create);
-
 /**
  * kernel_file_open - open a file for kernel internal use
  * @path:      path of the file to open