From patchwork Sun Apr 3 16:31:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8734611 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 B1E8E9F38C for ; Sun, 3 Apr 2016 16:32:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D69D520219 for ; Sun, 3 Apr 2016 16:32:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 030BC20212 for ; Sun, 3 Apr 2016 16:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754327AbcDCQbs (ORCPT ); Sun, 3 Apr 2016 12:31:48 -0400 Received: from mail-pa0-f43.google.com ([209.85.220.43]:36476 "EHLO mail-pa0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754320AbcDCQbq (ORCPT ); Sun, 3 Apr 2016 12:31:46 -0400 Received: by mail-pa0-f43.google.com with SMTP id tt10so126797970pab.3; Sun, 03 Apr 2016 09:31:46 -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=ND2956c/Unh2qBuH8enzguOcJYZNmg/E9rYihTEmEh0sbgSA+CQCKFBOTsj7li8zNu 0G5nXYIM9mEtKRs90PG1ItvQZTvFdIw652YyM7AbOSPLVunl30Q2ZNui5E9gyarncrX2 kiYMnFEr2aUygc8QidoDVnrUTZj83Vg5nO6hJSvG828jtg8LhpcCP8EtjuFNjopuZoMN niNQ+4Ex2dBotuXYVSiIV4MbBlpWZWgEnc2YKw1hxt8BYIffgxTNMkj1tmeek0tsQQCB Nc5LfTrPhCv5NUEEHwsK8MmJ6X/1Kpo7s/UdLM2w+uGofd6IHjPbmuMyW0ydYicOHUBe 5XWg== X-Gm-Message-State: AD7BkJJG1QippjjMeyb4zcn4I52qThujG0yW8vS/ILoIdC1OG+gaw5X67U5xCPAPQrnUEw== X-Received: by 10.66.66.135 with SMTP id f7mr17106581pat.155.1459701106197; Sun, 03 Apr 2016 09:31:46 -0700 (PDT) Received: from localhost (45-125-195-13.ip4.readyserver.sg. [45.125.195.13]) by smtp.gmail.com with ESMTPSA id n74sm33469401pfa.45.2016.04.03.09.31.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 03 Apr 2016 09:31:45 -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 v2 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Mon, 4 Apr 2016 00:31:05 +0800 Message-Id: <1459701069-31406-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1459701069-31406-1-git-send-email-ming.lei@canonical.com> References: <1459701069-31406-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++; \