From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F8F6C433B4 for ; Wed, 5 May 2021 17:36:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 097DB610E7 for ; Wed, 5 May 2021 17:36:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 097DB610E7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 720AC6B006E; Wed, 5 May 2021 13:36:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EFBA6B0070; Wed, 5 May 2021 13:36:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 571066B0071; Wed, 5 May 2021 13:36:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 3BD4D6B006E for ; Wed, 5 May 2021 13:36:06 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 01D41180AD830 for ; Wed, 5 May 2021 17:36:06 +0000 (UTC) X-FDA: 78107880732.30.E1EF923 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 27D0780192E9 for ; Wed, 5 May 2021 17:35:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=UdKLAv9tD4IGgGm2E+DtgLcmHg6ZIlBUn72zqqp8p8Y=; b=mN9tRfYc42+ctPCPH7j2z1N2AR fMnuaC/JLZcM2VKRlu8R1lHO2k+TBdqiEFsqOiw1gZ9CgG5JiQq68+Clws+E7ynITwcJGEbQj4zlB 1ruDX2D9xy/f2RYE0TSS6lOwb2U8unS7XvvAleK/nRzfO7xE3DX6BEtkoF/UyAYCU6W0kgvIzwCOs HqVJcA1prRwu04Qgpx63mhJpUYhGlRNAwjqjMtFdIefLIBLvDPFkINP25mKABQwqIaQ9P3OeZFt5K P2cVv/rus1WmtgLR4VHZYIVXyNbyOexQg6hhk0dkJXW1w6i0WHKH1oRXWwmtzZxiuiUjfL5IJglqZ wFefjiyg==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1leKQr-000ar5-R5; Wed, 05 May 2021 16:32:21 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v9 71/96] block: Add bio_add_folio Date: Wed, 5 May 2021 16:06:03 +0100 Message-Id: <20210505150628.111735-72-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505150628.111735-1-willy@infradead.org> References: <20210505150628.111735-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 27D0780192E9 X-Stat-Signature: 4oq6j4u5eq6awmqghtn4h544o5dargsp Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=mN9tRfYc; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf27; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620236135-500511 Content-Transfer-Encoding: quoted-printable 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: This is a thin wrapper around bio_add_page(). The main advantage here is the documentation that the submitter can expect to see folios in the completion handler, and that stupidly large folios are not supported. It's not currently possible to allocate stupidly large folios, but if it ever becomes possible, this function will fail gracefully instead of doing I/O to the wrong bytes. Signed-off-by: Matthew Wilcox (Oracle) --- block/bio.c | 21 +++++++++++++++++++++ include/linux/bio.h | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index 221dc56ba22f..f84defe8d84a 100644 --- a/block/bio.c +++ b/block/bio.c @@ -940,6 +940,27 @@ int bio_add_page(struct bio *bio, struct page *page, } EXPORT_SYMBOL(bio_add_page); =20 +/** + * bio_add_folio - Attempt to add part of a folio to a bio. + * @bio: Bio to add to. + * @folio: Folio to add. + * @len: How many bytes from the folio to add. + * @off: First byte in this folio to add. + * + * Always uses the head page of the folio in the bio. If a submitter + * only uses bio_add_folio(), it can count on never seeing tail pages + * in the completion routine. BIOs do not support folios larger than 2G= iB. + * + * Return: The number of bytes from this folio added to the bio. + */ +size_t bio_add_folio(struct bio *bio, struct folio *folio, size_t len, + size_t off) +{ + if (len > UINT_MAX || off > UINT_MAX) + return 0; + return bio_add_page(bio, &folio->page, len, off); +} + void bio_release_pages(struct bio *bio, bool mark_dirty) { struct bvec_iter_all iter_all; diff --git a/include/linux/bio.h b/include/linux/bio.h index f1a99f0a240c..f41f20ebc2c6 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -468,7 +468,8 @@ extern void bio_uninit(struct bio *); extern void bio_reset(struct bio *); void bio_chain(struct bio *, struct bio *); =20 -extern int bio_add_page(struct bio *, struct page *, unsigned int,unsign= ed int); +int bio_add_page(struct bio *, struct page *, unsigned len, unsigned off= ); +size_t bio_add_folio(struct bio *, struct folio *, size_t len, size_t of= f); extern int bio_add_pc_page(struct request_queue *, struct bio *, struct = page *, unsigned int, unsigned int); int bio_add_zone_append_page(struct bio *bio, struct page *page, --=20 2.30.2