From patchwork Thu Apr 14 11:46:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 8834651 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 207D8C0553 for ; Thu, 14 Apr 2016 11:49:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3ADB62011D for ; Thu, 14 Apr 2016 11:49:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4B3F220114 for ; Thu, 14 Apr 2016 11:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754267AbcDNLsZ (ORCPT ); Thu, 14 Apr 2016 07:48:25 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:35313 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753708AbcDNLsT (ORCPT ); Thu, 14 Apr 2016 07:48:19 -0400 Received: by mail-oi0-f68.google.com with SMTP id w18so9507073oie.2; Thu, 14 Apr 2016 04:48:18 -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=OiR6joiz/fOl9TnXcSpMzkhgB7blOeXr5bTczF7gnXTWzqbnS7TsyBGkH9SKs1hPJK uRcO9O+4YrtE3DXd6QnVQlUCsRbDROsxtuufG2kA5qV/v6Nf8jQxUqqV1y8qXAdqoP5F 9I/S5GrKboJZ9Xts7jiX7y1WE/o0UHDx1ALV4W6r+TyjP/BmUSxt4kozvCJPcWDwlxzD RPopO8KD3v234nr9f6dgRobkOTy+wv34zp5/nAAv9oSVSOknyXidqxYFA4lfmMicIl18 CH4g3t5DQrPK4IU3+2/FoMVXdq7/hP/Q3sHkrKU0+okfZGrVG4+SL5OYYAKc+pFTkZpW WgPA== X-Gm-Message-State: AOPr4FWjKQkA2/bBZOw5ZIXQKKLjEF4yy58ZJsb8LF3wqjgfTV1iXeyowT8ASSg6e8MHoQ== X-Received: by 10.157.43.104 with SMTP id f37mr6810915otd.77.1460634498196; Thu, 14 Apr 2016 04:48:18 -0700 (PDT) Received: from localhost ([12.228.154.70]) by smtp.gmail.com with ESMTPSA id fi5sm4997654oeb.5.2016.04.14.04.48.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 14 Apr 2016 04:48:17 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org Cc: linux-block@vger.kernel.org, Christoph Hellwig , Al Viro , Ming Lei Subject: [PATCH v4 4/8] iov_iter: use bvec iterator to implement iterate_bvec() Date: Thu, 14 Apr 2016 19:46:57 +0800 Message-Id: <1460634438-26530-5-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1460634438-26530-1-git-send-email-ming.lei@canonical.com> References: <1460634438-26530-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.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 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++; \