From c36d8ea235fc6e21ee552376100f945c13cdf50a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Mon, 7 Mar 2022 17:10:56 -0500 Subject: [PATCH] btrfs-progs: check: handle the block group tree properly We need to make sure we process the block group root, and mark its blocks as used for the free space tree checking. Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- check/main.c | 27 +++++++++++++++++---------- common/repair.c | 3 +++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/check/main.c b/check/main.c index 6ee3250e..94c44e59 100644 --- a/check/main.c +++ b/check/main.c @@ -8947,6 +8947,18 @@ out: return ret; } +static int load_super_root(struct list_head *head, struct btrfs_root *root) +{ + u8 level; + + if (!root) + return 0; + + level = btrfs_header_level(root->node); + return add_root_item_to_list(head, root->root_key.objectid, + root->node->start, 0, level, 0, NULL); +} + static int check_chunks_and_extents(void) { struct rb_root dev_cache; @@ -8965,9 +8977,7 @@ static int check_chunks_and_extents(void) int bits_nr; struct list_head dropping_trees; struct list_head normal_trees; - struct btrfs_root *root1; struct btrfs_root *root; - u8 level; root = gfs_info->fs_root; dev_cache = RB_ROOT; @@ -9000,16 +9010,13 @@ static int check_chunks_and_extents(void) } again: - root1 = gfs_info->tree_root; - level = btrfs_header_level(root1->node); - ret = add_root_item_to_list(&normal_trees, root1->root_key.objectid, - root1->node->start, 0, level, 0, NULL); + ret = load_super_root(&normal_trees, gfs_info->tree_root); if (ret < 0) goto out; - root1 = gfs_info->chunk_root; - level = btrfs_header_level(root1->node); - ret = add_root_item_to_list(&normal_trees, root1->root_key.objectid, - root1->node->start, 0, level, 0, NULL); + ret = load_super_root(&normal_trees, gfs_info->chunk_root); + if (ret < 0) + goto out; + ret = load_super_root(&normal_trees, gfs_info->block_group_root); if (ret < 0) goto out; diff --git a/common/repair.c b/common/repair.c index a1ee05c6..859024c3 100644 --- a/common/repair.c +++ b/common/repair.c @@ -149,6 +149,9 @@ int btrfs_mark_used_tree_blocks(struct btrfs_fs_info *fs_info, ret = traverse_tree_blocks(tree, fs_info->chunk_root->node, 0); if (!ret) ret = traverse_tree_blocks(tree, fs_info->tree_root->node, 1); + if (!ret && fs_info->block_group_root) + ret = traverse_tree_blocks(tree, + fs_info->block_group_root->node, 0); return ret; }