Skip to content

Commit 3c6e359

Browse files
fdmananakdave
authored andcommitted
btrfs: qgroup: avoid memory allocation if qgroups are not enabled
At btrfs_qgroup_inherit() we allocate a qgroup record even if qgroups are not enabled, which is unnecessary overhead and can result in subvolume and snapshot 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. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 50bed70 commit 3c6e359

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/btrfs/qgroup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,6 +3328,9 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
33283328
u32 level_size = 0;
33293329
u64 nums;
33303330

3331+
if (!btrfs_qgroup_enabled(fs_info))
3332+
return 0;
3333+
33313334
prealloc = kzalloc(sizeof(*prealloc), GFP_NOFS);
33323335
if (!prealloc)
33333336
return -ENOMEM;
@@ -3351,8 +3354,6 @@ int btrfs_qgroup_inherit(struct btrfs_trans_handle *trans, u64 srcid,
33513354

33523355
if (!committing)
33533356
mutex_lock(&fs_info->qgroup_ioctl_lock);
3354-
if (!btrfs_qgroup_enabled(fs_info))
3355-
goto out;
33563357

33573358
quota_root = fs_info->quota_root;
33583359
if (!quota_root) {

0 commit comments

Comments
 (0)