diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-08-07 17:26:39 -0400 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-24 01:33:50 -0500 |
commit | 1cb9dda4f4332aa560a2db39f92a96e1a8273cf8 (patch) | |
tree | ba73cf7643fe3564be9b363cbcaf646d4949c455 /fs | |
parent | 4550dd6c6b062fc5e5b647296d55da22616123c3 (diff) |
block: Convert bio_copy_data() to bvec_iter
Our fancy new bvec iterator makes code like this much easier to write.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bio.c | 60 |
1 files changed, 25 insertions, 35 deletions
@@ -852,58 +852,48 @@ EXPORT_SYMBOL(bio_alloc_pages); | |||
852 | */ | 852 | */ |
853 | void bio_copy_data(struct bio *dst, struct bio *src) | 853 | void bio_copy_data(struct bio *dst, struct bio *src) |
854 | { | 854 | { |
855 | struct bio_vec *src_bv, *dst_bv; | 855 | struct bvec_iter src_iter, dst_iter; |
856 | unsigned src_offset, dst_offset, bytes; | 856 | struct bio_vec src_bv, dst_bv; |
857 | void *src_p, *dst_p; | 857 | void *src_p, *dst_p; |
858 | unsigned bytes; | ||
858 | 859 | ||
859 | src_bv = __bio_iovec(src); | 860 | src_iter = src->bi_iter; |
860 | dst_bv = __bio_iovec(dst); | 861 | dst_iter = dst->bi_iter; |
861 | |||
862 | src_offset = src_bv->bv_offset; | ||
863 | dst_offset = dst_bv->bv_offset; | ||
864 | 862 | ||
865 | while (1) { | 863 | while (1) { |
866 | if (src_offset == src_bv->bv_offset + src_bv->bv_len) { | 864 | if (!src_iter.bi_size) { |
867 | src_bv++; | 865 | src = src->bi_next; |
868 | if (src_bv == bio_iovec_idx(src, src->bi_vcnt)) { | 866 | if (!src) |
869 | src = src->bi_next; | 867 | break; |
870 | if (!src) | ||
871 | break; | ||
872 | |||
873 | src_bv = __bio_iovec(src); | ||
874 | } | ||
875 | 868 | ||
876 | src_offset = src_bv->bv_offset; | 869 | src_iter = src->bi_iter; |
877 | } | 870 | } |
878 | 871 | ||
879 | if (dst_offset == dst_bv->bv_offset + dst_bv->bv_len) { | 872 | if (!dst_iter.bi_size) { |
880 | dst_bv++; | 873 | dst = dst->bi_next; |
881 | if (dst_bv == bio_iovec_idx(dst, dst->bi_vcnt)) { | 874 | if (!dst) |
882 | dst = dst->bi_next; | 875 | break; |
883 | if (!dst) | ||
884 | break; | ||
885 | |||
886 | dst_bv = __bio_iovec(dst); | ||
887 | } | ||
888 | 876 | ||
889 | dst_offset = dst_bv->bv_offset; | 877 | dst_iter = dst->bi_iter; |
890 | } | 878 | } |
891 | 879 | ||
892 | bytes = min(dst_bv->bv_offset + dst_bv->bv_len - dst_offset, | 880 | src_bv = bio_iter_iovec(src, src_iter); |
893 | src_bv->bv_offset + src_bv->bv_len - src_offset); | 881 | dst_bv = bio_iter_iovec(dst, dst_iter); |
882 | |||
883 | bytes = min(src_bv.bv_len, dst_bv.bv_len); | ||
894 | 884 | ||
895 | src_p = kmap_atomic(src_bv->bv_page); | 885 | src_p = kmap_atomic(src_bv.bv_page); |
896 | dst_p = kmap_atomic(dst_bv->bv_page); | 886 | dst_p = kmap_atomic(dst_bv.bv_page); |
897 | 887 | ||
898 | memcpy(dst_p + dst_offset, | 888 | memcpy(dst_p + dst_bv.bv_offset, |
899 | src_p + src_offset, | 889 | src_p + src_bv.bv_offset, |
900 | bytes); | 890 | bytes); |
901 | 891 | ||
902 | kunmap_atomic(dst_p); | 892 | kunmap_atomic(dst_p); |
903 | kunmap_atomic(src_p); | 893 | kunmap_atomic(src_p); |
904 | 894 | ||
905 | src_offset += bytes; | 895 | bio_advance_iter(src, &src_iter, bytes); |
906 | dst_offset += bytes; | 896 | bio_advance_iter(dst, &dst_iter, bytes); |
907 | } | 897 | } |
908 | } | 898 | } |
909 | EXPORT_SYMBOL(bio_copy_data); | 899 | EXPORT_SYMBOL(bio_copy_data); |