From patchwork Wed Mar 30 16:17:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8699731 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2DAE99F44D for ; Wed, 30 Mar 2016 16:24:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 591572026F for ; Wed, 30 Mar 2016 16:24:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29A832038A for ; Wed, 30 Mar 2016 16:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755035AbcC3QRp (ORCPT ); Wed, 30 Mar 2016 12:17:45 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33460 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754931AbcC3QRo (ORCPT ); Wed, 30 Mar 2016 12:17:44 -0400 Received: by mail-pf0-f195.google.com with SMTP id x3so7873676pfb.0; Wed, 30 Mar 2016 09:17:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sqH+M04IB5voUIBmOkvSetipqppS8wuuKQ8USkT2zHY=; b=C6/4uYmMNQxgq38uH9CjDvvlkrez/MSUIQ57EXVn5AyVuZB1CFIehqqy3My+KeEt39 fMSV/yl7jE2wMbr6JQVEnM1RJ/eBCnShIhkCllTJlb11sokysNvq1B7m7qtlqr/AzoCA L98DQTYW62DSm9yTOUQUCXiwnQRxaFYKuI8fJlDlTOXTpO1kuYiAmkSUXyPfRnL5E/P6 l4FUTSZKJ1xMzyZ0+1qfDjfs1xM64DXqbBFT8EnzYmxTwDqyKZ+Q3oHh/iHeECNUn7e2 k2CCUEqLienCkR0LalY5Ey77ZpHkCSoVo/3pvvq0etlRzYXYxM6qBQhN4V5kt5N/JBtF AEGA== X-Gm-Message-State: AD7BkJJdpE6qFjxOiKzF02wqotIr461qHJplnZJGA6jPqP5IA1CWUydiHtz91doEW4x4oQ== X-Received: by 10.98.32.211 with SMTP id m80mr14576287pfj.3.1459354663628; Wed, 30 Mar 2016 09:17:43 -0700 (PDT) Received: from localhost (45-125-195-13.ip4.readyserver.sg. [45.125.195.13]) by smtp.gmail.com with ESMTPSA id q2sm7009496pfq.88.2016.03.30.09.17.42 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 30 Mar 2016 09:17:42 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Anton Altaparmakov , xfs@oss.sgi.com, Dave Chinner , drbd-dev@lists.linbit.com, Philipp Reisner , Lars Ellenberg , Boaz Harrosh , Ming Lei Subject: [PATCH v1 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Thu, 31 Mar 2016 00:17:13 +0800 Message-Id: <1459354637-17415-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459354637-17415-1-git-send-email-ming.lei@canonical.com> References: <1459354637-17415-1-git-send-email-ming.lei@canonical.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SBL, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP bvec has provided one iterator already, so not necessary to invent a new wheel for this job. Signed-off-by: Ming Lei --- 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 #include #include +#include #include #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++; \