Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2635885pxv; Sun, 11 Jul 2021 20:58:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/rQ8WjL6gmDmxDw4QlmjuEskowBdE3Yfy5GQK6xXR69eB/ZACxecfD7jncrbDy1BfM5Mj X-Received: by 2002:a05:6402:1d4d:: with SMTP id dz13mr9025694edb.67.1626062314598; Sun, 11 Jul 2021 20:58:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626062314; cv=none; d=google.com; s=arc-20160816; b=F0UXjSe3UkHlZVLlpHAT5Jci2KSexZ5SjjueOXQaffvDLFz1uSqfU4ABPzTJbBoPLM xa9kMeIGECrjlsoZc62byxJv9a7LBqWkbfYutCRu59wboFOXLbccO0+5ntqUd2DR1gpk 2F52iUX/kxddzSbEjeu9NfhCblgwjH0/wVU22iPnJSa/ot2rn+gUqMqvgWx6Qimc+JBw CEQoSba/+xA+Po5TjtmeCKpW1o0thFMbPLoE5dYsqiiLZwwBRCrDNuUJfVkHPLKUveeB Kqe2UK8Ge8V1hN+BjOSdNt05Pfz6TPCjnWjv7DY+zG5S3Z++uIj44pijA46ZSDuQ7xMb tG7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bVPSf8Zkk6csbsziZBtmmFnz26QKcpfneTyu4NcWG00=; b=XO4z0s+HyyY4dQelZgddc92f8I0x75W37VyR5a19WQomFK6/E2hpHTW7XDzb1KzD+2 bxjAfFwXr/ELB421okMPQjlFuLuPfIx2wcdDAbNGI5NkkYlAPr4YunyBfoNYq+TDUvCI NCHIMy85cfCiql0UfcF0BVN06vRBpZpBu/LC8owgp1wSG6g7QdvRq8jFDLnlVHJSRqqI opzXsx/A5XSfQrWIEW3T/WdbpvM5Wtf99/SoyZ9B7wT4OkkJyqQYZhRaeCa4CQXVrLo0 vewDD/GdWExj4/yeNHGNJ9VrR9XPnR7IZeDiTNmTu1lRkPgvkJ+YT1CuvzjReTwdBsm6 omdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=j9muBP3w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cy26si11651356edb.25.2021.07.11.20.58.12; Sun, 11 Jul 2021 20:58:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=j9muBP3w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233306AbhGLD6A (ORCPT + 99 others); Sun, 11 Jul 2021 23:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbhGLD6A (ORCPT ); Sun, 11 Jul 2021 23:58:00 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A45C0613DD; Sun, 11 Jul 2021 20:55:12 -0700 (PDT) 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=bVPSf8Zkk6csbsziZBtmmFnz26QKcpfneTyu4NcWG00=; b=j9muBP3wTptyZsD5eXcQGw9O2c uHmtx3h2zSJ2rx7c9Kr74uYn5E79GZD2Tm4ggUHR7aKDBtvRpsMiOgRWpupCyto+whwL2akwyInb2 f9K6/k74kEnnvVoHDUWvDpTXSTZqkB8CWBjcSN39HdwRUO3hvIrdsZSQQAuIKlJQ6n7FAl1/TB7LR HgjgtpT5Io/FblJ/F/Lnb+LP3IuycmWYlX93MEMKL9S2waMe/O+hmu6/uzavgYB96Oky4Qst5qkdi lE10yzycg7HeXS9PUD89QVYcETxw2F8UJETGOfCvkJ3XkivI/zKgjLGrhbGLAJCWJ4ibyD0NMWLjJ VntxcuXQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m2n1N-00Gq40-B0; Mon, 12 Jul 2021 03:54:28 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v13 089/137] block: Add bio_add_folio() Date: Mon, 12 Jul 2021 04:06:13 +0100 Message-Id: <20210712030701.4000097-90-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712030701.4000097-1-willy@infradead.org> References: <20210712030701.4000097-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 1fab762e079b..1b500611d25c 100644 --- a/block/bio.c +++ b/block/bio.c @@ -933,6 +933,27 @@ int bio_add_page(struct bio *bio, struct page *page, } EXPORT_SYMBOL(bio_add_page); +/** + * 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 2GiB. + * + * 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 2203b686e1f0..ade93e2de6a1 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -462,7 +462,8 @@ extern void bio_uninit(struct bio *); extern void bio_reset(struct bio *); void bio_chain(struct bio *, struct bio *); -extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned 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 off); 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, -- 2.30.2