Commit 265d4ac0 authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: sink parameter start and len to check_data_csum

For check_data_csum(), the page we're using is directly from the inode
mapping, thus it has valid page_offset().

We can use (page_offset() + pg_off) to replace @start parameter
completely, while the @len should always be sectorsize.

Since we're here, also add some comment, as there are quite some
confusion in words like start/offset, without explaining whether it's
file_offset or logical bytenr.

This should not affect the existing behavior, as for current sectorsize
== PAGE_SIZE case, @pgoff should always be 0, and len is always
PAGE_SIZE (or sectorsize from the dio read path).
Reviewed-by: default avatarGoldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8896a08d
...@@ -2889,17 +2889,29 @@ void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start, ...@@ -2889,17 +2889,29 @@ void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
btrfs_queue_work(wq, &ordered_extent->work); btrfs_queue_work(wq, &ordered_extent->work);
} }
/*
* check_data_csum - verify checksum of one sector of uncompressed data
* @inode: the inode
* @io_bio: btrfs_io_bio which contains the csum
* @icsum: checksum index in the io_bio->csum array, size of csum_size
* @page: page where is the data to be verified
* @pgoff: offset inside the page
*
* The length of such check is always one sector size.
*/
static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio,
int icsum, struct page *page, int pgoff, u64 start, int icsum, struct page *page, int pgoff)
size_t len)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
char *kaddr; char *kaddr;
u32 len = fs_info->sectorsize;
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy); u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
u8 *csum_expected; u8 *csum_expected;
u8 csum[BTRFS_CSUM_SIZE]; u8 csum[BTRFS_CSUM_SIZE];
ASSERT(pgoff + len <= PAGE_SIZE);
csum_expected = ((u8 *)io_bio->csum) + icsum * csum_size; csum_expected = ((u8 *)io_bio->csum) + icsum * csum_size;
kaddr = kmap_atomic(page); kaddr = kmap_atomic(page);
...@@ -2913,8 +2925,8 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio, ...@@ -2913,8 +2925,8 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio,
kunmap_atomic(kaddr); kunmap_atomic(kaddr);
return 0; return 0;
zeroit: zeroit:
btrfs_print_data_csum_error(BTRFS_I(inode), start, csum, csum_expected, btrfs_print_data_csum_error(BTRFS_I(inode), page_offset(page) + pgoff,
io_bio->mirror_num); csum, csum_expected, io_bio->mirror_num);
if (io_bio->device) if (io_bio->device)
btrfs_dev_stat_inc_and_print(io_bio->device, btrfs_dev_stat_inc_and_print(io_bio->device,
BTRFS_DEV_STAT_CORRUPTION_ERRS); BTRFS_DEV_STAT_CORRUPTION_ERRS);
...@@ -2955,8 +2967,7 @@ int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset, ...@@ -2955,8 +2967,7 @@ int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
} }
phy_offset >>= inode->i_sb->s_blocksize_bits; phy_offset >>= inode->i_sb->s_blocksize_bits;
return check_data_csum(inode, io_bio, phy_offset, page, offset, start, return check_data_csum(inode, io_bio, phy_offset, page, offset);
(size_t)(end - start + 1));
} }
/* /*
...@@ -7674,8 +7685,7 @@ static blk_status_t btrfs_check_read_dio_bio(struct inode *inode, ...@@ -7674,8 +7685,7 @@ static blk_status_t btrfs_check_read_dio_bio(struct inode *inode,
ASSERT(pgoff < PAGE_SIZE); ASSERT(pgoff < PAGE_SIZE);
if (uptodate && if (uptodate &&
(!csum || !check_data_csum(inode, io_bio, icsum, (!csum || !check_data_csum(inode, io_bio, icsum,
bvec.bv_page, pgoff, bvec.bv_page, pgoff))) {
start, sectorsize))) {
clean_io_failure(fs_info, failure_tree, io_tree, clean_io_failure(fs_info, failure_tree, io_tree,
start, bvec.bv_page, start, bvec.bv_page,
btrfs_ino(BTRFS_I(inode)), btrfs_ino(BTRFS_I(inode)),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment