Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.137.202.133 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376660; b=tMNEeX6epzI6DEUJpcv9MT+dFPKafNnXTfoHz1eZ/ZP7jm3iLISimsmWS/jl5FyqLEft p33wzgZBeqYXPNp0NmCJnLy+dSAMCkjVCMM6itZzNOZrQafR/6Rqt4ma1iqwllRc26ISP yO23hF8QfJjpBxGKEXzcDoWaYA+85nx2tzgNSxtPR/OYdox2E2iiPvimxZ1sJb9WVUGLp K/yoBK/Ks6Cgol7md8MvzY7uyL5XW2YCPJgoVdmbgBcChqIDWIJzrx/rjJxXUuEKO1U1O bOpZO73WWlSuzw+CfjX3Cl40WJPUk70bLYcFSloNWBLQErN9TPtO/qAdLwBk/Q8kteQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376660; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-SRS-Rewrite; bh=bhFFr7nZ/aBj+Eu58hZrrjzbvKw6/5/SidxmX6FGvo4=; b=4loxiGdCUZgsEMN3CYfDNQuSSApEAkxsdSnjzW5XFhxyVmLVn3FZ6bXa7+tZMjuqKSoL eJQ1cWGOPyOF7gBHXpdI7AG6KloY6eTI/ht+x6VPkCYiN4BZ9numgxm77VFV1252rlI+l VKN9mjWXoAwyydBPfH3HXO4bbtoL0uwYrhJ/EC+JFEyA2KULRIXgrXNTyEiLbpikNsUjI 7SQoB4RY0ScHF4j41bGtohUUIY+GpJKghv/xh5kdvCkTptsjgk+PPf8ZWjtaWkC36ol3/ CEWGZ0JOhbO7ePFLkxcbrPaQjdEIali5GWEA9jyYc4NB9kLdmap6ST6na2/OTw4SvVw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=27jKC0sz; arc=none smtp.remote-ip=198.137.202.133 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53C47606A337; Fri, 4 Dec 2026 09:31:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 53C47606A337 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=27jKC0sz DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=bhFFr7nZ/aBj+Eu58hZrrjzbvKw6/5/SidxmX6FGvo4=; b=27jKC0szxUKP2r8gq7j1Eo3nLN TGGvu1JYbPkOcYI7lkOb1XK69up8KNWR9PQg3Oy9XwAfqsBwqaoeC+rp8PnZGHjXz73qrP9a4P0W3 nGJwSPU8h8KxePeipzfJ29GGz1ZISOU+EnEALigvgw/1AkSwNkzRZ2sRZm7IcZtAkQfmoSIH3GVae ZN9dgdPz+lC39DJIkYMoW+sRJbW4wfKB7Ft9fCr04UiU5Y78i8huHPH2KwH7jIOz+Pdry7DrtOQjG lS9fUXy6on17OLFYsCNVmpnqMLSlLNdvHsVYZ747dYLDeocVVI/kfRdvVy/um5UaGk7OQ0CL6G8Wp SeCOItKw==; Received: from 2a02-8389-2301-9f00-1d8d-b225-bb4b-bd8f.cable.dynamic.v6.surfer.at ([2a02:8389:2301:9f00:1d8d:b225:bb4b:bd8f] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZPd5-0000000HN1R-1wDp; Fri, 04 Dec 2026 09:30:59 +0000 From: Christoph Hellwig To: Christian Brauner Cc: Carlos Maiolino , Joanne Koong , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH 2/2] iomap: move optional ioend initialization to the core Date: Fri, 4 Dec 2026 10:30:12 +0100 Message-ID: <20261204093048.2537479-3-hch@lst.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204093048.2537479-1-hch@lst.de> References: <20261204093048.2537479-1-hch@lst.de> X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html For various features that require the file system to hook into the bio submission and completion, and ioend can be overlayed on the bio for direct I/O and buffered reads (buffered writes use the ioend unconditionally). Move the code to do this from the file system to the core iomap code by adding a set of flags to the direct I/O / read ops to prepare for passing checksums from the core to the file system in the ioend. Signed-off-by: Christoph Hellwig --- fs/iomap/buffered-io.c | 8 +++++++- fs/iomap/direct-io.c | 13 ++++++++++--- fs/iomap/internal.h | 2 ++ fs/iomap/ioend.c | 1 - fs/xfs/xfs_aops.c | 5 ++--- fs/xfs/xfs_file.c | 10 ++++------ fs/xfs/xfs_ioend.c | 14 +++++--------- fs/xfs/xfs_ioend.h | 3 +-- include/linux/iomap.h | 22 ++++++++++++++++++++-- 9 files changed, 51 insertions(+), 27 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 59bff9f000a3..ac81895f4e1b 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -557,8 +557,14 @@ static void iomap_read_end(struct folio *folio, size_t bytes_submitted) void iomap_read_submit(const struct iomap_iter *iter, struct iomap_read_folio_ctx *ctx) { - if (ctx->read_ctx && ctx->ops->submit_read) + if (ctx->read_ctx && ctx->ops->submit_read) { + if (ctx->ops->submit_flags & IOMAP_SUBMIT_F_IOEND) { + iomap_init_ioend(iter->inode, ctx->read_ctx, + ctx->read_ctx_file_offset, + iomap_ioend_flags(&iter->iomap)); + } ctx->ops->submit_read(iter, ctx); + } } static int iomap_read_folio_iter(struct iomap_iter *iter, diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 6fa1ca9c30b7..824bce3df668 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -74,9 +74,16 @@ static void iomap_dio_submit_bio(const struct iomap_iter *iter, WRITE_ONCE(iocb->private, bio); } - if (dio->dops && dio->dops->submit_io) { - dio->dops->submit_io(iter, bio, pos); - return; + if (dio->dops) { + if (dio->dops->submit_flags & IOMAP_SUBMIT_F_IOEND) { + iomap_init_ioend(iter->inode, bio, pos, + iomap_ioend_flags(&iter->iomap) | + IOMAP_IOEND_DIRECT); + } + if (dio->dops->submit_io) { + dio->dops->submit_io(iter, bio, pos); + return; + } } WARN_ON_ONCE(iter->iomap.flags & IOMAP_F_ANON_WRITE); diff --git a/fs/iomap/internal.h b/fs/iomap/internal.h index a194b7346184..a4c74a36acd9 100644 --- a/fs/iomap/internal.h +++ b/fs/iomap/internal.h @@ -31,6 +31,8 @@ u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend); void iomap_read_submit(const struct iomap_iter *iter, struct iomap_read_folio_ctx *ctx); +struct iomap_ioend *iomap_init_ioend(struct inode *inode, struct bio *bio, + loff_t file_offset, u16 ioend_flags); #ifdef CONFIG_BLOCK int iomap_bio_read_folio_range_sync(const struct iomap_iter *iter, struct folio *folio, loff_t pos, size_t len); diff --git a/fs/iomap/ioend.c b/fs/iomap/ioend.c index 4da248ff99f8..53630920adf8 100644 --- a/fs/iomap/ioend.c +++ b/fs/iomap/ioend.c @@ -34,7 +34,6 @@ struct iomap_ioend *iomap_init_ioend(struct inode *inode, ioend->io_private = NULL; return ioend; } -EXPORT_SYMBOL_GPL(iomap_init_ioend); /* * We're now finished for good with this ioend structure. Update the folio diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 1db6f3640c53..4ed11eb072db 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c @@ -583,9 +583,7 @@ xfs_bio_submit_read( const struct iomap_iter *iter, struct iomap_read_folio_ctx *ctx) { - xfs_ioend_submit_read(iter->inode, ctx->read_ctx, - ctx->read_ctx_file_offset, - iomap_ioend_flags(&iter->iomap)); + xfs_ioend_submit_read(iter->inode, ctx->read_ctx); ctx->read_ctx = NULL; } @@ -593,6 +591,7 @@ static const struct iomap_read_ops xfs_iomap_read_ops = { .read_folio_range = iomap_bio_read_folio_range, .submit_read = xfs_bio_submit_read, .bio_set = &iomap_ioend_bioset, + .submit_flags = IOMAP_SUBMIT_F_IOEND, }; static inline const struct iomap_read_ops * diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ba46156128df..09f45af509e9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -180,13 +180,13 @@ xfs_dio_read_bounce_submit_io( struct bio *bio, loff_t file_offset) { - xfs_ioend_submit_read(iter->inode, bio, file_offset, - iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT); + xfs_ioend_submit_read(iter->inode, bio); } static const struct iomap_dio_ops xfs_dio_read_bounce_ops = { .submit_io = xfs_dio_read_bounce_submit_io, .bio_set = &iomap_ioend_bioset, + .submit_flags = IOMAP_SUBMIT_F_IOEND, }; static int @@ -714,7 +714,6 @@ xfs_dio_zoned_submit_io( struct xfs_mount *mp = XFS_I(iter->inode)->i_mount; struct xfs_zone_alloc_ctx *ac = iter->private; xfs_filblks_t count_fsb; - struct iomap_ioend *ioend; count_fsb = XFS_B_TO_FSB(mp, bio->bi_iter.bi_size); if (count_fsb > ac->reserved_blocks) { @@ -728,15 +727,14 @@ xfs_dio_zoned_submit_io( ac->reserved_blocks -= count_fsb; bio->bi_end_io = xfs_end_bio; - ioend = iomap_init_ioend(iter->inode, bio, file_offset, - iomap_ioend_flags(&iter->iomap) | IOMAP_IOEND_DIRECT); - xfs_zone_alloc_and_submit(ioend, &ac->open_zone); + xfs_zone_alloc_and_submit(iomap_ioend_from_bio(bio), &ac->open_zone); } static const struct iomap_dio_ops xfs_dio_zoned_write_ops = { .bio_set = &iomap_ioend_bioset, .submit_io = xfs_dio_zoned_submit_io, .end_io = xfs_zoned_dio_write_end_io, + .submit_flags = IOMAP_SUBMIT_F_IOEND, }; /* diff --git a/fs/xfs/xfs_ioend.c b/fs/xfs/xfs_ioend.c index 7f4a4a95afe5..900e9593e32d 100644 --- a/fs/xfs/xfs_ioend.c +++ b/fs/xfs/xfs_ioend.c @@ -123,23 +123,19 @@ xfs_end_io_read( void xfs_ioend_submit_read( struct inode *inode, - struct bio *bio, - loff_t file_offset, - u16 ioend_flags) + struct bio *bio) { struct xfs_inode *ip = XFS_I(inode); - struct xfs_mount *mp = ip->i_mount; - struct iomap_ioend *ioend; + struct iomap_ioend *ioend = iomap_ioend_from_bio(bio); - ioend = iomap_init_ioend(inode, bio, file_offset, ioend_flags); - if ((ioend_flags & IOMAP_IOEND_DIRECT) && - READ_ONCE(mp->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) { + if ((ioend->io_flags & IOMAP_IOEND_DIRECT) && + READ_ONCE(ip->i_mount->m_read_bounce) == XFS_READ_BOUNCE_ALWAYS) { iomap_bounce_read(ioend, bdev_logical_block_size(bio->bi_bdev), xfs_bounce_submit_ioend); return; } - if (ioend_flags & IOMAP_IOEND_INTEGRITY) + if (ioend->io_flags & IOMAP_IOEND_INTEGRITY) fs_bio_integrity_alloc(bio); bio->bi_end_io = xfs_end_io_read; bio_set_flag(bio, BIO_COMPLETE_IN_TASK); diff --git a/fs/xfs/xfs_ioend.h b/fs/xfs/xfs_ioend.h index 7c2a1ea3e6ed..684ca93eef36 100644 --- a/fs/xfs/xfs_ioend.h +++ b/fs/xfs/xfs_ioend.h @@ -12,7 +12,6 @@ static inline bool xfs_ioend_is_append(struct iomap_ioend *ioend) } void xfs_end_bio(struct bio *bio); -void xfs_ioend_submit_read(struct inode *inode, struct bio *bio, - loff_t file_offset, u16 ioend_flags); +void xfs_ioend_submit_read(struct inode *inode, struct bio *bio); #endif /* __XFS_IOEND_H */ diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 6db4f005fdfc..e75801b9f26f 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -589,8 +589,6 @@ struct iomap_writepage_ctx { void *wb_ctx; /* pending writeback context */ }; -struct iomap_ioend *iomap_init_ioend(struct inode *inode, struct bio *bio, - loff_t file_offset, u16 ioend_flags); struct iomap_ioend *iomap_split_ioend(struct iomap_ioend *ioend, unsigned int max_len, bool is_append); void iomap_finish_ioends(struct iomap_ioend *ioend, int error); @@ -615,6 +613,16 @@ void iomap_bounce_read(struct iomap_ioend *orig_ioend, unsigned int minsize, void iomap_bounce_read_end_io(struct iomap_ioend *ioend, struct bio *orig_bio, int error); +/* + * Initialize the ioend for the bio before submitting. The file system + * needs to provide a bio_set with enough room for an ioend. + */ +#ifdef CONFIG_BLOCK +#define IOMAP_SUBMIT_F_IOEND (1U << 0) +#else +#define IOMAP_SUBMIT_F_IOEND 0 +#endif + struct iomap_read_folio_ctx { const struct iomap_read_ops *ops; struct folio *cur_folio; @@ -649,6 +657,11 @@ struct iomap_read_ops { * can be allocated from the provided bio_set. */ struct bio_set *bio_set; + + /* + * Optional, for IOMAP_SUBMIT_F_* flags. + */ + unsigned int submit_flags; }; /* @@ -672,6 +685,11 @@ struct iomap_dio_ops { * iomap_dio_bio_end_io. */ struct bio_set *bio_set; + + /* + * Optional, for IOMAP_SUBMIT_F_* flags. + */ + unsigned int submit_flags; }; /* -- 2.53.0