aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2019-02-15 06:13:19 -0500
committerJens Axboe <axboe@kernel.dk>2019-02-15 10:40:11 -0500
commit6dc4f100c175dd0511ae8674786e7c9006cdfbfa (patch)
treeb8e5204ca6eec1275187496f2d6c069643e478dc /include/linux
parent2e1f4f4d2481d8bf111904c3e45fc0c4c94bf76e (diff)
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')
-rw-r--r--include/linux/bio.h11
-rw-r--r--include/linux/bvec.h30
2 files changed, 39 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)
128 return bio->bi_vcnt >= bio->bi_max_vecs; 128 return bio->bi_vcnt >= bio->bi_max_vecs;
129} 129}
130 130
131#define mp_bvec_for_each_segment(bv, bvl, i, iter_all) \
132 for (bv = bvec_init_iter_all(&iter_all); \
133 (iter_all.done < (bvl)->bv_len) && \
134 (mp_bvec_next_segment((bvl), &iter_all), 1); \
135 iter_all.done += bv->bv_len, i += 1)
136
131/* 137/*
132 * drivers should _never_ use the all version - the bio may have been split 138 * drivers should _never_ use the all version - the bio may have been split
133 * before it got to the driver and the driver won't own all of it 139 * before it got to the driver and the driver won't own all of it
134 */ 140 */
135#define bio_for_each_segment_all(bvl, bio, i) \ 141#define bio_for_each_segment_all(bvl, bio, i, iter_all) \
136 for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) 142 for (i = 0, iter_all.idx = 0; iter_all.idx < (bio)->bi_vcnt; iter_all.idx++) \
143 mp_bvec_for_each_segment(bvl, &((bio)->bi_io_vec[iter_all.idx]), i, iter_all)
137 144
138static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, 145static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
139 unsigned bytes) 146 unsigned bytes)
diff --git a/include/linux/bvec.h b/include/linux/bvec.h
index 21f76bad7be2..30a57b68d017 100644
--- a/include/linux/bvec.h
+++ b/include/linux/bvec.h
@@ -45,6 +45,12 @@ struct bvec_iter {
45 current bvec */ 45 current bvec */
46}; 46};
47 47
48struct bvec_iter_all {
49 struct bio_vec bv;
50 int idx;
51 unsigned done;
52};
53
48/* 54/*
49 * various member access, note that bio_data should of course not be used 55 * various member access, note that bio_data should of course not be used
50 * on highmem page vectors 56 * on highmem page vectors
@@ -131,6 +137,30 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv,
131 .bi_bvec_done = 0, \ 137 .bi_bvec_done = 0, \
132} 138}
133 139
140static inline struct bio_vec *bvec_init_iter_all(struct bvec_iter_all *iter_all)
141{
142 iter_all->bv.bv_page = NULL;
143 iter_all->done = 0;
144
145 return &iter_all->bv;
146}
147
148static inline void mp_bvec_next_segment(const struct bio_vec *bvec,
149 struct bvec_iter_all *iter_all)
150{
151 struct bio_vec *bv = &iter_all->bv;
152
153 if (bv->bv_page) {
154 bv->bv_page = nth_page(bv->bv_page, 1);
155 bv->bv_offset = 0;
156 } else {
157 bv->bv_page = bvec->bv_page;
158 bv->bv_offset = bvec->bv_offset;
159 }
160 bv->bv_len = min_t(unsigned int, PAGE_SIZE - bv->bv_offset,
161 bvec->bv_len - iter_all->done);
162}
163
134/* 164/*
135 * Get the last single-page segment from the multi-page bvec and store it 165 * Get the last single-page segment from the multi-page bvec and store it
136 * in @seg 166 * in @seg