Commit 5d8eb6fe authored by Naohiro Aota's avatar Naohiro Aota Committed by David Sterba

btrfs: let btrfs_delete_unused_bgs() to clean relocated bgs

Currently, btrfs_relocate_chunk() is removing relocated BG by itself. But
the work can be done by btrfs_delete_unused_bgs() (and it's better since it
trim the BG). Let's dedupe the code.

While btrfs_delete_unused_bgs() is already hitting the relocated BG, it
skip the BG since the BG has "ro" flag set (to keep balancing BG intact).
On the other hand, btrfs cannot drop "ro" flag here to prevent additional
writes. So this patch make use of "removed" flag.
btrfs_delete_unused_bgs() now detect the flag to distinguish whether a
read-only BG is relocating or not.
Signed-off-by: default avatarNaohiro Aota <naohiro.aota@hgst.com>
Reviewed-by: default avatarJosef Bacik <jbacik@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 49303381
...@@ -10833,7 +10833,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) ...@@ -10833,7 +10833,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
if (block_group->reserved || if (block_group->reserved ||
btrfs_block_group_used(&block_group->item) || btrfs_block_group_used(&block_group->item) ||
block_group->ro || (block_group->ro && !block_group->removed) ||
list_is_singular(&block_group->list)) { list_is_singular(&block_group->list)) {
/* /*
* We want to bail if we made new allocations or have * We want to bail if we made new allocations or have
......
...@@ -2908,8 +2908,8 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, ...@@ -2908,8 +2908,8 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
{ {
struct btrfs_root *extent_root; struct btrfs_root *extent_root;
struct btrfs_trans_handle *trans;
int ret; int ret;
struct btrfs_block_group_cache *block_group;
root = root->fs_info->chunk_root; root = root->fs_info->chunk_root;
extent_root = root->fs_info->extent_root; extent_root = root->fs_info->extent_root;
...@@ -2939,21 +2939,17 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset) ...@@ -2939,21 +2939,17 @@ static int btrfs_relocate_chunk(struct btrfs_root *root, u64 chunk_offset)
if (ret) if (ret)
return ret; return ret;
trans = btrfs_start_trans_remove_block_group(root->fs_info,
chunk_offset);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
btrfs_handle_fs_error(root->fs_info, ret, NULL);
return ret;
}
/* /*
* step two, delete the device extents and the * step two, flag the chunk as removed and let
* chunk tree entries * btrfs_delete_unused_bgs() remove it.
*/ */
ret = btrfs_remove_chunk(trans, root, chunk_offset); block_group = btrfs_lookup_block_group(root->fs_info, chunk_offset);
btrfs_end_transaction(trans, extent_root); spin_lock(&block_group->lock);
return ret; block_group->removed = 1;
spin_unlock(&block_group->lock);
btrfs_put_block_group(block_group);
return 0;
} }
static int btrfs_relocate_sys_chunks(struct btrfs_root *root) static int btrfs_relocate_sys_chunks(struct btrfs_root *root)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment