From d26c0b441457f4054e09ecca173431b5d824539a Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Mon, 8 Nov 2021 14:26:45 -0500 Subject: [PATCH] btrfs-progs: check: check the global roots for uptodate root nodes Instead of checking the csum and extent tree individually, walk through the global roots and validate them all. This will work properly if we have extent tree v1 or extent tree v2. Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- check/main.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/check/main.c b/check/main.c index d296aeda..f873de09 100644 --- a/check/main.c +++ b/check/main.c @@ -10392,6 +10392,23 @@ out: return ret; } +static int check_global_roots_uptodate(void) +{ + struct btrfs_root *root; + struct rb_node *n; + + for (n = rb_first(&gfs_info->global_roots_tree); n; n = rb_next(n)) { + root = rb_entry(n, struct btrfs_root, rb_node); + if (!extent_buffer_uptodate(root->node)) { + error("chritical: global root [%llu %llu] not uptodate, unable to check the file system", + root->root_key.objectid, root->root_key.offset); + return -EIO; + } + } + + return 0; +} + static const char * const cmd_check_usage[] = { "btrfs check [options] ", "Check structural integrity of a filesystem (unmounted).", @@ -10784,18 +10801,9 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) if (ret) goto close_out; } - root = btrfs_extent_root(gfs_info, 0); - if (!extent_buffer_uptodate(root->node)) { - error("critical: extent_root, unable to check the filesystem"); - ret = -EIO; - err |= !!ret; - goto close_out; - } - root = btrfs_csum_root(gfs_info, 0); - if (!extent_buffer_uptodate(root->node)) { - error("critical: csum_root, unable to check the filesystem"); - ret = -EIO; + ret = check_global_roots_uptodate(); + if (ret) { err |= !!ret; goto close_out; }