From: David Sterba Date: Wed, 30 Aug 2017 17:25:11 +0000 (+0200) Subject: btrfs-progs: check: verify critical root pointers before use X-Git-Tag: upstream/4.16.1~471 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04f480bc01dcce0efb7a987e3646b27c7b875403;p=platform%2Fupstream%2Fbtrfs-progs.git 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 --- diff --git a/cmds-check.c b/cmds-check.c index f318404..cbf1dce 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -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;