Skip to content

Commit 26aab3a

Browse files
fdmananabrauner
authored andcommitted
fs: export may_create() as may_create_dentry()
For many years btrfs as been using a copy of may_create() in fs/btrfs/ioctl.c:btrfs_may_create(). Everytime may_create() is updated we need to update the btrfs copy, and this is a maintenance burden. Currently there are minor differences between both because the btrfs side lacks updates done in may_create(). Export may_create() so that btrfs can use it and with the less generic name may_create_dentry(). Signed-off-by: Filipe Manana <fdmanana@suse.com> Link: https://patch.msgid.link/ce5174bca079f4cdcbb8dd145f0924feb1f227cd.1768307858.git.fdmanana@suse.com Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 173e937 commit 26aab3a

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

fs/namei.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,8 +3657,8 @@ EXPORT_SYMBOL(may_delete_dentry);
36573657
* 4. We should have write and exec permissions on dir
36583658
* 5. We can't do it if dir is immutable (done in permission())
36593659
*/
3660-
static inline int may_create(struct mnt_idmap *idmap,
3661-
struct inode *dir, struct dentry *child)
3660+
int may_create_dentry(struct mnt_idmap *idmap,
3661+
struct inode *dir, struct dentry *child)
36623662
{
36633663
audit_inode_child(dir, child, AUDIT_TYPE_CHILD_CREATE);
36643664
if (child->d_inode)
@@ -3670,6 +3670,7 @@ static inline int may_create(struct mnt_idmap *idmap,
36703670

36713671
return inode_permission(idmap, dir, MAY_WRITE | MAY_EXEC);
36723672
}
3673+
EXPORT_SYMBOL(may_create_dentry);
36733674

36743675
// p1 != p2, both are on the same filesystem, ->s_vfs_rename_mutex is held
36753676
static struct dentry *lock_two_directories(struct dentry *p1, struct dentry *p2)
@@ -4116,7 +4117,7 @@ int vfs_create(struct mnt_idmap *idmap, struct dentry *dentry, umode_t mode,
41164117
struct inode *dir = d_inode(dentry->d_parent);
41174118
int error;
41184119

4119-
error = may_create(idmap, dir, dentry);
4120+
error = may_create_dentry(idmap, dir, dentry);
41204121
if (error)
41214122
return error;
41224123

@@ -4142,7 +4143,7 @@ int vfs_mkobj(struct dentry *dentry, umode_t mode,
41424143
void *arg)
41434144
{
41444145
struct inode *dir = dentry->d_parent->d_inode;
4145-
int error = may_create(&nop_mnt_idmap, dir, dentry);
4146+
int error = may_create_dentry(&nop_mnt_idmap, dir, dentry);
41464147
if (error)
41474148
return error;
41484149

@@ -4961,7 +4962,7 @@ int vfs_mknod(struct mnt_idmap *idmap, struct inode *dir,
49614962
struct delegated_inode *delegated_inode)
49624963
{
49634964
bool is_whiteout = S_ISCHR(mode) && dev == WHITEOUT_DEV;
4964-
int error = may_create(idmap, dir, dentry);
4965+
int error = may_create_dentry(idmap, dir, dentry);
49654966

49664967
if (error)
49674968
return error;
@@ -5107,7 +5108,7 @@ struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
51075108
unsigned max_links = dir->i_sb->s_max_links;
51085109
struct dentry *de;
51095110

5110-
error = may_create(idmap, dir, dentry);
5111+
error = may_create_dentry(idmap, dir, dentry);
51115112
if (error)
51125113
goto err;
51135114

@@ -5497,7 +5498,7 @@ int vfs_symlink(struct mnt_idmap *idmap, struct inode *dir,
54975498
{
54985499
int error;
54995500

5500-
error = may_create(idmap, dir, dentry);
5501+
error = may_create_dentry(idmap, dir, dentry);
55015502
if (error)
55025503
return error;
55035504

@@ -5605,7 +5606,7 @@ int vfs_link(struct dentry *old_dentry, struct mnt_idmap *idmap,
56055606
if (!inode)
56065607
return -ENOENT;
56075608

5608-
error = may_create(idmap, dir, new_dentry);
5609+
error = may_create_dentry(idmap, dir, new_dentry);
56095610
if (error)
56105611
return error;
56115612

@@ -5822,7 +5823,7 @@ int vfs_rename(struct renamedata *rd)
58225823
return error;
58235824

58245825
if (!target) {
5825-
error = may_create(rd->mnt_idmap, new_dir, new_dentry);
5826+
error = may_create_dentry(rd->mnt_idmap, new_dir, new_dentry);
58265827
} else {
58275828
new_is_dir = d_is_dir(new_dentry);
58285829

include/linux/fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,8 @@ int __check_sticky(struct mnt_idmap *idmap, struct inode *dir,
26592659

26602660
int may_delete_dentry(struct mnt_idmap *idmap, struct inode *dir,
26612661
struct dentry *victim, bool isdir);
2662+
int may_create_dentry(struct mnt_idmap *idmap,
2663+
struct inode *dir, struct dentry *child);
26622664

26632665
static inline bool execute_ok(struct inode *inode)
26642666
{

0 commit comments

Comments
 (0)