From patchwork Sat Jun 9 12:29:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10455585 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 9823960467 for ; Sat, 9 Jun 2018 12:33:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B04E1FF83 for ; Sat, 9 Jun 2018 12:33:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FDB7223A4; Sat, 9 Jun 2018 12:33:41 +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 F22FB1FF83 for ; Sat, 9 Jun 2018 12:33:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10C5F6B027E; Sat, 9 Jun 2018 08:33:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0BB336B0280; Sat, 9 Jun 2018 08:33:40 -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 EC6986B0281; Sat, 9 Jun 2018 08:33:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id BE9A86B027E for ; Sat, 9 Jun 2018 08:33:39 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id l10-v6so14532322qth.14 for ; Sat, 09 Jun 2018 05:33:39 -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=In67tOeOWY4m9CTzLp3qoAITiovS8MCzZEfpL704j70=; b=sM7GyJt/eKt+yDRw2xE2nATcI7g/UH8faicjiym+5CRZ/2mHyvfD5i1Wl0WN2YCcLf ed6CHfNzrxD+JxRh8PAgumcmEoQA1V4JXvc2hQmt0IqFtLT0W0LjcRaI89GLL49KxqGQ ZRgIdOK8xld+L7i6bbXR6fHnMWBrj7acEmZBae6LcmyenZRTly54UQ3DgqkAkNrTwOz1 sPQJNMz14TjUtNA2CzE95Z0syL84I62t+a8tLzgchAXmYCUAT9t+3rF+jPgu4XQyW5NU QHTJSFHETgcg8g+eyQ2tA1MLeGwK+YipYOiwnwPdXmcohNyW6n8Zmo3Kh7vULfA5HLXj g2iw== 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: APt69E3sW2NBmd6U7V+qZZtCA9W8Q5sUjWLtDqZ8aKGmx5jY1pd3c1On 7yuife7qh8pWjxgTYM3DiFSydYIz6nYCp63647TBiyGpOdCM4x8kSrPiGCm2As8ZEKX5vpliKjq 6NFEy4SU5LeYcgh83jikOEC3nbePZX6DzYuYwny6ePMbNHUZbU8zgrAP6f4sg04s2iQ== X-Received: by 2002:a0c:d7c6:: with SMTP id g6-v6mr8435189qvj.85.1528547619551; Sat, 09 Jun 2018 05:33:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK2E78jdvpakVqBFrA/6Yvyvozq5TQk2AJRhuoLxz8WqFbcukE4R/gAMFGlTqOYQ7/C4N3V X-Received: by 2002:a0c:d7c6:: with SMTP id g6-v6mr8435151qvj.85.1528547618716; Sat, 09 Jun 2018 05:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528547618; cv=none; d=google.com; s=arc-20160816; b=dX1U71XK0fuFFyc07PcTpTKacdE8tva0iUcsgjL2c+reYOZ6lyLu81ITsbO+A+63jU 3z6yAqDnFfzugyyFgEeQ9KYga1NOJoLy9QmJnW7Jz3BLjH/rFl3xuRpQrRcvOMQELajX C18dXp1KowBAxITmSdaA0lMtURtklxQM21/y9Dw1fUMijheecNvZKmwVW828gn86Z6gD tO+ww4PnC4F+xzl5rugVMdc7uwcejqrsrbnsHfTxvnVTxitOqvvwOSbYgxBcPSZEcdDZ r/ByNsZfbVAjwqgc3ZmH8aYqqMbVmlFud9yBoSWGTBZQEVJunQDz6gOlgeuosjiH5Qxl /vHQ== 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=In67tOeOWY4m9CTzLp3qoAITiovS8MCzZEfpL704j70=; b=W3LjGrv5BFtMFNEgefxTnwZusyWZ1nJXC3u/Eb+WD2ig1iqy0OSeZnvqUEdR3Q+Lph YAcVWdrW4Xe5UyeM6hq/9EzEoRUEiwpjHwHk3t7HFzcH2H3XQwQ99ilYgEbYYhh09/QA FFTFYYCdH6VlIMQWRyY3jPkd/5nLmNpUMic2we2NHn54vw9zfJkB00EJ3Fsrz+RV/bBo CAeY/62aLzkE6WeWwOTL+QooVrxNDvRxsLIUA3q9/+8OYsmWNNfjpT/krniOrkkal6O+ nBamktVTFrnkPj8lwg2D8GKHnGT7wLsSgMx7/y9ewrdnROXODxqb5THCZLaO0y+12i3y mxJA== 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 d7-v6si3646714qvf.4.2018.06.09.05.33.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 09 Jun 2018 05:33:38 -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 563C5BB42D; Sat, 9 Jun 2018 12:33:38 +0000 (UTC) Received: from localhost (ovpn-12-40.pek2.redhat.com [10.72.12.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B94D210C6D4; Sat, 9 Jun 2018 12:33:29 +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 15/30] block: introduce bio_clone_chunk_bioset() Date: Sat, 9 Jun 2018 20:29:59 +0800 Message-Id: <20180609123014.8861-16-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.1]); Sat, 09 Jun 2018 12:33:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 09 Jun 2018 12:33:38 +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 There is one use case(DM) which requires to clone bio chunk by chunk, so introduce this API. Signed-off-by: Ming Lei --- block/bio.c | 56 +++++++++++++++++++++++++++++++++++++++-------------- include/linux/bio.h | 1 + 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/block/bio.c b/block/bio.c index cb0f46e2752b..60219f82ddab 100644 --- a/block/bio.c +++ b/block/bio.c @@ -644,21 +644,13 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs) } EXPORT_SYMBOL(bio_clone_fast); -/** - * bio_clone_bioset - clone a bio - * @bio_src: bio to clone - * @gfp_mask: allocation priority - * @bs: bio_set to allocate from - * - * Clone bio. Caller will own the returned bio, but not the actual data it - * points to. Reference count of returned bio will be one. - */ -struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, - struct bio_set *bs) +static struct bio *__bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, + struct bio_set *bs, bool seg) { struct bvec_iter iter; struct bio_vec bv; struct bio *bio; + int nr_vecs = seg ? bio_segments(bio_src) : bio_chunks(bio_src); /* * Pre immutable biovecs, __bio_clone() used to just do a memcpy from @@ -682,7 +674,7 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, * __bio_clone_fast() anyways. */ - bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs); + bio = bio_alloc_bioset(gfp_mask, nr_vecs, bs); if (!bio) return NULL; bio->bi_disk = bio_src->bi_disk; @@ -700,8 +692,13 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0]; break; default: - bio_for_each_segment(bv, bio_src, iter) - bio->bi_io_vec[bio->bi_vcnt++] = bv; + if (seg) { + bio_for_each_segment(bv, bio_src, iter) + bio->bi_io_vec[bio->bi_vcnt++] = bv; + } else { + bio_for_each_chunk(bv, bio_src, iter) + bio->bi_io_vec[bio->bi_vcnt++] = bv; + } break; } @@ -719,9 +716,40 @@ struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, return bio; } + +/** + * bio_clone_bioset - clone a bio + * @bio_src: bio to clone + * @gfp_mask: allocation priority + * @bs: bio_set to allocate from + * + * Clone bio. Caller will own the returned bio, but not the actual data it + * points to. Reference count of returned bio will be one. + */ +struct bio *bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, + struct bio_set *bs) +{ + return __bio_clone_bioset(bio_src, gfp_mask, bs, true); +} EXPORT_SYMBOL(bio_clone_bioset); /** + * bio_clone_seg_bioset - clone a bio segment by segment + * @bio_src: bio to clone + * @gfp_mask: allocation priority + * @bs: bio_set to allocate from + * + * Clone bio. Caller will own the returned bio, but not the actual data it + * points to. Reference count of returned bio will be one. + */ +struct bio *bio_clone_chunk_bioset(struct bio *bio_src, gfp_t gfp_mask, + struct bio_set *bs) +{ + return __bio_clone_bioset(bio_src, gfp_mask, bs, false); +} +EXPORT_SYMBOL(bio_clone_chunk_bioset); + +/** * bio_add_pc_page - attempt to add page to bio * @q: the target queue * @bio: destination bio diff --git a/include/linux/bio.h b/include/linux/bio.h index 13fd7bc30390..0fa1035dde38 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -483,6 +483,7 @@ extern void bio_put(struct bio *); extern void __bio_clone_fast(struct bio *, struct bio *); extern struct bio *bio_clone_fast(struct bio *, gfp_t, struct bio_set *); extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs); +extern struct bio *bio_clone_chunk_bioset(struct bio *, gfp_t, struct bio_set *bs); extern struct bio_set fs_bio_set;