[PATCH v4 08/22] btrfs-progs: handle no bg item in extent tree for free space tree
From: Josef Bacik <josef@toxicpanda.com>
Date: 2021-12-15 20:00:06
Subsystem:
the rest · Maintainer:
Linus Torvalds
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> --- kernel-shared/free-space-tree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/kernel-shared/free-space-tree.c b/kernel-shared/free-space-tree.c
index 0fdf5004..896bd3a2 100644
--- a/kernel-shared/free-space-tree.c
+++ b/kernel-shared/free-space-tree.c@@ -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);
--
2.26.3