Commit 4989d277 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: refactor __btrfs_lookup_bio_sums to use bio_for_each_segment_all

Rework the loop a little bit to use the generic bio_for_each_segment_all
helper for iterating over the bio.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2a4d0c90
...@@ -163,7 +163,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -163,7 +163,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
struct inode *inode, struct bio *bio, struct inode *inode, struct bio *bio,
u64 logical_offset, u32 *dst, int dio) u64 logical_offset, u32 *dst, int dio)
{ {
struct bio_vec *bvec = bio->bi_io_vec; struct bio_vec *bvec;
struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio); struct btrfs_io_bio *btrfs_bio = btrfs_io_bio(bio);
struct btrfs_csum_item *item = NULL; struct btrfs_csum_item *item = NULL;
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree;
...@@ -176,8 +176,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -176,8 +176,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
u64 page_bytes_left; u64 page_bytes_left;
u32 diff; u32 diff;
int nblocks; int nblocks;
int bio_index = 0; int count = 0, i;
int count;
u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy); u16 csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
path = btrfs_alloc_path(); path = btrfs_alloc_path();
...@@ -223,8 +222,11 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -223,8 +222,11 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
if (dio) if (dio)
offset = logical_offset; offset = logical_offset;
page_bytes_left = bvec->bv_len; bio_for_each_segment_all(bvec, bio, i) {
while (bio_index < bio->bi_vcnt) { page_bytes_left = bvec->bv_len;
if (count)
goto next;
if (!dio) if (!dio)
offset = page_offset(bvec->bv_page) + bvec->bv_offset; offset = page_offset(bvec->bv_page) + bvec->bv_offset;
count = btrfs_find_ordered_sum(inode, offset, disk_bytenr, count = btrfs_find_ordered_sum(inode, offset, disk_bytenr,
...@@ -285,29 +287,17 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, ...@@ -285,29 +287,17 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
found: found:
csum += count * csum_size; csum += count * csum_size;
nblocks -= count; nblocks -= count;
next:
while (count--) { while (count--) {
disk_bytenr += root->sectorsize; disk_bytenr += root->sectorsize;
offset += root->sectorsize; offset += root->sectorsize;
page_bytes_left -= root->sectorsize; page_bytes_left -= root->sectorsize;
if (!page_bytes_left) { if (!page_bytes_left)
bio_index++; break; /* move to next bio */
/*
* make sure we're still inside the
* bio before we update page_bytes_left
*/
if (bio_index >= bio->bi_vcnt) {
WARN_ON_ONCE(count);
goto done;
}
bvec++;
page_bytes_left = bvec->bv_len;
}
} }
} }
done: WARN_ON_ONCE(count);
btrfs_free_path(path); btrfs_free_path(path);
return 0; return 0;
} }
......
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