From patchwork Tue Mar 8 11:29:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8532281 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 2551A9F2B4 for ; Tue, 8 Mar 2016 11:31:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 396AF201C8 for ; Tue, 8 Mar 2016 11:31:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 36DB820165 for ; Tue, 8 Mar 2016 11:31:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932768AbcCHLbx (ORCPT ); Tue, 8 Mar 2016 06:31:53 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:34490 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933060AbcCHLae (ORCPT ); Tue, 8 Mar 2016 06:30:34 -0500 Received: by mail-pf0-f194.google.com with SMTP id 184so1063939pff.1; Tue, 08 Mar 2016 03:30:33 -0800 (PST) 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=ZWF+QjaZ6vKltCyHWaazoEJe6pZvokXG3uhrF/t2n4b/xdioeruGSl7X2IGSmJT135 mAuwnWRwt5yvG9FZ3C/0x5PI4tij/Dh49qKzDr4tj7qRyKa/TttEzEr5klrKAuLQrohW O/6CRVgFYxGAsQiMQmm7QN0XsX3DrUi4u4ytkAeewQJEkJ7Ep14LdT9hCOYqNVUo81/Q 8vXSLCNQ1Q57RDZEIy6/2ORfIQC6al84uwDCQDid3o4QkFclJ/bcCow/VftSVVHKApKB SpFJcM7I2OYLBQOP46+6kN9GsYp6v+NnaT1ggPoxivqQBuA+tJy1nayTFg7BEf4gKYKl sRzQ== X-Gm-Message-State: AD7BkJIob/0aKo6dvgNyB+u/GSCXdF9albMwhHEzCZPLPR49UmjdT7BbL3r9WZ7Rk6vUOg== X-Received: by 10.98.80.10 with SMTP id e10mr40768732pfb.141.1457436633403; Tue, 08 Mar 2016 03:30:33 -0800 (PST) Received: from localhost ([116.251.212.171]) by smtp.gmail.com with ESMTPSA id n68sm4370443pfj.46.2016.03.08.03.30.32 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 08 Mar 2016 03:30:32 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Anton Altaparmakov , Ming Lei Subject: [PATCH 4/4] iov_iter: use bvec iterator to implement iterate_bvec() Date: Tue, 8 Mar 2016 19:29:46 +0800 Message-Id: <1457436586-26833-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457436586-26833-1-git-send-email-ming.lei@canonical.com> References: <1457436586-26833-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, 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++; \