btrfs-progs: check: verify critical root pointers before use

The pointers to critical roots must be valid before we start using them,
eg. as the space clearing code.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2017-08-30 19:25:11 +02:00
parent f03b293fdf
commit 04f480bc01

View file

@ -12903,6 +12903,22 @@ int cmd_check(int argc, char **argv)
global_info = info;
root = info->fs_root;
uuid_unparse(info->super_copy->fsid, uuidbuf);
printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);
/*
* Check the bare minimum before starting anything else that could rely
* on it, namely the tree roots, any local consistency checks
*/
if (!extent_buffer_uptodate(info->tree_root->node) ||
!extent_buffer_uptodate(info->dev_root->node) ||
!extent_buffer_uptodate(info->chunk_root->node)) {
error("critical roots corrupted, unable to check the filesystem");
err |= !!ret;
ret = -EIO;
goto close_out;
}
if (clear_space_cache) {
ret = do_clear_free_space_cache(info, clear_space_cache);
@ -12929,7 +12945,6 @@ int cmd_check(int argc, char **argv)
}
}
uuid_unparse(info->super_copy->fsid, uuidbuf);
if (qgroup_report) {
printf("Print quota groups for %s\nUUID: %s\n", argv[optind],
uuidbuf);
@ -12946,16 +12961,6 @@ int cmd_check(int argc, char **argv)
err |= !!ret;
goto close_out;
}
printf("Checking filesystem on %s\nUUID: %s\n", argv[optind], uuidbuf);
if (!extent_buffer_uptodate(info->tree_root->node) ||
!extent_buffer_uptodate(info->dev_root->node) ||
!extent_buffer_uptodate(info->chunk_root->node)) {
error("critical roots corrupted, unable to check the filesystem");
err |= !!ret;
ret = -EIO;
goto close_out;
}
if (init_extent_tree || init_csum_tree) {
struct btrfs_trans_handle *trans;