Commit 1cb9dda4 authored by Kent Overstreet's avatar Kent Overstreet

block: Convert bio_copy_data() to bvec_iter

Our fancy new bvec iterator makes code like this much easier to write.
Signed-off-by: default avatarKent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
parent 4550dd6c
...@@ -852,58 +852,48 @@ EXPORT_SYMBOL(bio_alloc_pages); ...@@ -852,58 +852,48 @@ EXPORT_SYMBOL(bio_alloc_pages);
*/ */
void bio_copy_data(struct bio *dst, struct bio *src) void bio_copy_data(struct bio *dst, struct bio *src)
{ {
struct bio_vec *src_bv, *dst_bv; struct bvec_iter src_iter, dst_iter;
unsigned src_offset, dst_offset, bytes; struct bio_vec src_bv, dst_bv;
void *src_p, *dst_p; void *src_p, *dst_p;
unsigned bytes;
src_bv = __bio_iovec(src); src_iter = src->bi_iter;
dst_bv = __bio_iovec(dst); dst_iter = dst->bi_iter;
src_offset = src_bv->bv_offset;
dst_offset = dst_bv->bv_offset;
while (1) { while (1) {
if (src_offset == src_bv->bv_offset + src_bv->bv_len) { if (!src_iter.bi_size) {
src_bv++; src = src->bi_next;
if (src_bv == bio_iovec_idx(src, src->bi_vcnt)) { if (!src)
src = src->bi_next; break;
if (!src)
break;
src_bv = __bio_iovec(src);
}
src_offset = src_bv->bv_offset; src_iter = src->bi_iter;
} }
if (dst_offset == dst_bv->bv_offset + dst_bv->bv_len) { if (!dst_iter.bi_size) {
dst_bv++; dst = dst->bi_next;
if (dst_bv == bio_iovec_idx(dst, dst->bi_vcnt)) { if (!dst)
dst = dst->bi_next; break;
if (!dst)
break;
dst_bv = __bio_iovec(dst);
}
dst_offset = dst_bv->bv_offset; dst_iter = dst->bi_iter;
} }
bytes = min(dst_bv->bv_offset + dst_bv->bv_len - dst_offset, src_bv = bio_iter_iovec(src, src_iter);
src_bv->bv_offset + src_bv->bv_len - src_offset); dst_bv = bio_iter_iovec(dst, dst_iter);
bytes = min(src_bv.bv_len, dst_bv.bv_len);
src_p = kmap_atomic(src_bv->bv_page); src_p = kmap_atomic(src_bv.bv_page);
dst_p = kmap_atomic(dst_bv->bv_page); dst_p = kmap_atomic(dst_bv.bv_page);
memcpy(dst_p + dst_offset, memcpy(dst_p + dst_bv.bv_offset,
src_p + src_offset, src_p + src_bv.bv_offset,
bytes); bytes);
kunmap_atomic(dst_p); kunmap_atomic(dst_p);
kunmap_atomic(src_p); kunmap_atomic(src_p);
src_offset += bytes; bio_advance_iter(src, &src_iter, bytes);
dst_offset += bytes; bio_advance_iter(dst, &dst_iter, bytes);
} }
} }
EXPORT_SYMBOL(bio_copy_data); EXPORT_SYMBOL(bio_copy_data);
......
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