diff options
author | Ming Lei <ming.lei@canonical.com> | 2016-06-09 12:00:58 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2016-06-09 12:00:58 -0400 |
commit | 8fc554552c9d89e7bf76cd4cbc0085648bf3125b (patch) | |
tree | 1fe45de8fea776f50a7bbfa970c17973a79f40da /include | |
parent | 52b9c330c6a8a4b5a1819bdaddf4ec76ab571e81 (diff) |
block: move bvec iterator into include/linux/bvec.h
bvec iterator helpers should be used to implement by
iterate_bvec():lib/iov_iter.c too, and move them into
one header, so that we can keep bvec iterator header
out of CONFIG_BLOCK. Then we can remove the reinventing
of wheel in iterate_bvec().
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Tested-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/bio.h | 51 | ||||
-rw-r--r-- | include/linux/bvec.h | 74 |
2 files changed, 75 insertions, 50 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h index 0bbb2e332410..8e0f677c26d2 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */ | 32 | /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */ |
33 | #include <linux/blk_types.h> | 33 | #include <linux/blk_types.h> |
34 | #include <linux/bvec.h> | ||
34 | 35 | ||
35 | #define BIO_DEBUG | 36 | #define BIO_DEBUG |
36 | 37 | ||
@@ -47,29 +48,6 @@ | |||
47 | #define bio_prio(bio) (bio)->bi_ioprio | 48 | #define bio_prio(bio) (bio)->bi_ioprio |
48 | #define bio_set_prio(bio, prio) ((bio)->bi_ioprio = prio) | 49 | #define bio_set_prio(bio, prio) ((bio)->bi_ioprio = prio) |
49 | 50 | ||
50 | /* | ||
51 | * various member access, note that bio_data should of course not be used | ||
52 | * on highmem page vectors | ||
53 | */ | ||
54 | #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) | ||
55 | |||
56 | #define bvec_iter_page(bvec, iter) \ | ||
57 | (__bvec_iter_bvec((bvec), (iter))->bv_page) | ||
58 | |||
59 | #define bvec_iter_len(bvec, iter) \ | ||
60 | min((iter).bi_size, \ | ||
61 | __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) | ||
62 | |||
63 | #define bvec_iter_offset(bvec, iter) \ | ||
64 | (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) | ||
65 | |||
66 | #define bvec_iter_bvec(bvec, iter) \ | ||
67 | ((struct bio_vec) { \ | ||
68 | .bv_page = bvec_iter_page((bvec), (iter)), \ | ||
69 | .bv_len = bvec_iter_len((bvec), (iter)), \ | ||
70 | .bv_offset = bvec_iter_offset((bvec), (iter)), \ | ||
71 | }) | ||
72 | |||
73 | #define bio_iter_iovec(bio, iter) \ | 51 | #define bio_iter_iovec(bio, iter) \ |
74 | bvec_iter_bvec((bio)->bi_io_vec, (iter)) | 52 | bvec_iter_bvec((bio)->bi_io_vec, (iter)) |
75 | 53 | ||
@@ -188,33 +166,6 @@ static inline void *bio_data(struct bio *bio) | |||
188 | #define bio_for_each_segment_all(bvl, bio, i) \ | 166 | #define bio_for_each_segment_all(bvl, bio, i) \ |
189 | for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) | 167 | for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) |
190 | 168 | ||
191 | static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter, | ||
192 | unsigned bytes) | ||
193 | { | ||
194 | WARN_ONCE(bytes > iter->bi_size, | ||
195 | "Attempted to advance past end of bvec iter\n"); | ||
196 | |||
197 | while (bytes) { | ||
198 | unsigned len = min(bytes, bvec_iter_len(bv, *iter)); | ||
199 | |||
200 | bytes -= len; | ||
201 | iter->bi_size -= len; | ||
202 | iter->bi_bvec_done += len; | ||
203 | |||
204 | if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { | ||
205 | iter->bi_bvec_done = 0; | ||
206 | iter->bi_idx++; | ||
207 | } | ||
208 | } | ||
209 | } | ||
210 | |||
211 | #define for_each_bvec(bvl, bio_vec, iter, start) \ | ||
212 | for (iter = (start); \ | ||
213 | (iter).bi_size && \ | ||
214 | ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \ | ||
215 | bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len)) | ||
216 | |||
217 | |||
218 | static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, | 169 | static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, |
219 | unsigned bytes) | 170 | unsigned bytes) |
220 | { | 171 | { |
diff --git a/include/linux/bvec.h b/include/linux/bvec.h new file mode 100644 index 000000000000..29c459da277e --- /dev/null +++ b/include/linux/bvec.h | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * bvec iterator | ||
3 | * | ||
4 | * Copyright (C) 2001 Ming Lei <ming.lei@canonical.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 as | ||
8 | * published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public Licens | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- | ||
19 | */ | ||
20 | #ifndef __LINUX_BVEC_ITER_H | ||
21 | #define __LINUX_BVEC_ITER_H | ||
22 | |||
23 | #include <linux/blk_types.h> | ||
24 | |||
25 | /* | ||
26 | * various member access, note that bio_data should of course not be used | ||
27 | * on highmem page vectors | ||
28 | */ | ||
29 | #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx]) | ||
30 | |||
31 | #define bvec_iter_page(bvec, iter) \ | ||
32 | (__bvec_iter_bvec((bvec), (iter))->bv_page) | ||
33 | |||
34 | #define bvec_iter_len(bvec, iter) \ | ||
35 | min((iter).bi_size, \ | ||
36 | __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done) | ||
37 | |||
38 | #define bvec_iter_offset(bvec, iter) \ | ||
39 | (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done) | ||
40 | |||
41 | #define bvec_iter_bvec(bvec, iter) \ | ||
42 | ((struct bio_vec) { \ | ||
43 | .bv_page = bvec_iter_page((bvec), (iter)), \ | ||
44 | .bv_len = bvec_iter_len((bvec), (iter)), \ | ||
45 | .bv_offset = bvec_iter_offset((bvec), (iter)), \ | ||
46 | }) | ||
47 | |||
48 | static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter, | ||
49 | unsigned bytes) | ||
50 | { | ||
51 | WARN_ONCE(bytes > iter->bi_size, | ||
52 | "Attempted to advance past end of bvec iter\n"); | ||
53 | |||
54 | while (bytes) { | ||
55 | unsigned len = min(bytes, bvec_iter_len(bv, *iter)); | ||
56 | |||
57 | bytes -= len; | ||
58 | iter->bi_size -= len; | ||
59 | iter->bi_bvec_done += len; | ||
60 | |||
61 | if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) { | ||
62 | iter->bi_bvec_done = 0; | ||
63 | iter->bi_idx++; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | #define for_each_bvec(bvl, bio_vec, iter, start) \ | ||
69 | for (iter = (start); \ | ||
70 | (iter).bi_size && \ | ||
71 | ((bvl = bvec_iter_bvec((bio_vec), (iter))), 1); \ | ||
72 | bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len)) | ||
73 | |||
74 | #endif /* __LINUX_BVEC_ITER_H */ | ||