From patchwork Sat Jun 9 12:29:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10455531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5DF3D60467 for ; Sat, 9 Jun 2018 12:31:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DF0C223A4 for ; Sat, 9 Jun 2018 12:31:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40CC9223A6; Sat, 9 Jun 2018 12:31:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B49C6223A4 for ; Sat, 9 Jun 2018 12:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE29C6B0266; Sat, 9 Jun 2018 08:31:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B6A2A6B0269; Sat, 9 Jun 2018 08:31:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0C506B026A; Sat, 9 Jun 2018 08:31:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk0-f200.google.com (mail-qk0-f200.google.com [209.85.220.200]) by kanga.kvack.org (Postfix) with ESMTP id 6FEE06B0266 for ; Sat, 9 Jun 2018 08:31:38 -0400 (EDT) Received: by mail-qk0-f200.google.com with SMTP id 5-v6so15530122qke.19 for ; Sat, 09 Jun 2018 05:31:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=eG2++5AiYFno4bFpT79hjlCh5JfDicJNbTGAtKNUFwI=; b=Kt9//217337Qa3IoZOXZjfwMoqE2MB8A3mMgwhI9xZlDgPVsvAdwjfylfbVMfWA21n UfW6HK0+kePvAhOBbgEC0MyUlSfI0sMacisZcD94K9ZJ3lScmza4PlNMH39AKAGiOckf W0E5Y4tuWfdpCm9aMJeJrn7dYspqz+vOtfA21Y9WzShv/wQmto5qbwGEmbBaWv2r2uwD ccCu2i31ldEQxMUQL/HfsMVRQOhO+Ah44wMfwE9FL0xMCoRai2+1ipf4rFlVx37X7sTo 9uDxkX9Dagz2DiApNvgxHZIhP2S2wAjAvByZVXqDcZCUo6Vp7s6hNNh8b5kOdZYCm85C CFOg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APt69E0dYhqBckgiDVqeuu1KpiC8+mWqpb0xo9gJDPrOGTd8RH7V6XLt 2T67qBssKkNnpd/ohqPLKZTR+mkcHnKG3bjr3jVfKVbcefy+Si9uVUrRA0OToooym1pCh0eVHwb Q12pqIml/2DcnNtBMR7MlyXkIFjpx0DS3F9rR1bi5NMdouDjqXjHS7whShM5mho4EDA== X-Received: by 2002:ac8:2d2e:: with SMTP id n43-v6mr9614269qta.106.1528547498254; Sat, 09 Jun 2018 05:31:38 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKzjdMGA/SbIWQIGGpyAbSv9Seex7jNEMXdVI3Ct3U/YlsYVmbZFcHJHxjii7ywKpzsQF3Z X-Received: by 2002:ac8:2d2e:: with SMTP id n43-v6mr9614236qta.106.1528547497517; Sat, 09 Jun 2018 05:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547497; cv=none; d=google.com; s=arc-20160816; b=tTjKYxIGQsz8erVrzN3FD0eDsu2IDeHlp9oNSMAgXGigPYsu1oICjgjNEyyrUvkjDk P31Nm+foi+AdOk36D+Z8iXIs2MA7/zaO0pVzOcfxcJhHEoI9K0lnaLHS1421F7QzZQ7h 851h4wkXUanj3aeRv/QlEoZEnk1jFvG1sIpYTfsqWg9Xz4WIbK1isGW8yzHg/pj/+Aut fHulOtj/226hzQo5SJgg/RTC0R4VkxnPCuFwPL6MVcrNNhLaMLxsXuVZ2eSc+m7Bk516 RwmyBBY7ixHyAlRi+pTzEYdNhZsF74vZC6383HgoCco+Mnoq3QE88i5YCUYEZfvxwm8l OoQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=eG2++5AiYFno4bFpT79hjlCh5JfDicJNbTGAtKNUFwI=; b=sQqZeovZG7CVrradzpCkdKM0yNmW/SHwvQxqPjT3Rr/NgUMJodlgNP8cIP+73DegsI ti31NKZkGuB3B7Os9m/zpYmlOrlRM56FX6EdcrGEfBX+nhR6HRJqeQrZ0M6FTd86KQYw VLiOcxAVDTTgNkjAxVw3BlpKe1IWsn9dDhxoEjLw2vES0UYw5u68rPrxhZslnNF+eudW NQr6bIHT/77kNcvwbVZQyKr8DdX1Zb2r4d/Du2ksSWWJ30C1vViZwizJDoQPWXv11Q8d yO6d3/hmfuQ3fDOSFkyJdUKItTw+vITpMVV9X5ZgVUz+vB59Gt7WDPuHD9gUMVbm7shU esdg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id x186-v6si1880391qkd.254.2018.06.09.05.31.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:31:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ming.lei@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=ming.lei@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27D404187E53; Sat, 9 Jun 2018 12:31:37 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82877210C6D4; Sat, 9 Jun 2018 12:31:28 +0000 (UTC) From: Ming Lei To: Jens Axboe , Christoph Hellwig , Alexander Viro , Kent Overstreet Cc: David Sterba , Huang Ying , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Theodore Ts'o , "Darrick J . Wong" , Coly Li , Filipe Manana , Randy Dunlap , Ming Lei Subject: [PATCH V6 05/30] block: introduce bio_for_each_chunk() Date: Sat, 9 Jun 2018 20:29:49 +0800 Message-Id: <20180609123014.8861-6-ming.lei@redhat.com> In-Reply-To: <20180609123014.8861-1-ming.lei@redhat.com> References: <20180609123014.8861-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 09 Jun 2018 12:31:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 09 Jun 2018 12:31:37 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'ming.lei@redhat.com' RCPT:'' X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This helper is used to iterate multipage bvec for bio spliting/merge, and it is required in bio_clone_bioset() too, so introduce it. Signed-off-by: Ming Lei --- include/linux/bio.h | 34 +++++++++++++++++++++++++++++++--- include/linux/bvec.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/include/linux/bio.h b/include/linux/bio.h index 397a38aca182..e9f74c73bbe6 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -80,6 +80,9 @@ #define bio_data_dir(bio) \ (op_is_write(bio_op(bio)) ? WRITE : READ) +#define bio_iter_chunk_iovec(bio, iter) \ + bvec_iter_chunk_bvec((bio)->bi_io_vec, (iter)) + /* * Check whether this bio carries any data or not. A NULL bio is allowed. */ @@ -165,8 +168,8 @@ static inline bool bio_full(struct bio *bio) #define bio_for_each_segment_all(bvl, bio, i) \ for (i = 0, bvl = (bio)->bi_io_vec; i < (bio)->bi_vcnt; i++, bvl++) -static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, - unsigned bytes) +static inline void __bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes, bool chunk) { iter->bi_sector += bytes >> 9; @@ -174,11 +177,26 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, iter->bi_size -= bytes; iter->bi_done += bytes; } else { - bvec_iter_advance(bio->bi_io_vec, iter, bytes); + if (!chunk) + bvec_iter_advance(bio->bi_io_vec, iter, bytes); + else + bvec_iter_chunk_advance(bio->bi_io_vec, iter, bytes); /* TODO: It is reasonable to complete bio with error here. */ } } +static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes) +{ + __bio_advance_iter(bio, iter, bytes, false); +} + +static inline void bio_advance_chunk_iter(struct bio *bio, struct bvec_iter *iter, + unsigned bytes) +{ + __bio_advance_iter(bio, iter, bytes, true); +} + static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, unsigned int bytes) { @@ -202,6 +220,16 @@ static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, #define bio_for_each_segment(bvl, bio, iter) \ __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter) +#define __bio_for_each_chunk(bvl, bio, iter, start) \ + for (iter = (start); \ + (iter).bi_size && \ + ((bvl = bio_iter_chunk_iovec((bio), (iter))), 1); \ + bio_advance_chunk_iter((bio), &(iter), (bvl).bv_len)) + +/* returns one real segment(multipage bvec) each time */ +#define bio_for_each_chunk(bvl, bio, iter) \ + __bio_for_each_chunk(bvl, bio, iter, (bio)->bi_iter) + #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) static inline unsigned bio_segments(struct bio *bio) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 52c90ea1a96a..9e082d023392 100644 --- a/include/linux/bvec.h +++ b/include/linux/bvec.h @@ -126,8 +126,16 @@ struct bvec_iter { .bv_offset = bvec_iter_offset((bvec), (iter)), \ }) -static inline bool bvec_iter_advance(const struct bio_vec *bv, - struct bvec_iter *iter, unsigned bytes) +#define bvec_iter_chunk_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = bvec_iter_chunk_page((bvec), (iter)), \ + .bv_len = bvec_iter_chunk_len((bvec), (iter)), \ + .bv_offset = bvec_iter_chunk_offset((bvec), (iter)), \ +}) + +static inline bool __bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes, bool chunk) { if (WARN_ONCE(bytes > iter->bi_size, "Attempted to advance past end of bvec iter\n")) { @@ -136,8 +144,14 @@ static inline bool bvec_iter_advance(const struct bio_vec *bv, } while (bytes) { - unsigned iter_len = bvec_iter_len(bv, *iter); - unsigned len = min(bytes, iter_len); + unsigned len; + + if (chunk) + len = bvec_iter_chunk_len(bv, *iter); + else + len = bvec_iter_len(bv, *iter); + + len = min(bytes, len); bytes -= len; iter->bi_size -= len; @@ -176,6 +190,20 @@ static inline bool bvec_iter_rewind(const struct bio_vec *bv, return true; } +static inline bool bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes) +{ + return __bvec_iter_advance(bv, iter, bytes, false); +} + +static inline bool bvec_iter_chunk_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes) +{ + return __bvec_iter_advance(bv, iter, bytes, true); +} + #define for_each_bvec(bvl, bio_vec, iter, start) \ for (iter = (start); \ (iter).bi_size && \