Commit 5c67aa90 authored by Al Viro's avatar Al Viro

iov_iter: unify iterate_iovec and iterate_kvec

The differences between iterate_iovec and iterate_kvec are minor:
	* kvec callback is treated as if it returned 0
	* initialization of __p is with i->iov and i->kvec resp.
which is trivially dealt with.

No code generation changes - compiler is quite capable of turning
	left = ((void)(STEP), 0);
	__v.iov_len -= left;
(with no accesses to left downstream) and
	(void)(STEP);
into the same code.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 7a1bcb5d
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
#define PIPE_PARANOIA /* for now */ #define PIPE_PARANOIA /* for now */
/* covers iovec and kvec alike */
#define iterate_iovec(i, n, __v, __p, skip, STEP) { \ #define iterate_iovec(i, n, __v, __p, skip, STEP) { \
size_t left; \ size_t left; \
size_t wanted = n; \ size_t wanted = n; \
__p = i->iov; \
do { \ do { \
__v.iov_len = min(n, __p->iov_len - skip); \ __v.iov_len = min(n, __p->iov_len - skip); \
if (likely(__v.iov_len)) { \ if (likely(__v.iov_len)) { \
...@@ -37,25 +37,6 @@ ...@@ -37,25 +37,6 @@
n = wanted - n; \ n = wanted - n; \
} }
#define iterate_kvec(i, n, __v, __p, skip, STEP) { \
size_t wanted = n; \
__p = i->kvec; \
do { \
__v.iov_len = min(n, __p->iov_len - skip); \
if (likely(__v.iov_len)) { \
__v.iov_base = __p->iov_base + skip; \
(void)(STEP); \
skip += __v.iov_len; \
n -= __v.iov_len; \
if (skip < __p->iov_len) \
break; \
} \
__p++; \
skip = 0; \
} while (n); \
n = wanted - n; \
}
#define iterate_bvec(i, n, __v, __bi, skip, STEP) { \ #define iterate_bvec(i, n, __v, __bi, skip, STEP) { \
struct bvec_iter __start; \ struct bvec_iter __start; \
__start.bi_size = n; \ __start.bi_size = n; \
...@@ -109,7 +90,7 @@ ...@@ -109,7 +90,7 @@
if (likely(n)) { \ if (likely(n)) { \
size_t skip = i->iov_offset; \ size_t skip = i->iov_offset; \
if (likely(iter_is_iovec(i))) { \ if (likely(iter_is_iovec(i))) { \
const struct iovec *iov; \ const struct iovec *iov = i->iov; \
struct iovec v; \ struct iovec v; \
iterate_iovec(i, n, v, iov, skip, (I)) \ iterate_iovec(i, n, v, iov, skip, (I)) \
i->nr_segs -= iov - i->iov; \ i->nr_segs -= iov - i->iov; \
...@@ -123,9 +104,10 @@ ...@@ -123,9 +104,10 @@
i->nr_segs -= i->bvec - bvec; \ i->nr_segs -= i->bvec - bvec; \
skip = __bi.bi_bvec_done; \ skip = __bi.bi_bvec_done; \
} else if (iov_iter_is_kvec(i)) { \ } else if (iov_iter_is_kvec(i)) { \
const struct kvec *kvec; \ const struct kvec *kvec = i->kvec; \
struct kvec v; \ struct kvec v; \
iterate_kvec(i, n, v, kvec, skip, (K)) \ iterate_iovec(i, n, v, kvec, skip, \
((void)(K),0)) \
i->nr_segs -= kvec - i->kvec; \ i->nr_segs -= kvec - i->kvec; \
i->kvec = kvec; \ i->kvec = kvec; \
} else if (iov_iter_is_xarray(i)) { \ } else if (iov_iter_is_xarray(i)) { \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment