Skip to content

Commit 265d4ac

Browse files
adam900710kdave
authored andcommitted
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: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8896a08 commit 265d4ac

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

fs/btrfs/inode.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,17 +2889,29 @@ void btrfs_writepage_endio_finish_ordered(struct page *page, u64 start,
28892889
btrfs_queue_work(wq, &ordered_extent->work);
28902890
}
28912891

2892+
/*
2893+
* check_data_csum - verify checksum of one sector of uncompressed data
2894+
* @inode: the inode
2895+
* @io_bio: btrfs_io_bio which contains the csum
2896+
* @icsum: checksum index in the io_bio->csum array, size of csum_size
2897+
* @page: page where is the data to be verified
2898+
* @pgoff: offset inside the page
2899+
*
2900+
* The length of such check is always one sector size.
2901+
*/
28922902
static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio,
2893-
int icsum, struct page *page, int pgoff, u64 start,
2894-
size_t len)
2903+
int icsum, struct page *page, int pgoff)
28952904
{
28962905
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
28972906
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
28982907
char *kaddr;
2908+
u32 len = fs_info->sectorsize;
28992909
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
29002910
u8 *csum_expected;
29012911
u8 csum[BTRFS_CSUM_SIZE];
29022912

2913+
ASSERT(pgoff + len <= PAGE_SIZE);
2914+
29032915
csum_expected = ((u8 *)io_bio->csum) + icsum * csum_size;
29042916

29052917
kaddr = kmap_atomic(page);
@@ -2913,8 +2925,8 @@ static int check_data_csum(struct inode *inode, struct btrfs_io_bio *io_bio,
29132925
kunmap_atomic(kaddr);
29142926
return 0;
29152927
zeroit:
2916-
btrfs_print_data_csum_error(BTRFS_I(inode), start, csum, csum_expected,
2917-
io_bio->mirror_num);
2928+
btrfs_print_data_csum_error(BTRFS_I(inode), page_offset(page) + pgoff,
2929+
csum, csum_expected, io_bio->mirror_num);
29182930
if (io_bio->device)
29192931
btrfs_dev_stat_inc_and_print(io_bio->device,
29202932
BTRFS_DEV_STAT_CORRUPTION_ERRS);
@@ -2955,8 +2967,7 @@ int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u64 phy_offset,
29552967
}
29562968

29572969
phy_offset >>= inode->i_sb->s_blocksize_bits;
2958-
return check_data_csum(inode, io_bio, phy_offset, page, offset, start,
2959-
(size_t)(end - start + 1));
2970+
return check_data_csum(inode, io_bio, phy_offset, page, offset);
29602971
}
29612972

29622973
/*
@@ -7674,8 +7685,7 @@ static blk_status_t btrfs_check_read_dio_bio(struct inode *inode,
76747685
ASSERT(pgoff < PAGE_SIZE);
76757686
if (uptodate &&
76767687
(!csum || !check_data_csum(inode, io_bio, icsum,
7677-
bvec.bv_page, pgoff,
7678-
start, sectorsize))) {
7688+
bvec.bv_page, pgoff))) {
76797689
clean_io_failure(fs_info, failure_tree, io_tree,
76807690
start, bvec.bv_page,
76817691
btrfs_ino(BTRFS_I(inode)),

0 commit comments

Comments
 (0)