block: introduce bio_for_each_bvec() and rq_for_each_bvec()
authorMing Lei <ming.lei@redhat.com>
Fri, 15 Feb 2019 11:13:11 +0000 (19:13 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 15 Feb 2019 15:40:10 +0000 (08:40 -0700)
bio_for_each_bvec() is used for iterating over multi-page bvec for bio
split & merge code.

rq_for_each_bvec() can be used for drivers which may handle the
multi-page bvec directly, so far loop is one perfect use case.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/bio.h
include/linux/blkdev.h

index 72b4f7be2106495acccdf4c6a16d74d3c6a74903..7ef8a7505c0a221f2d9b05fa92dc6a6fb0895f1c 100644 (file)
@@ -156,6 +156,16 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
 #define bio_for_each_segment(bvl, bio, iter)                           \
        __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter)
 
+#define __bio_for_each_bvec(bvl, bio, iter, start)             \
+       for (iter = (start);                                            \
+            (iter).bi_size &&                                          \
+               ((bvl = mp_bvec_iter_bvec((bio)->bi_io_vec, (iter))), 1); \
+            bio_advance_iter((bio), &(iter), (bvl).bv_len))
+
+/* iterate over multi-page bvec */
+#define bio_for_each_bvec(bvl, bio, iter)                      \
+       __bio_for_each_bvec(bvl, bio, iter, (bio)->bi_iter)
+
 #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
 
 static inline unsigned bio_segments(struct bio *bio)
index 3603270cb82d7ace5b994c973c17f6f3b8a208ac..b6292d469ea429f18d124b3e89f3a884839de8b8 100644 (file)
@@ -792,6 +792,10 @@ struct req_iterator {
        __rq_for_each_bio(_iter.bio, _rq)                       \
                bio_for_each_segment(bvl, _iter.bio, _iter.iter)
 
+#define rq_for_each_bvec(bvl, _rq, _iter)                      \
+       __rq_for_each_bio(_iter.bio, _rq)                       \
+               bio_for_each_bvec(bvl, _iter.bio, _iter.iter)
+
 #define rq_iter_last(bvec, _iter)                              \
                (_iter.bio->bi_next == NULL &&                  \
                 bio_iter_last(bvec, _iter.iter))