]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: qgroup: avoid memory allocation if qgroups are not enabled
authorFilipe Manana <fdmanana@suse.com>
Thu, 26 Jun 2025 15:57:02 +0000 (16:57 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 21:58:04 +0000 (23:58 +0200)
At btrfs_qgroup_inherit() we allocate a qgroup record even if qgroups are
not enabled, which is unnecessary overhead and can result in subvolume
creation to fail with -ENOMEM, as create_subvol() calls this function.

Improve on this by making btrfs_qgroup_inherit() check if qgroups are
enabled earlier and return if they are not, avoiding the unnecessary
memory allocation and taking some locks.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.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/qgroup.c

index afc9a27071298f32d3581d09eac6e150220da1ba..b83d9534adaed3bffdea930a7f3357219b3c3dce 100644 (file)
@@ -3328,6 +3328,9 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
        u32 level_size = 0;
        u64 nums;
 
+       if (!btrfs_qgroup_enabled(fs_info))
+               return 0;
+
        prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
        if (!prealloc)
                return -ENOMEM;
@@ -3351,8 +3354,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
 
        if (!committing)
                mutex_lock(&fs_info->qgroup_ioctl_lock);
-       if (!btrfs_qgroup_enabled(fs_info))
-               goto out;
 
        quota_root = fs_info->quota_root;
        if (!quota_root) {