Commit e2eb0248 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: cleanup the main loop in btrfs_lookup_bio_sums

Introduce a bio_offset variable for the current offset into the bio
instead of recalculating it over and over.   Remove the now only used
once search_len and sector_offset variables, and reduce the scope for
count and cur_disk_bytenr.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 65886d2b
...@@ -350,10 +350,9 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) ...@@ -350,10 +350,9 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
const u32 csum_size = fs_info->csum_size; const u32 csum_size = fs_info->csum_size;
u32 orig_len = bio->bi_iter.bi_size; u32 orig_len = bio->bi_iter.bi_size;
u64 orig_disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT; u64 orig_disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
u64 cur_disk_bytenr;
const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits; const unsigned int nblocks = orig_len >> fs_info->sectorsize_bits;
int count = 0;
blk_status_t ret = BLK_STS_OK; blk_status_t ret = BLK_STS_OK;
u32 bio_offset = 0;
if ((inode->flags & BTRFS_INODE_NODATASUM) || if ((inode->flags & BTRFS_INODE_NODATASUM) ||
test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state)) test_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state))
...@@ -404,28 +403,14 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) ...@@ -404,28 +403,14 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
path->skip_locking = 1; path->skip_locking = 1;
} }
for (cur_disk_bytenr = orig_disk_bytenr; while (bio_offset < orig_len) {
cur_disk_bytenr < orig_disk_bytenr + orig_len; int count;
cur_disk_bytenr += (count * sectorsize)) { u64 cur_disk_bytenr = orig_disk_bytenr + bio_offset;
u64 search_len = orig_disk_bytenr + orig_len - cur_disk_bytenr; u8 *csum_dst = bbio->csum +
unsigned int sector_offset; (bio_offset >> fs_info->sectorsize_bits) * csum_size;
u8 *csum_dst;
/*
* Although both cur_disk_bytenr and orig_disk_bytenr is u64,
* we're calculating the offset to the bio start.
*
* Bio size is limited to UINT_MAX, thus unsigned int is large
* enough to contain the raw result, not to mention the right
* shifted result.
*/
ASSERT(cur_disk_bytenr - orig_disk_bytenr < UINT_MAX);
sector_offset = (cur_disk_bytenr - orig_disk_bytenr) >>
fs_info->sectorsize_bits;
csum_dst = bbio->csum + sector_offset * csum_size;
count = search_csum_tree(fs_info, path, cur_disk_bytenr, count = search_csum_tree(fs_info, path, cur_disk_bytenr,
search_len, csum_dst); orig_len - bio_offset, csum_dst);
if (count < 0) { if (count < 0) {
ret = errno_to_blk_status(count); ret = errno_to_blk_status(count);
if (bbio->csum != bbio->csum_inline) if (bbio->csum != bbio->csum_inline)
...@@ -450,8 +435,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) ...@@ -450,8 +435,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
if (inode->root->root_key.objectid == if (inode->root->root_key.objectid ==
BTRFS_DATA_RELOC_TREE_OBJECTID) { BTRFS_DATA_RELOC_TREE_OBJECTID) {
u64 file_offset = bbio->file_offset + u64 file_offset = bbio->file_offset + bio_offset;
cur_disk_bytenr - orig_disk_bytenr;
set_extent_bits(&inode->io_tree, file_offset, set_extent_bits(&inode->io_tree, file_offset,
file_offset + sectorsize - 1, file_offset + sectorsize - 1,
...@@ -462,6 +446,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio) ...@@ -462,6 +446,7 @@ blk_status_t btrfs_lookup_bio_sums(struct btrfs_bio *bbio)
cur_disk_bytenr, cur_disk_bytenr + sectorsize); cur_disk_bytenr, cur_disk_bytenr + sectorsize);
} }
} }
bio_offset += count * sectorsize;
} }
btrfs_free_path(path); btrfs_free_path(path);
......
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