Skip to content

Commit 977de00

Browse files
Benjamin Coddingtonbrauner
authored andcommitted
VFS: move dentry_create() from fs/open.c to fs/namei.c
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>
1 parent 8f0b4cc commit 977de00

2 files changed

Lines changed: 38 additions & 39 deletions

File tree

fs/namei.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4937,6 +4937,44 @@ inline struct dentry *start_creating_user_path(
49374937
}
49384938
EXPORT_SYMBOL(start_creating_user_path);
49394939

4940+
/**
4941+
* dentry_create - Create and open a file
4942+
* @path: path to create
4943+
* @flags: O_ flags
4944+
* @mode: mode bits for new file
4945+
* @cred: credentials to use
4946+
*
4947+
* Caller must hold the parent directory's lock, and have prepared
4948+
* a negative dentry, placed in @path->dentry, for the new file.
4949+
*
4950+
* Caller sets @path->mnt to the vfsmount of the filesystem where
4951+
* the new file is to be created. The parent directory and the
4952+
* negative dentry must reside on the same filesystem instance.
4953+
*
4954+
* On success, returns a "struct file *". Otherwise a ERR_PTR
4955+
* is returned.
4956+
*/
4957+
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
4958+
const struct cred *cred)
4959+
{
4960+
struct file *f;
4961+
int error;
4962+
4963+
f = alloc_empty_file(flags, cred);
4964+
if (IS_ERR(f))
4965+
return f;
4966+
4967+
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
4968+
if (!error)
4969+
error = vfs_open(path, f);
4970+
4971+
if (unlikely(error)) {
4972+
fput(f);
4973+
return ERR_PTR(error);
4974+
}
4975+
return f;
4976+
}
4977+
EXPORT_SYMBOL(dentry_create);
49404978

49414979
/**
49424980
* vfs_mknod - create device node or file

fs/open.c

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,45 +1141,6 @@ struct file *dentry_open_nonotify(const struct path *path, int flags,
11411141
return f;
11421142
}
11431143

1144-
/**
1145-
* dentry_create - Create and open a file
1146-
* @path: path to create
1147-
* @flags: O_ flags
1148-
* @mode: mode bits for new file
1149-
* @cred: credentials to use
1150-
*
1151-
* Caller must hold the parent directory's lock, and have prepared
1152-
* a negative dentry, placed in @path->dentry, for the new file.
1153-
*
1154-
* Caller sets @path->mnt to the vfsmount of the filesystem where
1155-
* the new file is to be created. The parent directory and the
1156-
* negative dentry must reside on the same filesystem instance.
1157-
*
1158-
* On success, returns a "struct file *". Otherwise a ERR_PTR
1159-
* is returned.
1160-
*/
1161-
struct file *dentry_create(const struct path *path, int flags, umode_t mode,
1162-
const struct cred *cred)
1163-
{
1164-
struct file *f;
1165-
int error;
1166-
1167-
f = alloc_empty_file(flags, cred);
1168-
if (IS_ERR(f))
1169-
return f;
1170-
1171-
error = vfs_create(mnt_idmap(path->mnt), path->dentry, mode, NULL);
1172-
if (!error)
1173-
error = vfs_open(path, f);
1174-
1175-
if (unlikely(error)) {
1176-
fput(f);
1177-
return ERR_PTR(error);
1178-
}
1179-
return f;
1180-
}
1181-
EXPORT_SYMBOL(dentry_create);
1182-
11831144
/**
11841145
* kernel_file_open - open a file for kernel internal use
11851146
* @path: path of the file to open

0 commit comments

Comments
 (0)