Skip to content

Commit 7357623

Browse files
adam900710kdave
authored andcommitted
btrfs: block-group: refactor how we delete one block group item
When deleting a block group item, it's pretty straight forward, just delete the item pointed by the key. However it will not be that straight-forward for incoming skinny block group item. So refactor the block group item deletion into a new function, remove_block_group_item(), also to make the already lengthy btrfs_remove_block_group() a little shorter. Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9afc664 commit 7357623

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

fs/btrfs/block-group.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,34 @@ static void clear_incompat_bg_bits(struct btrfs_fs_info *fs_info, u64 flags)
865865
}
866866
}
867867

868+
static int remove_block_group_item(struct btrfs_trans_handle *trans,
869+
struct btrfs_path *path,
870+
struct btrfs_block_group *block_group)
871+
{
872+
struct btrfs_fs_info *fs_info = trans->fs_info;
873+
struct btrfs_root *root;
874+
struct btrfs_key key;
875+
int ret;
876+
877+
root = fs_info->extent_root;
878+
key.objectid = block_group->start;
879+
key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
880+
key.offset = block_group->length;
881+
882+
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
883+
if (ret > 0)
884+
ret = -ENOENT;
885+
if (ret < 0)
886+
return ret;
887+
888+
ret = btrfs_del_item(trans, root, path);
889+
return ret;
890+
}
891+
868892
int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
869893
u64 group_start, struct extent_map *em)
870894
{
871895
struct btrfs_fs_info *fs_info = trans->fs_info;
872-
struct btrfs_root *root = fs_info->extent_root;
873896
struct btrfs_path *path;
874897
struct btrfs_block_group *block_group;
875898
struct btrfs_free_cluster *cluster;
@@ -1067,10 +1090,6 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
10671090

10681091
spin_unlock(&block_group->space_info->lock);
10691092

1070-
key.objectid = block_group->start;
1071-
key.type = BTRFS_BLOCK_GROUP_ITEM_KEY;
1072-
key.offset = block_group->length;
1073-
10741093
mutex_lock(&fs_info->chunk_mutex);
10751094
spin_lock(&block_group->lock);
10761095
block_group->removed = 1;
@@ -1112,16 +1131,10 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
11121131
/* Once for the block groups rbtree */
11131132
btrfs_put_block_group(block_group);
11141133

1115-
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
1116-
if (ret > 0)
1117-
ret = -EIO;
1134+
ret = remove_block_group_item(trans, path, block_group);
11181135
if (ret < 0)
11191136
goto out;
11201137

1121-
ret = btrfs_del_item(trans, root, path);
1122-
if (ret)
1123-
goto out;
1124-
11251138
if (remove_em) {
11261139
struct extent_map_tree *em_tree;
11271140

0 commit comments

Comments
 (0)