Commit 6cd7ce49 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: don't access the bio directly in btrfs_csum_one_bio

Use bio_for_each_segment_all to iterate over the segments instead.
This requires a bit of reshuffling so that we only lookup up the ordered
item once inside the bio_for_each_segment_all loop.
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 6a2de22f
...@@ -447,13 +447,12 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, ...@@ -447,13 +447,12 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
struct bio *bio, u64 file_start, int contig) struct bio *bio, u64 file_start, int contig)
{ {
struct btrfs_ordered_sum *sums; struct btrfs_ordered_sum *sums;
struct btrfs_ordered_extent *ordered; struct btrfs_ordered_extent *ordered = NULL;
char *data; char *data;
struct bio_vec *bvec = bio->bi_io_vec; struct bio_vec *bvec;
int bio_index = 0;
int index; int index;
int nr_sectors; int nr_sectors;
int i; int i, j;
unsigned long total_bytes = 0; unsigned long total_bytes = 0;
unsigned long this_sum_bytes = 0; unsigned long this_sum_bytes = 0;
u64 offset; u64 offset;
...@@ -470,17 +469,20 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, ...@@ -470,17 +469,20 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
if (contig) if (contig)
offset = file_start; offset = file_start;
else else
offset = page_offset(bvec->bv_page) + bvec->bv_offset; offset = 0; /* shut up gcc */
ordered = btrfs_lookup_ordered_extent(inode, offset);
BUG_ON(!ordered); /* Logic error */
sums->bytenr = (u64)bio->bi_iter.bi_sector << 9; sums->bytenr = (u64)bio->bi_iter.bi_sector << 9;
index = 0; index = 0;
while (bio_index < bio->bi_vcnt) { bio_for_each_segment_all(bvec, bio, j) {
if (!contig) if (!contig)
offset = page_offset(bvec->bv_page) + bvec->bv_offset; offset = page_offset(bvec->bv_page) + bvec->bv_offset;
if (!ordered) {
ordered = btrfs_lookup_ordered_extent(inode, offset);
BUG_ON(!ordered); /* Logic error */
}
data = kmap_atomic(bvec->bv_page); data = kmap_atomic(bvec->bv_page);
nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info, nr_sectors = BTRFS_BYTES_TO_BLKS(root->fs_info,
...@@ -529,9 +531,6 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode, ...@@ -529,9 +531,6 @@ int btrfs_csum_one_bio(struct btrfs_root *root, struct inode *inode,
} }
kunmap_atomic(data); kunmap_atomic(data);
bio_index++;
bvec++;
} }
this_sum_bytes = 0; this_sum_bytes = 0;
btrfs_add_ordered_sum(inode, ordered, sums); btrfs_add_ordered_sum(inode, ordered, sums);
......
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