From patchwork Mon Apr 4 06:56:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8737911 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 73FE89F36E for ; Mon, 4 Apr 2016 06:58:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 99C6A201BB for ; Mon, 4 Apr 2016 06:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B36C3200DB for ; Mon, 4 Apr 2016 06:58:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754261AbcDDG5G (ORCPT ); Mon, 4 Apr 2016 02:57:06 -0400 Received: from mail-pf0-f170.google.com ([209.85.192.170]:36386 "EHLO mail-pf0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751010AbcDDG5E (ORCPT ); Mon, 4 Apr 2016 02:57:04 -0400 Received: by mail-pf0-f170.google.com with SMTP id e128so116178011pfe.3; Sun, 03 Apr 2016 23:57:03 -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=T84E5r8SO0QZoKCDA8vyoXvqulJoiLHB4RbTn9CHEzk=; b=bJxzL2p1T/EprGtdwna8E1RNxZseYqiaufJlaZ7As2mwRDJ3/Vk0TsvY5UQWS4MrpE RpltEykJEOnlupNddPBhEepbbPu85+ztGEEQILpKu+ei2i+1sQ2dyZAik+aHvMRhssl+ IWRT/yZ23FMzo2W5Or4yYY6+VTdL93/TJVkJAVDUSk1qrw3lfgB9peRV/H8pJqk32Cb6 fzLuINqpuYrvnEItmQU0tA//EQEymWNT+7cj+vN5BBdrHBt2tbiMuVp8wtMtns37BbZM BYUgiQNJ7jLFkLc0PprcWMMNyDFj47JE2mxl1WHmpy5ZjGGEqBARRZUaNcCBCJBqAI0S /U+w== X-Gm-Message-State: AD7BkJJuqSDwlntSE9ihVdMXcBS0l7BrWBGKd7V/XJVSgEZu2VkjXFq/WiIj9kgGpbKfbg== X-Received: by 10.98.16.198 with SMTP id 67mr18454882pfq.21.1459753023504; Sun, 03 Apr 2016 23:57:03 -0700 (PDT) Received: from localhost (45-125-195-13.ip4.readyserver.sg. [45.125.195.13]) by smtp.gmail.com with ESMTPSA id ut5sm38849630pab.15.2016.04.03.23.57.01 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 03 Apr 2016 23:57:02 -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 v3 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Mon, 4 Apr 2016 14:56:30 +0800 Message-Id: <1459752994-2205-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459752994-2205-1-git-send-email-ming.lei@canonical.com> References: <1459752994-2205-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=ham 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 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++; \