From patchwork Fri May 25 03:45:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426027 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 672AD602D8 for ; Fri, 25 May 2018 03:47:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 545DD2959E for ; Fri, 25 May 2018 03:47:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 460CB295A4; Fri, 25 May 2018 03:47:53 +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 9CE502959E for ; Fri, 25 May 2018 03:47:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 969056B0294; Thu, 24 May 2018 23:47:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 918536B0296; Thu, 24 May 2018 23:47:51 -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 8086D6B0297; Thu, 24 May 2018 23:47:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 55CB66B0294 for ; Thu, 24 May 2018 23:47:51 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id c4-v6so2919677qtp.9 for ; Thu, 24 May 2018 20:47:51 -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=6ohPLapeZto0fYS8USEPKhQS8UOMYtNidbpOWj0QsZk=; b=Sqj/cNOylFFvhry6/EuHVTx0K7R74GnryvtqbxIUoPPgdUnlM6IlLsYzxdutd6QjHL 48SUEkr7B89JcKSlSfaNx1owDSRBavgWGaeBGOKCoTspgcoLXTPZGLKl+qJGpUYgpAyX P3wxuJweffvhQfpl/Uv9gv+MMAMAP35v1so48wmilVgNNjuXC3eAOl2+ovJ2Lh+YBx78 dQq3K7kJ0c6dDuyNYpsHx0n+HF0Davpg+Il4OoA5ASWxxfOwoI+da3gOrJ0a6LzEo1eD IXEH6xqoAgL2VAANuLRsPxdFaCsDFLcDTbcOq+U0Jj3EDGHqQfr/PXzMlccAcUtiMscr B4Ng== 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: ALKqPwfjdsL0EsA5w7B2iXSqQpdM0M7sMX7UwywR+VBIJNgB1DBcZy7a RCnq3qR6IRo8vSLNyobaRPp4I6g2b6Im4Ge9QjThPZiPcBvin7RbLekDj6vgcV7IHc4fwaoUyXZ QqI19pfe4V/zQ2vhnuoRoemUuHnmkcyV3giB+SBot4YiKiwQRkdvkaPYgp2ODLHDM/Q== X-Received: by 2002:a37:82c6:: with SMTP id e189-v6mr544098qkd.322.1527220071140; Thu, 24 May 2018 20:47:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKG7h3GFHI0pX28DCkrNvdxZPx76kO/NjL7ssU8a1omWyildKsh8Xi+rqy+NBqirM9b/08j X-Received: by 2002:a37:82c6:: with SMTP id e189-v6mr544076qkd.322.1527220070488; Thu, 24 May 2018 20:47:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220070; cv=none; d=google.com; s=arc-20160816; b=Q/dpbXDE5Mm3gMtOHGUB5VBrzn+ElOjU/rOnbAo7xLCwf5rUJxDUEg81AaRxXutbEC 37PhS7fTohcRtQ1PVwgiWkZ/5nEMPDrS5avyjg5ewWgpFU1JupflONSl6ZFx6vw/vsjU CUhmkP6ViJjVwPL48Hvekul3V/U/Ibg++FQlJE9etz7V62Ak+4C5Lqp43Mh6Hw6w4aRS nyUovAr5Avn2dbWXBX4DXld8lLEGL7xpRikVUEa8zXenBwy1VsZWQBh8P/k62V1W9/gV xHs4IrvfGS5BnwD9y9K3S3Pz7fzqhgdyPs0vtzUQNALbnsas3Ng3uhY8pnAyd3teChfu 9+Ow== 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=6ohPLapeZto0fYS8USEPKhQS8UOMYtNidbpOWj0QsZk=; b=vDzq4EK7TqmWFEF9jfmUMifcbVi/lvMf0P3TRJwKKn0yy6U79YQHJoejBd7pfH9Fa7 kIfe2I2qu7tRaNQgriLRBr/P83htEFvi/sbyPbP/vDpCl8xpsxXP1P868POM2gDpNr5z EzykZYMSgOw2uqVUZ4swfcnnnxxOnRvUBa4JAnUr2elk/IQgauw/VzIUPwY4fJ0Rar2e pJ4W91kJ0Fy/Y68HZA+RnWR6jTYEmJF+N94c6zO8dlzsDb8uLk/lVSbvNTgRlmEsLCTd C1WkvLqfYMqUrjJxiLQRwXGkYUi0b7lDp1xesvWZY8hVPmslvo3MjE6W4XHDS4oUuKAR AuJA== 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 j23-v6si13371qtl.150.2018.05.24.20.47.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 20:47:50 -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-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 23BB0402290A; Fri, 25 May 2018 03:47:50 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id B05242166BB2; Fri, 25 May 2018 03:47:41 +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 , Ming Lei Subject: [RESEND PATCH V5 05/33] block: introduce bio_for_each_segment() Date: Fri, 25 May 2018 11:45:53 +0800 Message-Id: <20180525034621.31147-6-ming.lei@redhat.com> In-Reply-To: <20180525034621.31147-1-ming.lei@redhat.com> References: <20180525034621.31147-1-ming.lei@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:47:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:47:50 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 7f92af1299ad..3d3795b9a353 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_seg_iovec(bio, iter) \ + bvec_iter_segment_bvec((bio)->bi_io_vec, (iter)) + /* * Check whether this bio carries any data or not. A NULL bio is allowed. */ @@ -160,8 +163,8 @@ static inline void *bio_data(struct bio *bio) #define bio_for_each_page_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 seg) { iter->bi_sector += bytes >> 9; @@ -169,11 +172,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 (!seg) + bvec_iter_advance(bio->bi_io_vec, iter, bytes); + else + bvec_iter_seg_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_seg_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) { @@ -197,6 +215,16 @@ static inline bool bio_rewind_iter(struct bio *bio, struct bvec_iter *iter, #define bio_for_each_page(bvl, bio, iter) \ __bio_for_each_page(bvl, bio, iter, (bio)->bi_iter) +#define __bio_for_each_segment(bvl, bio, iter, start) \ + for (iter = (start); \ + (iter).bi_size && \ + ((bvl = bio_iter_seg_iovec((bio), (iter))), 1); \ + bio_advance_seg_iter((bio), &(iter), (bvl).bv_len)) + +/* returns one real segment(multipage bvec) each time */ +#define bio_for_each_segment(bvl, bio, iter) \ + __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter) + #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len) static inline unsigned bio_pages(struct bio *bio) diff --git a/include/linux/bvec.h b/include/linux/bvec.h index 2433c73fa5ea..84c395feed49 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_segment_bvec(bvec, iter) \ +((struct bio_vec) { \ + .bv_page = bvec_iter_segment_page((bvec), (iter)), \ + .bv_len = bvec_iter_segment_len((bvec), (iter)), \ + .bv_offset = bvec_iter_segment_offset((bvec), (iter)), \ +}) + +static inline bool __bvec_iter_advance(const struct bio_vec *bv, + struct bvec_iter *iter, + unsigned bytes, bool segment) { 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 (segment) + len = bvec_iter_segment_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_seg_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 && \