Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1367346
| From | Ming Lei <ming.lei@canonical.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v1 4/8] iov_iter: use bvec iterator to implement iterate_bvec() |
| Date | 2016-03-30 18:20 +0200 |
| Message-ID | <rir0D-7XM-43@gated-at.bofh.it> (permalink) |
| References | <rir0C-7XM-9@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
bvec has provided one iterator already, so not necessary
to invent a new wheel for this job.
Signed-off-by: Ming Lei <ming.lei@canonical.com>
---
lib/iov_iter.c | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 5fecddc..5e1b224 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -3,6 +3,7 @@
#include <linux/pagemap.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
+#include <linux/bvec_iter.h>
#include <net/checksum.h>
#define iterate_iovec(i, n, __v, __p, skip, STEP) { \
@@ -57,35 +58,25 @@
}
#define iterate_bvec(i, n, __v, __p, skip, STEP) { \
- size_t wanted = n; \
+ struct bvec_iter __bi, __start; \
+ __start.bi_size = n; \
+ __start.bi_bvec_done = skip; \
+ __start.bi_idx = 0; \
__p = i->bvec; \
- __v.bv_len = min_t(size_t, n, __p->bv_len - skip); \
- if (likely(__v.bv_len)) { \
- __v.bv_page = __p->bv_page; \
- __v.bv_offset = __p->bv_offset + skip; \
+ for_each_bvec(__v, __p, __bi, __start) { \
(void)(STEP); \
- skip += __v.bv_len; \
- n -= __v.bv_len; \
} \
- while (unlikely(n)) { \
- __p++; \
- __v.bv_len = min_t(size_t, n, __p->bv_len); \
- if (unlikely(!__v.bv_len)) \
- continue; \
- __v.bv_page = __p->bv_page; \
- __v.bv_offset = __p->bv_offset; \
- (void)(STEP); \
+ if (!__bi.bi_idx) \
+ skip += __v.bv_len; \
+ else \
skip = __v.bv_len; \
- n -= __v.bv_len; \
- } \
- n = wanted; \
}
#define iterate_all_kinds(i, n, v, I, B, K) { \
size_t skip = i->iov_offset; \
if (unlikely(i->type & ITER_BVEC)) { \
const struct bio_vec *bvec; \
- struct bio_vec v; \
+ struct bio_vec v = { 0 }; \
iterate_bvec(i, n, v, bvec, skip, (B)) \
} else if (unlikely(i->type & ITER_KVEC)) { \
const struct kvec *kvec; \
@@ -102,7 +93,7 @@
size_t skip = i->iov_offset; \
if (unlikely(i->type & ITER_BVEC)) { \
const struct bio_vec *bvec; \
- struct bio_vec v; \
+ struct bio_vec v = { 0 }; \
iterate_bvec(i, n, v, bvec, skip, (B)) \
if (skip == bvec->bv_len) { \
bvec++; \
--
1.9.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v1 0/8] block: prepare for multipage bvecs Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 6/8] block: bio: remove BIO_MAX_SECTORS Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 1/8] block: move bvec iterator into include/linux/bvec_iter.h Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 3/8] block: mark 1st parameter of bvec_iter_advance as const Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 7/8] block: drbd: avoid to use BIO_MAX_SIZE Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 5/8] fs: xfs: replace BIO_MAX_SECTORS with BIO_MAX_PAGES Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 8/8] block: bio: remove BIO_MAX_SIZE Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:20 +0200
[PATCH v1 2/8] block: make 'struct bvec_iter' not depend on CONFIG_BLOCK Ming Lei <ming.lei@canonical.com> - 2016-03-30 18:30 +0200
Re: [PATCH v1 2/8] block: make 'struct bvec_iter' not depend on CONFIG_BLOCK Christoph Hellwig <hch@infradead.org> - 2016-03-30 19:20 +0200
Re: [PATCH v1 2/8] block: make 'struct bvec_iter' not depend on CONFIG_BLOCK Ming Lei <ming.lei@canonical.com> - 2016-03-31 03:10 +0200
Re: [PATCH v1 2/8] block: make 'struct bvec_iter' not depend on CONFIG_BLOCK Christoph Hellwig <hch@infradead.org> - 2016-03-31 10:00 +0200
Re: [PATCH v1 2/8] block: make 'struct bvec_iter' not depend on CONFIG_BLOCK Ming Lei <ming.lei@canonical.com> - 2016-04-01 02:40 +0200
csiph-web