aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLu Fengqi <lufq.fnst@cn.fujitsu.com>2018-08-08 21:46:04 -0400
committerDavid Sterba <dsterba@suse.com>2018-08-23 11:37:26 -0400
commita5b7f4295eeae8b05ca91f6d145cd8773b08de9e (patch)
tree34d2cb5ef46a2c16c6673010f200d17fbd5fd732
parentde02b9f6bb65a6a1848f346f7a3617b7a9b930c0 (diff)
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: c4c129db5da8 ("btrfs: drop unused parameter qgroup_reserved") CC: stable@vger.kernel.org # 4.18+ Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--fs/btrfs/extent-tree.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index de6f75f5547b..2d9074295d7f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5800,7 +5800,7 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
5800 * root: the root of the parent directory 5800 * root: the root of the parent directory
5801 * rsv: block reservation 5801 * rsv: block reservation
5802 * items: the number of items that we need do reservation 5802 * 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
5804 * 5804 *
5805 * This function is used to reserve the space for snapshot/subvolume 5805 * This function is used to reserve the space for snapshot/subvolume
5806 * creation and deletion. Those operations are different with the 5806 * creation and deletion. Those operations are different with the
@@ -5810,10 +5810,10 @@ void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans)
5810 * the space reservation mechanism in start_transaction(). 5810 * the space reservation mechanism in start_transaction().
5811 */ 5811 */
5812int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, 5812int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5813 struct btrfs_block_rsv *rsv, 5813 struct btrfs_block_rsv *rsv, int items,
5814 int items,
5815 bool use_global_rsv) 5814 bool use_global_rsv)
5816{ 5815{
5816 u64 qgroup_num_bytes = 0;
5817 u64 num_bytes; 5817 u64 num_bytes;
5818 int ret; 5818 int ret;
5819 struct btrfs_fs_info *fs_info = root->fs_info; 5819 struct btrfs_fs_info *fs_info = root->fs_info;
@@ -5821,12 +5821,11 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5821 5821
5822 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) { 5822 if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
5823 /* One for parent inode, two for dir entries */ 5823 /* One for parent inode, two for dir entries */
5824 num_bytes = 3 * fs_info->nodesize; 5824 qgroup_num_bytes = 3 * fs_info->nodesize;
5825 ret = btrfs_qgroup_reserve_meta_prealloc(root, num_bytes, true); 5825 ret = btrfs_qgroup_reserve_meta_prealloc(root,
5826 qgroup_num_bytes, true);
5826 if (ret) 5827 if (ret)
5827 return ret; 5828 return ret;
5828 } else {
5829 num_bytes = 0;
5830 } 5829 }
5831 5830
5832 num_bytes = btrfs_calc_trans_metadata_size(fs_info, items); 5831 num_bytes = btrfs_calc_trans_metadata_size(fs_info, items);
@@ -5838,8 +5837,8 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
5838 if (ret == -ENOSPC && use_global_rsv) 5837 if (ret == -ENOSPC && use_global_rsv)
5839 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1); 5838 ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, 1);
5840 5839
5841 if (ret && num_bytes) 5840 if (ret && qgroup_num_bytes)
5842 btrfs_qgroup_free_meta_prealloc(root, num_bytes); 5841 btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes);
5843 5842
5844 return ret; 5843 return ret;
5845} 5844}