From patchwork Fri May 25 03:46:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 10426079 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 18A27602D8 for ; Fri, 25 May 2018 03:49:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 082F72959E for ; Fri, 25 May 2018 03:49:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F11EB295A4; Fri, 25 May 2018 03:49:44 +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 74C8A2959E for ; Fri, 25 May 2018 03:49:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82DF16B02A8; Thu, 24 May 2018 23:49:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7B70C6B02AA; Thu, 24 May 2018 23:49:43 -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 631506B02AB; Thu, 24 May 2018 23:49:43 -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 2D8276B02A8 for ; Thu, 24 May 2018 23:49:43 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id g3-v6so2906259qtp.14 for ; Thu, 24 May 2018 20:49:43 -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=pRVxslCiv51Qin0JejF7iNDEiVyRI7bI0mPGxALBAbI=; b=dSmPlN/VoY69+aqwmES5ezh7BWHvgHZsslradi23piI37Tbh3vlRw8LN3RKkPrGvYq EprN7pb+CXsuVE/vqtajOcsZ5eaGmxTk5T88VWJybNsEFLfw2DuxRRBHA6IWEZGdaPZ/ dJcX0ic0jQAYhWnmOKtmCnCefhBeWYmUiEQDGXHne6kzKegNRMkkGzxyHUZGt85fCYqs +ZdW+ac9EViNJNtn1OO9RheohDGVSw/mFRnSU2+p/9JtV94vC1651cYV9R2H9JogOfVA mjFcNWb6In32uNfgwFUeHhptr9kSLkwlOW959LG3c1WY/MvYlXEbtpSMBbEnkn6F9R5P vdTQ== 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: ALKqPwfVxrF58W3IsqDfjR6Yts26JY4I12z1V0MNBahWahyNJ3JUHzJ5 KMkZQxWTrTBs+5Pz/JyBdnqUSjCZdhgcXCPHXQcgWaZ83icDQ8YCun7SbZR4p2duN/AszfKv1pA AainisJV66hdW4wnJJMfcLJSyrvC6UxOyak9GDz3AIz59F8/vfOLpW6ogalUi66Ne+g== X-Received: by 2002:aed:3c7a:: with SMTP id u55-v6mr560522qte.391.1527220182973; Thu, 24 May 2018 20:49:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKW2iU1bMb6nU/iee0ihXARPTTBKwxFMAZkvuoSGsjEY97N/1brQTpqyjvBWoLwg5IosvtK X-Received: by 2002:aed:3c7a:: with SMTP id u55-v6mr560506qte.391.1527220182336; Thu, 24 May 2018 20:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527220182; cv=none; d=google.com; s=arc-20160816; b=AnLdXaRO6Y4uP8gS8a1oHtilSOc88H1LFQLoCLUuoZ0ke6JaVjTplgWUnPbteI4C5b lN5eEgCdyf1JzPmJUakgN9+MH7KwWnl4Mog0Xs1OujGeH/FaKp7N7ykGukamGvPqWOPr T7OqZpoutxKh+dHDKjAT0J8lpMKj/RTl9Ut36k+lvUhWfWGnYS+BJI/70ZrOAYuppVKf 2a1g9YLlwQIoE2jzdZjTniAzrXDI0rexQaTaFG4WdUuF7tRRXqQuyYyMg4h5SwjaQLw7 RVVF+d6ro4z5sLX0uzSIdJcP077XXngY3dgGP6W7uT/UCpe8F7nJTumHcY/F5KQyJgeC ubsw== 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=pRVxslCiv51Qin0JejF7iNDEiVyRI7bI0mPGxALBAbI=; b=xtlbonIV4DO46nK9wASNzua2dhw27JXoze259ByGpfUKfVf7gMjpwqPEwbmE9JKI36 gFYcPeU35EAzmPHq3W8auajgvaUvwxa1I4KElodsMeP89Ev0KKkNBKDcYYyrj0p9RElH U82GcfruxqfmcU5RfnkqO5uWOJPyju18k42T192MAuGIlq0Vd2dN7DleTgiN6xVxIXa2 nYDr3DH4KOiSCGkKau4zeNaaUYkT4LWMjFJI9rWkVHODloWjMUy0K9ZHHK6tyn6RA6w7 MPTJOL9KsnTm/k6DZ1kH5fzjrmJ4y5WXyL5ZPkh8OMp3zpH3zXkRU0jB2j8hqBMLEE4a SE2w== 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 l4-v6si6301844qkc.332.2018.05.24.20.49.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 20:49:42 -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 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:'' 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 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;