From patchwork Tue Mar 22 06:12:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8638051 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 06C5D9F44D for ; Tue, 22 Mar 2016 06:13:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 290E020225 for ; Tue, 22 Mar 2016 06:13:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B0172038F for ; Tue, 22 Mar 2016 06:13:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752887AbcCVGM7 (ORCPT ); Tue, 22 Mar 2016 02:12:59 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33576 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbcCVGMz (ORCPT ); Tue, 22 Mar 2016 02:12:55 -0400 Received: by mail-pf0-f196.google.com with SMTP id x3so33962347pfb.0; Mon, 21 Mar 2016 23:12:55 -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=DxX0qxvihfp/xCBoeAwAS9rwUImJjQQqIwFbAu4abCjwfB7uztlQUw+i3e8ty29wgL TCRaDst91HmqGHCq9UlXe+TWq8Mb6Hfzvgq9q8QJ5ZMAxchJIMmzOXClue3KQxjqOX1z C4uCksbdunXZDhpJkP5lv2cybw9svqlcdr2Zh4nhwOftMaVhEmhAGmihJkNkJwY1IVDd qb2Ln2M5PGKP6FWkLs+iXSpOI+IL/BgIlsJh53b8l4qtJ9khhCtRGnt8CTkIUBHM35lO kbOuC0P+/yzpFaE+YEUgu/9EiGdraPlype9od6d/uM8tRj5yFU1T1Cyv79lC1/J1uyp/ DckQ== X-Gm-Message-State: AD7BkJJLZZs2d7Q3V7UqoDGg2M/ScWkH7PVPD+dSbM7lDji9vRWc8gfqr6kT6DS/+B6y/Q== X-Received: by 10.67.21.231 with SMTP id hn7mr51428424pad.150.1458627174869; Mon, 21 Mar 2016 23:12:54 -0700 (PDT) Received: from localhost ([116.251.212.171]) by smtp.gmail.com with ESMTPSA id y7sm39006429pfa.82.2016.03.21.23.12.53 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 21 Mar 2016 23:12:54 -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 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Tue, 22 Mar 2016 14:12:25 +0800 Message-Id: <1458627149-12988-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458627149-12988-1-git-send-email-ming.lei@canonical.com> References: <1458627149-12988-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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 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++; \