summaryrefslogtreecommitdiff
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorFilipe Manana <fdmanana@suse.com>2015-06-09 17:48:21 +0100
committerChris Mason <clm@fb.com>2015-06-10 07:02:46 -0700
commit4617ea3a52cfe8ae407ef406ab999f40a558c369 (patch)
tree12f1391feee7674ed4d411ae71a0bd1c4ffb20c6 /fs/btrfs/extent-tree.c
parent7558c8bc17481c1f856e009af8503ab40fec348a (diff)
downloadlwn-4617ea3a52cfe8ae407ef406ab999f40a558c369.tar.gz
lwn-4617ea3a52cfe8ae407ef406ab999f40a558c369.zip
Btrfs: fix necessary chunk tree space calculation when allocating a chunk
When allocating a new chunk or removing one we need to update num_devs device items and insert or remove a chunk item in the chunk tree, so in the worst case the space needed in the chunk space_info is: btrfs_calc_trunc_metadata_size(chunk_root, num_devs) + btrfs_calc_trans_metadata_size(chunk_root, 1) That is, in the worst case we need to cow num_devs paths and cow 1 other path that can result in splitting every node and leaf, and each path consisting of BTRFS_MAX_LEVEL - 1 nodes and 1 leaf. We were requiring some additional chunk_root->nodesize * BTRFS_MAX_LEVEL * num_devs bytes, which were unnecessary since updating the existing device items does not result in splitting the nodes and leaf since after updating them they remain with the same size. Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index f1d1216f7feb..4eefabcc838f 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -4116,8 +4116,7 @@ static u64 get_profile_num_devs(struct btrfs_root *root, u64 type)
*/
void check_system_chunk(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
- u64 type,
- const bool is_allocation)
+ u64 type)
{
struct btrfs_space_info *info;
u64 left;
@@ -4141,11 +4140,8 @@ void check_system_chunk(struct btrfs_trans_handle *trans,
num_devs = get_profile_num_devs(root, type);
/* num_devs device items to update and 1 chunk item to add or remove */
- if (is_allocation)
- thresh = btrfs_calc_trans_metadata_size(root, num_devs + 1);
- else
- thresh = btrfs_calc_trans_metadata_size(root, num_devs) +
- btrfs_calc_trunc_metadata_size(root, 1);
+ thresh = btrfs_calc_trunc_metadata_size(root, num_devs) +
+ btrfs_calc_trans_metadata_size(root, 1);
if (left < thresh && btrfs_test_opt(root, ENOSPC_DEBUG)) {
btrfs_info(root->fs_info, "left=%llu, need=%llu, flags=%llu",
@@ -4258,7 +4254,7 @@ again:
* Check if we have enough space in SYSTEM chunk because we may need
* to update devices.
*/
- check_system_chunk(trans, extent_root, flags, true);
+ check_system_chunk(trans, extent_root, flags);
ret = btrfs_alloc_chunk(trans, extent_root, flags);
trans->allocating_chunk = false;
@@ -8926,7 +8922,7 @@ out:
if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
alloc_flags = update_block_group_flags(root, cache->flags);
lock_chunks(root->fs_info->chunk_root);
- check_system_chunk(trans, root, alloc_flags, true);
+ check_system_chunk(trans, root, alloc_flags);
unlock_chunks(root->fs_info->chunk_root);
}
mutex_unlock(&root->fs_info->ro_block_group_mutex);