btrfs: Better csum error message for data csum mismatch
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Thu, 9 Feb 2017 02:45:06 +0000 (10:45 +0800)
committerDavid Sterba <dsterba@suse.com>
Fri, 17 Feb 2017 11:03:48 +0000 (12:03 +0100)
The original csum error message only outputs inode number, offset, check
sum and expected check sum.

However no root objectid is outputted, which sometimes makes debugging
quite painful under multi-subvolume case (including relocation).

Also the checksum output is decimal, which seldom makes sense for
users/developers and is hard to read in most time.

This patch will add root objectid, which will be %lld for rootid larger
than LAST_FREE_OBJECTID, and hex csum output for better readability.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/btrfs_inode.h
fs/btrfs/compression.c
fs/btrfs/inode.c

index b2dde0efebc03418987873fc9c7532afae74ecce..819a6d27218a902c6149ae73576afb90fe31b467 100644 (file)
@@ -324,6 +324,24 @@ static inline void btrfs_inode_resume_unlocked_dio(struct inode *inode)
                  &BTRFS_I(inode)->runtime_flags);
 }
 
+static inline void btrfs_print_data_csum_error(struct inode *inode,
+               u64 logical_start, u32 csum, u32 csum_expected, int mirror_num)
+{
+       struct btrfs_root *root = BTRFS_I(inode)->root;
+
+       /* Output minus objectid, which is more meaningful */
+       if (root->objectid >= BTRFS_LAST_FREE_OBJECTID)
+               btrfs_warn_rl(root->fs_info,
+       "csum failed root %lld ino %lld off %llu csum 0x%08x expected csum 0x%08x mirror %d",
+                       root->objectid, btrfs_ino(BTRFS_I(inode)),
+                       logical_start, csum, csum_expected, mirror_num);
+       else
+               btrfs_warn_rl(root->fs_info,
+       "csum failed root %llu ino %llu off %llu csum 0x%08x expected csum 0x%08x mirror %d",
+                       root->objectid, btrfs_ino(BTRFS_I(inode)),
+                       logical_start, csum, csum_expected, mirror_num);
+}
+
 bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end);
 
 #endif
index 4547112406498688dfb2d06dcc75b58d6d88edc3..903c32c9eb22214f10d6dbdadb64f6b698e2bf66 100644 (file)
@@ -124,10 +124,8 @@ static int check_compressed_csum(struct inode *inode,
                kunmap_atomic(kaddr);
 
                if (csum != *cb_sum) {
-                       btrfs_info(BTRFS_I(inode)->root->fs_info,
-                          "csum failed ino %llu extent %llu csum %u wanted %u mirror %d",
-                          btrfs_ino(BTRFS_I(inode)), disk_start, csum, *cb_sum,
-                          cb->mirror_num);
+                       btrfs_print_data_csum_error(inode, disk_start, csum,
+                                                   *cb_sum, cb->mirror_num);
                        ret = -EIO;
                        goto fail;
                }
index 92416f3ea9a851f1dff0fdc24867d5e2b92ea075..175c28a94a576a2cf573d81604e28766f907c2fa 100644 (file)
@@ -3086,9 +3086,8 @@ static int __readpage_endio_check(struct inode *inode,
        kunmap_atomic(kaddr);
        return 0;
 zeroit:
-       btrfs_warn_rl(BTRFS_I(inode)->root->fs_info,
-               "csum failed ino %llu off %llu csum %u expected csum %u",
-                  btrfs_ino(BTRFS_I(inode)), start, csum, csum_expected);
+       btrfs_print_data_csum_error(inode, start, csum, csum_expected,
+                                   io_bio->mirror_num);
        memset(kaddr + pgoff, 1, len);
        flush_dcache_page(page);
        kunmap_atomic(kaddr);