Skip to content

Commit e7a0489

Browse files
osandovkdave
authored andcommitted
btrfs: fix RAID direct I/O reads with alternate csums
btrfs_lookup_and_bind_dio_csum() does pointer arithmetic which assumes 32-bit checksums. If using a larger checksum, this leads to spurious failures when a direct I/O read crosses a stripe. This is easy to reproduce: # mkfs.btrfs -f --checksum blake2 -d raid0 /dev/vdc /dev/vdd ... # mount /dev/vdc /mnt # cd /mnt # dd if=/dev/urandom of=foo bs=1M count=1 status=none # dd if=foo of=/dev/null bs=1M iflag=direct status=none dd: error reading 'foo': Input/output error # dmesg | tail -1 [ 135.821568] BTRFS warning (device vdc): csum failed root 5 ino 257 off 421888 ... Fix it by using the actual checksum size. Fixes: 1e25a2e ("btrfs: don't assume ordered sums to be 4 bytes") CC: [email protected] # 5.4+ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Omar Sandoval <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent a5ae50d commit e7a0489

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

fs/btrfs/inode.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7783,6 +7783,7 @@ static inline blk_status_t btrfs_lookup_and_bind_dio_csum(struct inode *inode,
77837783
{
77847784
struct btrfs_io_bio *io_bio = btrfs_io_bio(bio);
77857785
struct btrfs_io_bio *orig_io_bio = btrfs_io_bio(dip->orig_bio);
7786+
u16 csum_size;
77867787
blk_status_t ret;
77877788

77887789
/*
@@ -7802,7 +7803,8 @@ static inline blk_status_t btrfs_lookup_and_bind_dio_csum(struct inode *inode,
78027803

78037804
file_offset -= dip->logical_offset;
78047805
file_offset >>= inode->i_sb->s_blocksize_bits;
7805-
io_bio->csum = (u8 *)(((u32 *)orig_io_bio->csum) + file_offset);
7806+
csum_size = btrfs_super_csum_size(btrfs_sb(inode->i_sb)->super_copy);
7807+
io_bio->csum = orig_io_bio->csum + csum_size * file_offset;
78067808

78077809
return 0;
78087810
}

0 commit comments

Comments
 (0)