Re: [PATCH v15 01/17] block: Add bio_add_folio()
From: Ming Lei <hidden>
Date: 2021-07-30 08:27:04
Also in:
linux-fsdevel, linux-mm
On Mon, Jul 19, 2021 at 07:39:45PM +0100, Matthew Wilcox (Oracle) wrote:
quoted hunk ↗ jump to hunk
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) <willy@infradead.org> --- 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..c64e35548fb2 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 that are 4GiB or larger. + * + * 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;
The added page shouldn't cross 4G boundary, so just wondering why not check 'if (len > UINT_MAX - off)'? Thanks, Ming