From patchwork Mon Jun 11 19:48:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10458731 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 CA82A6020F for ; Mon, 11 Jun 2018 19:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B99DD285BA for ; Mon, 11 Jun 2018 19:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE383285BE; Mon, 11 Jun 2018 19:48:18 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B0F4285BA for ; Mon, 11 Jun 2018 19:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753645AbeFKTsR (ORCPT ); Mon, 11 Jun 2018 15:48:17 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:48582 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751050AbeFKTsQ (ORCPT ); Mon, 11 Jun 2018 15:48:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=4GO3eC6+bA2dL+jVB8dATTSWG9ZPnG4qSpLLp5sJ9mY=; b=M0pjmVvyYmXtHczQ2Gl/YIg8T RwVgE8obbFNm5d+yGuv9Y5vaIwJ4NZRjakPf3kzyeziehPUSYwx6HOPbp7KpSSrklnutLfwAB8pki eNzJ9laKJliU4Kmz4LvxV2s3AvbhWsKHmHerTKcJbo1NbPyUGBsdtTHORP3C9aWzFbsXkJ0vw2Isi cIqyks9EK00mJ3+aVugUx/q2luBjzgS+ttoDn7AHt/L91F14Jhlv86hp346MlQkwsqFAIbM4Rklif iiKgCt4b/G8Rv1FgfjD/kho/2qXM6H+EEGMVbSn9sxuS+jTfGBXFzbOBUie2SRVfh+nYDhrRigNxP xtEW79c+g==; Received: from 213-225-7-72.nat.highway.a1.net ([213.225.7.72] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fSSnW-00045u-G6; Mon, 11 Jun 2018 19:48:15 +0000 From: Christoph Hellwig To: Jens Axboe , Coly Li Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH 1/6] block: add a bio_reuse helper Date: Mon, 11 Jun 2018 21:48:01 +0200 Message-Id: <20180611194806.13222-2-hch@lst.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180611194806.13222-1-hch@lst.de> References: <20180611194806.13222-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This abstracts out a way to reuse a bio without destroying the data pointers. Signed-off-by: Christoph Hellwig --- block/bio.c | 20 ++++++++++++++++++++ include/linux/bio.h | 1 + 2 files changed, 21 insertions(+) diff --git a/block/bio.c b/block/bio.c index 70c4e1b6dd45..fa1b7ab50784 100644 --- a/block/bio.c +++ b/block/bio.c @@ -308,6 +308,26 @@ void bio_reset(struct bio *bio) } EXPORT_SYMBOL(bio_reset); +/** + * bio_reuse - prepare a bio for reuse + * @bio: bio to reuse + * + * Prepares an already setup and possible used bio for reusing it another + * time. Compared to bio_reset() this preserves the bio size and the + * layout and contents of the bio vectors. + */ +void bio_reuse(struct bio *bio) +{ + unsigned int size = bio->bi_iter.bi_size; + unsigned short vcnt = bio->bi_vcnt; + + bio_reset(bio); + + bio->bi_iter.bi_size = size; + bio->bi_vcnt = vcnt; +} +EXPORT_SYMBOL_GPL(bio_reuse); + static struct bio *__bio_chain_endio(struct bio *bio) { struct bio *parent = bio->bi_private; diff --git a/include/linux/bio.h b/include/linux/bio.h index f08f5fe7bd08..15c871ab50db 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -475,6 +475,7 @@ extern void bio_init(struct bio *bio, struct bio_vec *table, unsigned short max_vecs); extern void bio_uninit(struct bio *); extern void bio_reset(struct bio *); +void bio_reuse(struct bio *); void bio_chain(struct bio *, struct bio *); extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);