btrfs-progs: check: verify critical root pointers before use
authorDavid Sterba <dsterba@suse.com>
Wed, 30 Aug 2017 17:25:11 +0000 (19:25 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 8 Sep 2017 14:15:05 +0000 (16:15 +0200)
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>
cmds-check.c

index f318404..cbf1dce 100644 (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;