summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2026-01-13 15:39:50 +0300
committerChristian Brauner <brauner@kernel.org>2026-01-14 19:17:47 +0300
commit173e937552432db9406f04eb7905541b774ac7cd (patch)
tree955d11473e0d2ff307fe7802160e7baf467ef4bd
parent8f0b4cce4481fb22653697cced8d0d04027cb1e8 (diff)
downloadlinux-173e937552432db9406f04eb7905541b774ac7cd.tar.xz
fs: export may_delete() as may_delete_dentry()
For many years btrfs as been using a copy of may_delete() in fs/btrfs/ioctl.c:btrfs_may_delete(). Everytime may_delete() 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_delete(). Export may_delete() so that btrfs can use it and with the less generic name may_delete_dentry(). While at it change the calls in vfs_rmdir() to pass a boolean literal instead of 1 and 0 as the last argument since the argument has a bool type. Signed-off-by: Filipe Manana <fdmanana@suse.com> Link: https://patch.msgid.link/e09128fd53f01b19d0a58f0e7d24739f79f47f6d.1768307858.git.fdmanana@suse.com Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
-rw-r--r--fs/namei.c17
-rw-r--r--include/linux/fs.h3
2 files changed, 12 insertions, 8 deletions
diff --git a/fs/namei.c b/fs/namei.c
index bf0f66f0e9b9..28aebc786e8f 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -3604,7 +3604,7 @@ EXPORT_SYMBOL(__check_sticky);
* 11. We don't allow removal of NFS sillyrenamed files; it's handled by
* nfs_async_unlink().
*/
-static int may_delete(struct mnt_idmap *idmap, struct inode *dir,
+int may_delete_dentry(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *victim, bool isdir)
{
struct inode *inode = d_backing_inode(victim);
@@ -3646,6 +3646,7 @@ static int may_delete(struct mnt_idmap *idmap, struct inode *dir,
return -EBUSY;
return 0;
}
+EXPORT_SYMBOL(may_delete_dentry);
/* Check whether we can create an object with dentry child in directory
* dir.
@@ -5209,7 +5210,7 @@ SYSCALL_DEFINE2(mkdir, const char __user *, pathname, umode_t, mode)
int vfs_rmdir(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, struct delegated_inode *delegated_inode)
{
- int error = may_delete(idmap, dir, dentry, 1);
+ int error = may_delete_dentry(idmap, dir, dentry, true);
if (error)
return error;
@@ -5344,7 +5345,7 @@ int vfs_unlink(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, struct delegated_inode *delegated_inode)
{
struct inode *target = dentry->d_inode;
- int error = may_delete(idmap, dir, dentry, 0);
+ int error = may_delete_dentry(idmap, dir, dentry, false);
if (error)
return error;
@@ -5816,7 +5817,7 @@ int vfs_rename(struct renamedata *rd)
if (source == target)
return 0;
- error = may_delete(rd->mnt_idmap, old_dir, old_dentry, is_dir);
+ error = may_delete_dentry(rd->mnt_idmap, old_dir, old_dentry, is_dir);
if (error)
return error;
@@ -5826,11 +5827,11 @@ int vfs_rename(struct renamedata *rd)
new_is_dir = d_is_dir(new_dentry);
if (!(flags & RENAME_EXCHANGE))
- error = may_delete(rd->mnt_idmap, new_dir,
- new_dentry, is_dir);
+ error = may_delete_dentry(rd->mnt_idmap, new_dir,
+ new_dentry, is_dir);
else
- error = may_delete(rd->mnt_idmap, new_dir,
- new_dentry, new_is_dir);
+ error = may_delete_dentry(rd->mnt_idmap, new_dir,
+ new_dentry, new_is_dir);
}
if (error)
return error;
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 04ceeca12a0d..06632783a76c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2657,6 +2657,9 @@ static inline int path_permission(const struct path *path, int mask)
int __check_sticky(struct mnt_idmap *idmap, struct inode *dir,
struct inode *inode);
+int may_delete_dentry(struct mnt_idmap *idmap, struct inode *dir,
+ struct dentry *victim, bool isdir);
+
static inline bool execute_ok(struct inode *inode)
{
return (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode);