]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: qgroup: use btrfs_qgroup_enabled() in ioctls
authorFilipe Manana <fdmanana@suse.com>
Tue, 1 Jul 2025 14:25:14 +0000 (15:25 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 22:07:37 +0000 (00:07 +0200)
We have a publicly exported btrfs_qgroup_enabled() and an ioctl.c private
qgroup_enabled() helper. Both of these test if qgroups are enabled, the
first check if the flag BTRFS_FS_QUOTA_ENABLED is set in fs_info->flags
while the second checks if fs_info->quota_root is not NULL while holding
the mutex fs_info->qgroup_ioctl_lock.

We can get away with the private ioctl.c:qgroup_enabled(), as all entry
points into the qgroup code check if fs_info->quota_root is NULL or not
while holding the mutex fs_info->qgroup_ioctl_lock, and returning the
error -ENOTCONN in case it's NULL.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c

index c9ab1e12525ed247115dbbc6f20fb90615177c3f..503c469249e5e5020484f4442111427a93690b51 100644 (file)
@@ -3711,22 +3711,6 @@ drop_write:
        return ret;
 }
 
-/*
- * Quick check for ioctl handlers if quotas are enabled. Proper locking must be
- * done before any operations.
- */
-static bool qgroup_enabled(struct btrfs_fs_info *fs_info)
-{
-       bool ret = true;
-
-       mutex_lock(&fs_info->qgroup_ioctl_lock);
-       if (!fs_info->quota_root)
-               ret = false;
-       mutex_unlock(&fs_info->qgroup_ioctl_lock);
-
-       return ret;
-}
-
 static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
 {
        struct inode *inode = file_inode(file);
@@ -3741,7 +3725,7 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       if (!qgroup_enabled(root->fs_info))
+       if (!btrfs_qgroup_enabled(fs_info))
                return -ENOTCONN;
 
        ret = mnt_want_write_file(file);
@@ -3811,7 +3795,7 @@ static long btrfs_ioctl_qgroup_create(struct file *file, void __user *arg)
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       if (!qgroup_enabled(root->fs_info))
+       if (!btrfs_qgroup_enabled(root->fs_info))
                return -ENOTCONN;
 
        ret = mnt_want_write_file(file);
@@ -3870,7 +3854,7 @@ static long btrfs_ioctl_qgroup_limit(struct file *file, void __user *arg)
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       if (!qgroup_enabled(root->fs_info))
+       if (!btrfs_qgroup_enabled(root->fs_info))
                return -ENOTCONN;
 
        ret = mnt_want_write_file(file);
@@ -3918,7 +3902,7 @@ static long btrfs_ioctl_quota_rescan(struct file *file, void __user *arg)
        if (!capable(CAP_SYS_ADMIN))
                return -EPERM;
 
-       if (!qgroup_enabled(fs_info))
+       if (!btrfs_qgroup_enabled(fs_info))
                return -ENOTCONN;
 
        ret = mnt_want_write_file(file);