mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 06:10:56 +00:00
btrfs: factor out a btrfs_csum_ptr helper
Add a helper to find the csum for a byte offset into the csum buffer. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
97861cd166
commit
a89ce08ce6
2 changed files with 11 additions and 10 deletions
|
@ -2733,6 +2733,14 @@ int btrfs_get_extent_inline_ref_type(const struct extent_buffer *eb,
|
||||||
enum btrfs_inline_ref_type is_data);
|
enum btrfs_inline_ref_type is_data);
|
||||||
u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
|
u64 hash_extent_data_ref(u64 root_objectid, u64 owner, u64 offset);
|
||||||
|
|
||||||
|
static inline u8 *btrfs_csum_ptr(const struct btrfs_fs_info *fs_info, u8 *csums,
|
||||||
|
u64 offset)
|
||||||
|
{
|
||||||
|
u64 offset_in_sectors = offset >> fs_info->sectorsize_bits;
|
||||||
|
|
||||||
|
return csums + offset_in_sectors * fs_info->csum_size;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Take the number of bytes to be checksummed and figure out how many leaves
|
* Take the number of bytes to be checksummed and figure out how many leaves
|
||||||
* it would require to store the csums for that many bytes.
|
* it would require to store the csums for that many bytes.
|
||||||
|
|
|
@ -3371,15 +3371,12 @@ static int check_data_csum(struct inode *inode, struct btrfs_bio *bbio,
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
|
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
|
||||||
u32 len = fs_info->sectorsize;
|
u32 len = fs_info->sectorsize;
|
||||||
const u32 csum_size = fs_info->csum_size;
|
|
||||||
unsigned int offset_sectors;
|
|
||||||
u8 *csum_expected;
|
u8 *csum_expected;
|
||||||
u8 csum[BTRFS_CSUM_SIZE];
|
u8 csum[BTRFS_CSUM_SIZE];
|
||||||
|
|
||||||
ASSERT(pgoff + len <= PAGE_SIZE);
|
ASSERT(pgoff + len <= PAGE_SIZE);
|
||||||
|
|
||||||
offset_sectors = bio_offset >> fs_info->sectorsize_bits;
|
csum_expected = btrfs_csum_ptr(fs_info, bbio->csum, bio_offset);
|
||||||
csum_expected = ((u8 *)bbio->csum) + offset_sectors * csum_size;
|
|
||||||
|
|
||||||
if (btrfs_check_sector_csum(fs_info, page, pgoff, csum, csum_expected))
|
if (btrfs_check_sector_csum(fs_info, page, pgoff, csum, csum_expected))
|
||||||
goto zeroit;
|
goto zeroit;
|
||||||
|
@ -8020,12 +8017,8 @@ static inline blk_status_t btrfs_submit_dio_bio(struct bio *bio,
|
||||||
if (ret)
|
if (ret)
|
||||||
goto err;
|
goto err;
|
||||||
} else {
|
} else {
|
||||||
u64 csum_offset;
|
btrfs_bio(bio)->csum = btrfs_csum_ptr(fs_info, dip->csums,
|
||||||
|
file_offset - dip->file_offset);
|
||||||
csum_offset = file_offset - dip->file_offset;
|
|
||||||
csum_offset >>= fs_info->sectorsize_bits;
|
|
||||||
csum_offset *= fs_info->csum_size;
|
|
||||||
btrfs_bio(bio)->csum = dip->csums + csum_offset;
|
|
||||||
}
|
}
|
||||||
map:
|
map:
|
||||||
ret = btrfs_map_bio(fs_info, bio, 0);
|
ret = btrfs_map_bio(fs_info, bio, 0);
|
||||||
|
|
Loading…
Reference in a new issue