diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2014-01-15 07:00:56 -0500 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-01-28 16:20:39 -0500 |
commit | 215a63d139b1e04ce4b595eeca84671782eb5758 (patch) | |
tree | 9c813902da86e942c2def0468b7f2db54cb9f0f4 /fs/btrfs | |
parent | 920e4a58d27ea146b34674cf9565ab0373f9ca51 (diff) |
Btrfs: cleanup the code of used_block_group in find_free_extent()
used_block_group is just used for the space cluster which doesn't
belong to the current block group, the other place needn't use it.
Or the logic of code seems unclear.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/extent-tree.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 1efcc262be47..b55a4fd13ecc 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -6159,7 +6159,6 @@ static noinline int find_free_extent(struct btrfs_root *orig_root, | |||
6159 | struct btrfs_root *root = orig_root->fs_info->extent_root; | 6159 | struct btrfs_root *root = orig_root->fs_info->extent_root; |
6160 | struct btrfs_free_cluster *last_ptr = NULL; | 6160 | struct btrfs_free_cluster *last_ptr = NULL; |
6161 | struct btrfs_block_group_cache *block_group = NULL; | 6161 | struct btrfs_block_group_cache *block_group = NULL; |
6162 | struct btrfs_block_group_cache *used_block_group; | ||
6163 | u64 search_start = 0; | 6162 | u64 search_start = 0; |
6164 | u64 max_extent_size = 0; | 6163 | u64 max_extent_size = 0; |
6165 | int empty_cluster = 2 * 1024 * 1024; | 6164 | int empty_cluster = 2 * 1024 * 1024; |
@@ -6220,7 +6219,6 @@ static noinline int find_free_extent(struct btrfs_root *orig_root, | |||
6220 | if (search_start == hint_byte) { | 6219 | if (search_start == hint_byte) { |
6221 | block_group = btrfs_lookup_block_group(root->fs_info, | 6220 | block_group = btrfs_lookup_block_group(root->fs_info, |
6222 | search_start); | 6221 | search_start); |
6223 | used_block_group = block_group; | ||
6224 | /* | 6222 | /* |
6225 | * we don't want to use the block group if it doesn't match our | 6223 | * we don't want to use the block group if it doesn't match our |
6226 | * allocation bits, or if its not cached. | 6224 | * allocation bits, or if its not cached. |
@@ -6257,7 +6255,6 @@ search: | |||
6257 | u64 offset; | 6255 | u64 offset; |
6258 | int cached; | 6256 | int cached; |
6259 | 6257 | ||
6260 | used_block_group = block_group; | ||
6261 | btrfs_get_block_group(block_group); | 6258 | btrfs_get_block_group(block_group); |
6262 | search_start = block_group->key.objectid; | 6259 | search_start = block_group->key.objectid; |
6263 | 6260 | ||
@@ -6300,6 +6297,7 @@ have_block_group: | |||
6300 | * lets look there | 6297 | * lets look there |
6301 | */ | 6298 | */ |
6302 | if (last_ptr) { | 6299 | if (last_ptr) { |
6300 | struct btrfs_block_group_cache *used_block_group; | ||
6303 | unsigned long aligned_cluster; | 6301 | unsigned long aligned_cluster; |
6304 | /* | 6302 | /* |
6305 | * the refill lock keeps out other | 6303 | * the refill lock keeps out other |
@@ -6310,10 +6308,8 @@ have_block_group: | |||
6310 | if (used_block_group != block_group && | 6308 | if (used_block_group != block_group && |
6311 | (!used_block_group || | 6309 | (!used_block_group || |
6312 | used_block_group->ro || | 6310 | used_block_group->ro || |
6313 | !block_group_bits(used_block_group, flags))) { | 6311 | !block_group_bits(used_block_group, flags))) |
6314 | used_block_group = block_group; | ||
6315 | goto refill_cluster; | 6312 | goto refill_cluster; |
6316 | } | ||
6317 | 6313 | ||
6318 | if (used_block_group != block_group) | 6314 | if (used_block_group != block_group) |
6319 | btrfs_get_block_group(used_block_group); | 6315 | btrfs_get_block_group(used_block_group); |
@@ -6328,16 +6324,17 @@ have_block_group: | |||
6328 | spin_unlock(&last_ptr->refill_lock); | 6324 | spin_unlock(&last_ptr->refill_lock); |
6329 | trace_btrfs_reserve_extent_cluster(root, | 6325 | trace_btrfs_reserve_extent_cluster(root, |
6330 | block_group, search_start, num_bytes); | 6326 | block_group, search_start, num_bytes); |
6327 | if (used_block_group != block_group) { | ||
6328 | btrfs_put_block_group(block_group); | ||
6329 | block_group = used_block_group; | ||
6330 | } | ||
6331 | goto checks; | 6331 | goto checks; |
6332 | } | 6332 | } |
6333 | 6333 | ||
6334 | WARN_ON(last_ptr->block_group != used_block_group); | 6334 | WARN_ON(last_ptr->block_group != used_block_group); |
6335 | if (used_block_group != block_group) { | 6335 | if (used_block_group != block_group) |
6336 | btrfs_put_block_group(used_block_group); | 6336 | btrfs_put_block_group(used_block_group); |
6337 | used_block_group = block_group; | ||
6338 | } | ||
6339 | refill_cluster: | 6337 | refill_cluster: |
6340 | BUG_ON(used_block_group != block_group); | ||
6341 | /* If we are on LOOP_NO_EMPTY_SIZE, we can't | 6338 | /* If we are on LOOP_NO_EMPTY_SIZE, we can't |
6342 | * set up a new clusters, so lets just skip it | 6339 | * set up a new clusters, so lets just skip it |
6343 | * and let the allocator find whatever block | 6340 | * and let the allocator find whatever block |
@@ -6456,25 +6453,25 @@ unclustered_alloc: | |||
6456 | goto loop; | 6453 | goto loop; |
6457 | } | 6454 | } |
6458 | checks: | 6455 | checks: |
6459 | search_start = stripe_align(root, used_block_group, | 6456 | search_start = stripe_align(root, block_group, |
6460 | offset, num_bytes); | 6457 | offset, num_bytes); |
6461 | 6458 | ||
6462 | /* move on to the next group */ | 6459 | /* move on to the next group */ |
6463 | if (search_start + num_bytes > | 6460 | if (search_start + num_bytes > |
6464 | used_block_group->key.objectid + used_block_group->key.offset) { | 6461 | block_group->key.objectid + block_group->key.offset) { |
6465 | btrfs_add_free_space(used_block_group, offset, num_bytes); | 6462 | btrfs_add_free_space(block_group, offset, num_bytes); |
6466 | goto loop; | 6463 | goto loop; |
6467 | } | 6464 | } |
6468 | 6465 | ||
6469 | if (offset < search_start) | 6466 | if (offset < search_start) |
6470 | btrfs_add_free_space(used_block_group, offset, | 6467 | btrfs_add_free_space(block_group, offset, |
6471 | search_start - offset); | 6468 | search_start - offset); |
6472 | BUG_ON(offset > search_start); | 6469 | BUG_ON(offset > search_start); |
6473 | 6470 | ||
6474 | ret = btrfs_update_reserved_bytes(used_block_group, num_bytes, | 6471 | ret = btrfs_update_reserved_bytes(block_group, num_bytes, |
6475 | alloc_type); | 6472 | alloc_type); |
6476 | if (ret == -EAGAIN) { | 6473 | if (ret == -EAGAIN) { |
6477 | btrfs_add_free_space(used_block_group, offset, num_bytes); | 6474 | btrfs_add_free_space(block_group, offset, num_bytes); |
6478 | goto loop; | 6475 | goto loop; |
6479 | } | 6476 | } |
6480 | 6477 | ||
@@ -6484,16 +6481,12 @@ checks: | |||
6484 | 6481 | ||
6485 | trace_btrfs_reserve_extent(orig_root, block_group, | 6482 | trace_btrfs_reserve_extent(orig_root, block_group, |
6486 | search_start, num_bytes); | 6483 | search_start, num_bytes); |
6487 | if (used_block_group != block_group) | ||
6488 | btrfs_put_block_group(used_block_group); | ||
6489 | btrfs_put_block_group(block_group); | 6484 | btrfs_put_block_group(block_group); |
6490 | break; | 6485 | break; |
6491 | loop: | 6486 | loop: |
6492 | failed_cluster_refill = false; | 6487 | failed_cluster_refill = false; |
6493 | failed_alloc = false; | 6488 | failed_alloc = false; |
6494 | BUG_ON(index != get_block_group_index(block_group)); | 6489 | BUG_ON(index != get_block_group_index(block_group)); |
6495 | if (used_block_group != block_group) | ||
6496 | btrfs_put_block_group(used_block_group); | ||
6497 | btrfs_put_block_group(block_group); | 6490 | btrfs_put_block_group(block_group); |
6498 | } | 6491 | } |
6499 | up_read(&space_info->groups_sem); | 6492 | up_read(&space_info->groups_sem); |