Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754438AbcDNLsc (ORCPT ); Thu, 14 Apr 2016 07:48:32 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35313 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753708AbcDNLsT (ORCPT ); Thu, 14 Apr 2016 07:48:19 -0400 From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Ming Lei Subject: [PATCH v4 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Thu, 14 Apr 2016 19:46:57 +0800 Message-Id: <1460634438-26530-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460634438-26530-1-git-send-email-ming.lei@canonical.com> References: <1460634438-26530-1-git-send-email-ming.lei@canonical.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1962 Lines: 68 bvec has provided one iterator already, so not necessary to reinvent a new wheel for this job. Signed-off-by: Ming Lei --- lib/iov_iter.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 5fecddc..c8691ac 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -57,35 +57,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 +92,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