summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2017-08-30 19:25:11 +0200
committerDavid Sterba <dsterba@suse.com>2017-09-08 16:15:05 +0200
commit04f480bc01dcce0efb7a987e3646b27c7b875403 (patch)
tree6e25416782901457e44138ff57bbded0a7ea0ad7
parentf03b293fdf18d257a68e4e55122064960fddbf11 (diff)
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>
-rw-r--r--cmds-check.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/cmds-check.c b/cmds-check.c
index f3184043..cbf1dcec 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;