Skip to content

Commit a5b7f42

Browse files
Lu Fengqikdave
authored andcommitted
btrfs: fix qgroup_free wrong num_bytes in btrfs_subvolume_reserve_metadata
After btrfs_qgroup_reserve_meta_prealloc(), num_bytes will be assigned again by btrfs_calc_trans_metadata_size(). Once block_rsv fails, we can't properly free the num_bytes of the previous qgroup_reserve. Use a separate variable to store the num_bytes of the qgroup_reserve. Delete the comment for the qgroup_reserved that does not exist and add a comment about use_global_rsv. Fixes: c4c129d ("btrfs: drop unused parameter qgroup_reserved") CC: [email protected] # 4.18+ Signed-off-by: Lu Fengqi <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent de02b9f commit a5b7f42

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

fs/btrfs/extent-tree.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5800,7 +5800,7 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
58005800
* root: the root of the parent directory
58015801
* rsv: block reservation
58025802
* items: the number of items that we need do reservation
5803-
* qgroup_reserved: used to return the reserved size in qgroup
5803+
* use_global_rsv: allow fallback to the global block reservation
58045804
*
58055805
* This function is used to reserve the space for snapshot/subvolume
58065806
* creation and deletion. Those operations are different with the
@@ -5810,23 +5810,22 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
58105810
* the space reservation mechanism in start_transaction().
58115811
*/
58125812
int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5813-
struct btrfs_block_rsv *rsv,
5814-
int items,
5813+
struct btrfs_block_rsv *rsv, int items,
58155814
bool use_global_rsv)
58165815
{
5816+
u64 qgroup_num_bytes = 0;
58175817
u64 num_bytes;
58185818
int ret;
58195819
struct btrfs_fs_info *fs_info = root->fs_info;
58205820
struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
58215821

58225822
if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
58235823
/* One for parent inode, two for dir entries */
5824-
num_bytes = 3 * fs_info->nodesize;
5825-
ret = btrfs_qgroup_reserve_meta_prealloc(root, num_bytes, true);
5824+
qgroup_num_bytes = 3 * fs_info->nodesize;
5825+
ret = btrfs_qgroup_reserve_meta_prealloc(root,
5826+
qgroup_num_bytes, true);
58265827
if (ret)
58275828
return ret;
5828-
} else {
5829-
num_bytes = 0;
58305829
}
58315830

58325831
num_bytes = btrfs_calc_trans_metadata_size(fs_info, items);
@@ -5838,8 +5837,8 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
58385837
if (ret == -ENOSPC && use_global_rsv)
58395838
ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1);
58405839

5841-
if (ret && num_bytes)
5842-
btrfs_qgroup_free_meta_prealloc(root, num_bytes);
5840+
if (ret && qgroup_num_bytes)
5841+
btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes);
58435842

58445843
return ret;
58455844
}

0 commit comments

Comments
 (0)