Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1243915

[PATCH 2/2] iov_iter: use bvec iterator to implement iterate_bvec()

From Ming Lei <tom.leiming@gmail.com>
Newsgroups linux.kernel
Subject [PATCH 2/2] iov_iter: use bvec iterator to implement iterate_bvec()
Date 2015-10-10 17:30 +0200
Message-ID <qi4fT-4T5-15@gated-at.bofh.it> (permalink)
References <qi4fT-4T5-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


bvec has provided one iterator already, so not necessary
to invent a new wheel for this job.

Signed-off-by: Ming Lei <tom.leiming@gmail.com>
---
 lib/iov_iter.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 75232ad..e5cfc5c 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/bio.h>
 #include <net/checksum.h>
 
 #define iterate_iovec(i, n, __v, __p, skip, STEP) {	\
@@ -57,28 +58,18 @@
 }
 
 #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) {			\
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/2] iov_iter: use bvec iterator to implement iterate_bvec() Ming Lei <tom.leiming@gmail.com> - 2015-10-10 17:30 +0200
  [PATCH 2/2] iov_iter: use bvec iterator to implement iterate_bvec() Ming Lei <tom.leiming@gmail.com> - 2015-10-10 17:30 +0200
    Re: [PATCH 2/2] iov_iter: use bvec iterator to implement  iterate_bvec() kbuild test robot <lkp@intel.com> - 2015-10-10 17:40 +0200
      Re: [PATCH 2/2] iov_iter: use bvec iterator to implement iterate_bvec() Ming Lei <tom.leiming@gmail.com> - 2015-10-10 17:50 +0200
    Re: [PATCH 2/2] iov_iter: use bvec iterator to implement  iterate_bvec() kbuild test robot <lkp@intel.com> - 2015-10-10 17:40 +0200

csiph-web