btrfs-progs: Add support to suppress tree block csum error output
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 16 Jan 2015 03:04:09 +0000 (11:04 +0800)
committerDavid Sterba <dsterba@suse.cz>
Wed, 11 Feb 2015 16:14:05 +0000 (17:14 +0100)
Add new open ctree flag OPEN_CTREE_SUPPRESS_CHECK_BLOCK_ERRORS to
suppress tree block csum error output.

Provides the basis for new btrfs-find-root and other enhancement on
btrfs offline tools output.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[renamed vars and funcs, added comments]
Signed-off-by: David Sterba <dsterba@suse.cz>
ctree.h
disk-io.c
disk-io.h

diff --git a/ctree.h b/ctree.h
index f4275d9..901c340 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -998,6 +998,7 @@ struct btrfs_fs_info {
        unsigned int on_restoring:1;
        unsigned int is_chunk_recover:1;
        unsigned int quota_enabled:1;
+       unsigned int suppress_check_block_errors:1;
 
        int (*free_extent_hook)(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
@@ -1006,6 +1007,7 @@ struct btrfs_fs_info {
                                int refs_to_drop);
        struct cache_tree *fsck_extent_cache;
        struct cache_tree *corrupt_blocks;
+
 };
 
 /*
index f418d4e..6c1961e 100644 (file)
--- a/disk-io.c
+++ b/disk-io.c
@@ -60,7 +60,7 @@ static int check_tree_block(struct btrfs_root *root, struct extent_buffer *buf)
        return ret;
 }
 
-static void print_tree_block_err(struct btrfs_root *root,
+static void print_tree_block_error(struct btrfs_root *root,
                                struct extent_buffer *eb,
                                int err)
 {
@@ -141,6 +141,8 @@ int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
 {
        u16 csum_size =
                btrfs_super_csum_size(root->fs_info->super_copy);
+       if (verify && root->fs_info->suppress_check_block_errors)
+               return verify_tree_block_csum_silent(buf, csum_size);
        return csum_tree_block_size(buf, csum_size, verify);
 }
 
@@ -291,8 +293,8 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
 
        while (1) {
                ret = read_whole_eb(root->fs_info, eb, mirror_num);
-               if (ret == 0 && check_tree_block(root, eb) == 0 &&
-                   csum_tree_block(root, eb, 1) == 0 &&
+               if (ret == 0 && csum_tree_block(root, eb, 1) == 0 &&
+                   check_tree_block(root, eb) == 0 &&
                    verify_parent_transid(eb->tree, eb, parent_transid, ignore)
                    == 0) {
                        if (eb->flags & EXTENT_BAD_TRANSID &&
@@ -305,11 +307,14 @@ struct extent_buffer *read_tree_block(struct btrfs_root *root, u64 bytenr,
                        return eb;
                }
                if (ignore) {
-                       if (check_tree_block(root, eb))
-                               print_tree_block_err(root, eb,
+                       if (check_tree_block(root, eb)) {
+                               if (!root->fs_info->suppress_check_block_errors)
+                                       print_tree_block_error(root, eb,
                                                check_tree_block(root, eb));
-                       else
-                               printk("Csum didn't match\n");
+                       } else {
+                               if (!root->fs_info->suppress_check_block_errors)
+                                       fprintf(stderr, "Csum didn't match\n");
+                       }
                        ret = -EIO;
                        break;
                }
@@ -371,7 +376,7 @@ static int write_tree_block(struct btrfs_trans_handle *trans,
                     struct extent_buffer *eb)
 {
        if (check_tree_block(root, eb)) {
-               print_tree_block_err(root, eb, check_tree_block(root, eb));
+               print_tree_block_error(root, eb, check_tree_block(root, eb));
                BUG();
        }
 
@@ -1142,6 +1147,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
        }
        if (flags & OPEN_CTREE_RESTORE)
                fs_info->on_restoring = 1;
+       if (flags & OPEN_CTREE_SUPPRESS_CHECK_BLOCK_ERRORS)
+               fs_info->suppress_check_block_errors = 1;
 
        ret = btrfs_scan_fs_devices(fp, path, &fs_devices, sb_bytenr,
                                    (flags & OPEN_CTREE_RECOVER_SUPER),
index 53df8f0..a69a62f 100644 (file)
--- a/disk-io.h
+++ b/disk-io.h
@@ -34,6 +34,11 @@ enum btrfs_open_ctree_flags {
        OPEN_CTREE_NO_BLOCK_GROUPS      = (1 << 5),
        OPEN_CTREE_EXCLUSIVE            = (1 << 6),
        OPEN_CTREE_NO_DEVICES           = (1 << 7),
+       /*
+        * Don't print error messages if bytenr or checksums do not match in
+        * tree block headers. Turn on by OPEN_CTREE_SUPPRESS_ERROR
+        */
+       OPEN_CTREE_SUPPRESS_CHECK_BLOCK_ERRORS  = (1 << 8)
 };
 
 static inline u64 btrfs_sb_offset(int mirror)