aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/bio.h
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2019-02-15 19:13:19 +0800
committerJens Axboe <axboe@kernel.dk>2019-02-15 08:40:11 -0700
commit6dc4f100c175dd0511ae8674786e7c9006cdfbfa (patch)
treeb8e5204ca6eec1275187496f2d6c069643e478dc /include/linux/bio.h
parentbcache: avoid to use bio_for_each_segment_all() in bch_bio_alloc_pages() (diff)
downloadwireguard-linux-6dc4f100c175dd0511ae8674786e7c9006cdfbfa.tar.xz
wireguard-linux-6dc4f100c175dd0511ae8674786e7c9006cdfbfa.zip
block: allow bio_for_each_segment_all() to iterate over multi-page bvec
This patch introduces one extra iterator variable to bio_for_each_segment_all(), then we can allow bio_for_each_segment_all() to iterate over multi-page bvec. Given it is just one mechannical & simple change on all bio_for_each_segment_all() users, this patch does tree-wide change in one single patch, so that we can avoid to use a temporary helper for this conversion. Reviewed-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'include/linux/bio.h')
-rw-r--r--include/linux/bio.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7ef8a7505c0a..089370eb84d9 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -128,12 +128,19 @@ static inline bool bio_full(struct bio *bio)
return bio->bi_vcnt >= bio->bi_max_vecs;
}
+#define mp_bvec_for_each_segment(bv, bvl, i, iter_all) \
+ for (bv = bvec_init_iter_all(&iter_all); \
+ (iter_all.done < (bvl)->bv_len) && \
+ (mp_bvec_next_segment((bvl), &iter_all), 1); \
+ iter_all.done += bv->bv_len, i += 1)
+
/*
* drivers should _never_ use the all version - the bio may have been split
* before it got to the driver and the driver won't own all of it
*/
-#define bio_for_each_segment_all(bvl, bio, i) \
- for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++)
+#define bio_for_each_segment_all(bvl, bio, i, iter_all) \
+ for (i = 0, iter_all.idx = 0; iter_all.idx < (bio)->bi_vcnt; iter_all.idx++) \
+ mp_bvec_for_each_segment(bvl, &((bio)->bi_io_vec[iter_all.idx]), i, iter_all)
static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
unsigned bytes)