btrfs-progs: check: add block group tree support

This makes the appropriate changes to enable the block group tree
checking for both lowmem and normal check modes.  This is relatively
straightforward, simply need to use the helper to get the right root for
dealing with block groups.

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:52 -05:00 committed by David Sterba
parent 7e3bf7fc44
commit 1bbfc9c9a6
2 changed files with 22 additions and 3 deletions

View File

@ -6268,10 +6268,17 @@ static int check_type_with_root(u64 rootid, u8 key_type)
break;
case BTRFS_EXTENT_ITEM_KEY:
case BTRFS_METADATA_ITEM_KEY:
case BTRFS_BLOCK_GROUP_ITEM_KEY:
if (rootid != BTRFS_EXTENT_TREE_OBJECTID)
goto err;
break;
case BTRFS_BLOCK_GROUP_ITEM_KEY:
if (btrfs_fs_incompat(gfs_info, EXTENT_TREE_V2)) {
if (rootid != BTRFS_BLOCK_GROUP_TREE_OBJECTID)
goto err;
} else if (rootid != BTRFS_EXTENT_TREE_OBJECTID) {
goto err;
}
break;
case BTRFS_ROOT_ITEM_KEY:
if (rootid != BTRFS_ROOT_TREE_OBJECTID)
goto err;
@ -9492,6 +9499,18 @@ again:
return ret;
}
/*
* If we are extent tree v2 then we can reint the block group root as
* well.
*/
if (btrfs_fs_incompat(gfs_info, EXTENT_TREE_V2)) {
ret = btrfs_fsck_reinit_root(trans, gfs_info->block_group_root);
if (ret) {
fprintf(stderr, "block group initialization failed\n");
return ret;
}
}
/*
* Now we have all the in-memory block groups setup so we can make
* allocations properly, and the metadata we care about is safe since we

View File

@ -5540,7 +5540,7 @@ int check_chunks_and_extents_lowmem(void)
key.offset = 0;
key.type = BTRFS_ROOT_ITEM_KEY;
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
ret = btrfs_search_slot(NULL, gfs_info->tree_root, &key, &path, 0, 0);
if (ret) {
error("cannot find extent tree in tree_root");
goto out;
@ -5575,7 +5575,7 @@ int check_chunks_and_extents_lowmem(void)
if (ret)
goto out;
next:
ret = btrfs_next_item(root, &path);
ret = btrfs_next_item(gfs_info->tree_root, &path);
if (ret)
goto out;
}