Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2999258imm; Thu, 24 May 2018 20:51:50 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrHMIojimhf2PO2QBnTsiX9jPAn7vcsDFRVYgNO/wYTz0pakoZ5wMcwfA8YVB5/zLqGdnyO X-Received: by 2002:a17:902:6bc7:: with SMTP id m7-v6mr823773plt.162.1527220310215; Thu, 24 May 2018 20:51:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220310; cv=none; d=google.com; s=arc-20160816; b=QfhJWJTBjY7tImmq/dB3ZEZtY+vwnVziotl4OHBjToRZTBHEtUFbv6cEflPAopS2Ew /6AdmN63N0k41eypkrqo6n1Y0iuBp0XP8ouDzayBf6wMcfjLtQQfCe4Wz04e+E1TQhDm YxRWPk2wyWzpKJkDJbvFtNAx7RIzbSQcWYPDrJEiUt9arJRCwPzKNQYPdfoxBt6kggav 1U1qNljSMjJoxDnIKUaGrrpGANNw9idhjnf9/NMOPdZECMnGOskmAxMKmawmbdg2ry3Y C3hJMVg6d9Dian2tHly/h/ozDvyzV/lTVzjwOAoavvvty2tM/7lSoAeKDlQAea2MOeX6 6ZMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=pRVxslCiv51Qin0JejF7iNDEiVyRI7bI0mPGxALBAbI=; b=ovOkqfsATlNNPW3QRyciiTtXRc+1YbDjgx2e0WvHo4GK6Zk+S8zfvm+nD8vor35GGz VuQZ2nvqNTbUdzYmSXSEot0JgQCyKMB7w0UjVjo9TOZk2/5t/hVAEwvG/TTdvJ0/Ygue uJ5XimKTYAbWb2d1f4pOxxNoEs4aokCwg/nqi/jujKWLo88sLEG5KP+Vcj/SUPtr9to4 bR8CJJtnQX3yWh1ZH/O4OPSORNPt0NSjjYsbWcow8IMqlpOBmN3p1NdAqFjQfr/NQfxr GbYcpJkAho6upEQ/G/z93J9MMx4RXr77cmUBka74qND+IFgm4ZJ8EwAiDnCKq49vJZkA isWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x7-v6si11880175pgt.559.2018.05.24.20.51.35; Thu, 24 May 2018 20:51:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935443AbeEYDto (ORCPT + 99 others); Thu, 24 May 2018 23:49:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38022 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935358AbeEYDtm (ORCPT ); Thu, 24 May 2018 23:49:42 -0400 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 EF4114022414; Fri, 25 May 2018 03:49:41 +0000 (UTC) Received: from localhost (ovpn-12-30.pek2.redhat.com [10.72.12.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7173E2166BB2; Fri, 25 May 2018 03:49:34 +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 15/33] block: introduce bio_clone_seg_bioset() Date: Fri, 25 May 2018 11:46:03 +0800 Message-Id: <20180525034621.31147-16-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:49:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 25 May 2018 03:49:42 +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:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is one use case(DM) which requires to clone bio segment by segement, 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 d0debb22ee34..63d4fe85f42e 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 page) { struct bvec_iter iter; struct bio_vec bv; struct bio *bio; + int nr_vecs = page ? bio_pages(bio_src) : bio_segments(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_pages(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_page(bv, bio_src, iter) - bio->bi_io_vec[bio->bi_vcnt++] = bv; + if (page) { + bio_for_each_page(bv, bio_src, iter) + bio->bi_io_vec[bio->bi_vcnt++] = bv; + } else { + bio_for_each_segment(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_seg_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_seg_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 b24c00f99c9c..61a04c131641 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -475,6 +475,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_seg_bioset(struct bio *, gfp_t, struct bio_set *bs); extern struct bio_set fs_bio_set; -- 2.9.5