[PATCH 7/8] btrfs: Increment corrupt device counter during compressed read

Nikolay Borisov
2020-07-02T12:44:07Z

If a compressed read fails due to csum error only a line is printed to
dmesg, device corrupt counter is not modified.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
fs/btrfs/compression.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index db80c3fa6c08..2f30bf4127f8 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -172,8 +172,7 @@ static inline int compressed_bio_size(struct btrfs_fs_info *fs_info,
(DIV_ROUND_UP(disk_size, fs_info->sectorsize)) * csum_size;
}

-static int check_compressed_csum(struct btrfs_inode *inode,
- struct compressed_bio *cb,
+static int check_compressed_csum(struct btrfs_inode *inode, struct bio *bio,
u64 disk_start)
{
struct btrfs_fs_info *fs_info = inode->root->fs_info;
@@ -184,6 +183,7 @@ static int check_compressed_csum(struct btrfs_inode *inode,
unsigned long i;
char *kaddr;
u8 csum[BTRFS_CSUM_SIZE];
+ struct compressed_bio *cb = bio->bi_private;
u8 *cb_sum = cb->sums;

if (inode->flags & BTRFS_INODE_NODATASUM)
@@ -201,6 +201,9 @@ static int check_compressed_csum(struct btrfs_inode *inode,
if (memcmp(&csum, cb_sum, csum_size)) {
btrfs_print_data_csum_error(inode, disk_start,
csum, cb_sum, cb->mirror_num);
+ if (btrfs_io_bio(bio)->dev)
+ btrfs_dev_stat_inc_and_print(btrfs_io_bio(bio)->dev,
+ BTRFS_DEV_STAT_CORRUPTION_ERRS);
ret = -EIO;
goto fail;
}
@@ -255,7 +258,7 @@ static void end_compressed_bio_read(struct bio *bio)
goto csum_failed;

inode = cb->inode;
- ret = check_compressed_csum(BTRFS_I(inode), cb,
+ ret = check_compressed_csum(BTRFS_I(inode), bio,
(u64)bio->bi_iter.bi_sector << 9);
if (ret)
goto csum_failed;
--
2.17.1