btrfs-progs: handle no bg item in extent tree for free space tree

We have an ASSERT(ret == 0) when populating the free space tree as we
should at least find the block group item with extent tree v1.  However
with v2 we no longer have the block group item in the extent tree, so
fix the population logic to handle an empty block group (which occurs
during mkfs) and only assert if ret != 0 and we don't have extent tree
v2 turned on.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2022-03-07 17:10:50 -05:00 committed by David Sterba
parent 9f1f88c642
commit c7a8363276
1 changed files with 8 additions and 3 deletions

View File

@ -1057,6 +1057,9 @@ int populate_free_space_tree(struct btrfs_trans_handle *trans,
if (ret)
goto out;
start = block_group->start;
end = block_group->start + block_group->length;
/*
* Iterate through all of the extent and metadata items in this block
* group, adding the free space between them and the free space at the
@ -1071,10 +1074,11 @@ int populate_free_space_tree(struct btrfs_trans_handle *trans,
ret = btrfs_search_slot_for_read(extent_root, &key, path, 1, 0);
if (ret < 0)
goto out;
ASSERT(ret == 0);
if (ret > 0) {
ASSERT(btrfs_fs_incompat(trans->fs_info, EXTENT_TREE_V2));
goto done;
}
start = block_group->start;
end = block_group->start + block_group->length;
while (1) {
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
@ -1106,6 +1110,7 @@ int populate_free_space_tree(struct btrfs_trans_handle *trans,
if (ret)
break;
}
done:
if (start < end) {
ret = __add_to_free_space_tree(trans, block_group, path2,
start, end - start);