From bb575e3818fdb1762d5176e66be451c4aef32b72 Mon Sep 17 00:00:00 2001 From: Josef Bacik Date: Mon, 8 Nov 2021 14:26:46 -0500 Subject: [PATCH] btrfs-progs: check: check all of the csum roots Use the global roots tree to find all of the csum roots in the system and check all of them as appropriate. Signed-off-by: Josef Bacik Signed-off-by: David Sterba --- check/main.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/check/main.c b/check/main.c index f873de09..337ab82f 100644 --- a/check/main.c +++ b/check/main.c @@ -5977,7 +5977,7 @@ out: return ret; } -static int check_csums(struct btrfs_root *root) +static int check_csum_root(struct btrfs_root *root) { struct btrfs_path path; struct extent_buffer *leaf; @@ -5995,7 +5995,6 @@ static int check_csums(struct btrfs_root *root) max_entries = ((BTRFS_LEAF_DATA_SIZE(gfs_info) - (sizeof(struct btrfs_item) * 2)) / csum_size) - 1; - root = btrfs_csum_root(gfs_info, 0); if (!extent_buffer_uptodate(root->node)) { fprintf(stderr, "No valid csum tree found\n"); return -ENOENT; @@ -6100,6 +6099,27 @@ skip_csum_check: return errors; } +static int check_csums(void) +{ + struct rb_node *n; + struct btrfs_root *root; + int ret; + + root = btrfs_csum_root(gfs_info, 0); + while (1) { + ret = check_csum_root(root); + if (ret) + break; + n = rb_next(&root->rb_node); + if (!n) + break; + root = rb_entry(n, struct btrfs_root, rb_node); + if (root->root_key.objectid != BTRFS_CSUM_TREE_OBJECTID) + break; + } + return ret; +} + static int is_dropped_key(struct btrfs_key *key, struct btrfs_key *drop_key) { @@ -10912,7 +10932,7 @@ static int cmd_check(const struct cmd_struct *cmd, int argc, char **argv) task_start(ctx.info, &ctx.start_time, &ctx.item_count); } - ret = check_csums(root); + ret = check_csums(); task_stop(ctx.info); /* * Data csum error is not fatal, and it may indicate more serious