always initialize ioends in the core iomap code
Subsystems (3)
Hi all,
this series moves initialization of optional ioends from file systems code (currently only XFS) into the core iomap code. This prepares for supporting file data checksums in iomap which will be implemented in XFS soon, but I think it also generally improves the architecture by having a more clear layering.
Diffstat:
fs/iomap/bio.c | 3 +-- fs/iomap/buffered-io.c | 19 +++++++++++++++---- fs/iomap/direct-io.c | 13 ++++++++++--- fs/iomap/internal.h | 4 ++++ 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 ++++++++++++++++++++-- 10 files changed, 62 insertions(+), 32 deletions(-)
PATCH 1/2 iomap: factor out a iomap_read_submit helper
Prepare for adding more submit code by de-duplicating the logic around the method call.
--- fs/iomap/bio.c | 3 +-- fs/iomap/buffered-io.c | 13 +++++++++---- fs/iomap/internal.h | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-)
fs/iomap/bio.c +1 -2
@@ -75,8 +75,7 @@ static void iomap_read_alloc_bio(const struct iomap_iter *iter,struct bio *bio;/* Submit the existing range if there was one. */ -if (ctx->read_ctx) - ctx->ops->submit_read (iter, ctx); +iomap_read_submit (iter, ctx);/* Same as readahead_gfp_mask: */ if (ctx->rac)
fs/iomap/buffered-io.c +9 -4
@@ -554,6 +554,13 @@ 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) + ctx->ops->submit_read (iter, ctx); +} +static int iomap_read_folio_iter (struct iomap_iter *iter,struct iomap_read_folio_ctx *ctx,size_t *bytes_submitted) {
@@ -675,8 +682,7 @@ void iomap_read_folio(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx,while ((ret =iomap_iter (&iter, next)) >0 ) { iter.status =iomap_read_folio_iter (&iter, ctx, &bytes_submitted); -if (ctx->read_ctx && ctx->ops->submit_read) - ctx->ops->submit_read (&iter, ctx); +iomap_read_submit (&iter, ctx); }if (ctx->cur_folio)
@@ -751,8 +757,7 @@ void iomap_readahead(iomap_iter_next_fn next, struct iomap_read_folio_ctx *ctx,while (iomap_iter (&iter, next) >0 ) { iter.status =iomap_readahead_iter (&iter, ctx, &cur_bytes_submitted); -if (ctx->read_ctx && ctx->ops->submit_read) - ctx->ops->submit_read (&iter, ctx); +iomap_read_submit (&iter, ctx); }if (ctx->cur_folio)
fs/iomap/internal.h +2 -0
@@ -29,6 +29,8 @@ static inline bool iomap_bio_has_room(const struct iomap *iomap,u32 iomap_finish_ioend_buffered_read (struct iomap_ioend *ioend);u32 iomap_finish_ioend_direct (struct iomap_ioend *ioend); +void iomap_read_submit (const struct iomap_iter *iter, +struct iomap_read_folio_ctx *ctx);#ifdef CONFIG_BLOCK int iomap_bio_read_folio_range_sync (const struct iomap_iter *iter,struct folio *folio,loff_t pos,size_t len);
Signature · 1 line
2.53.0
PATCH 2/2 iomap: move optional ioend initialization to the core
In reply to Christoph HellwigFor 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.
--- 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(-)
fs/iomap/buffered-io.c +7 -1
@@ -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,
fs/iomap/direct-io.c +10 -3
@@ -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 );
fs/iomap/internal.h +2 -0
@@ -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);
fs/iomap/ioend.c +0 -1
@@ -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
fs/xfs/xfs_aops.c +2 -3
@@ -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 *
fs/xfs/xfs_file.c +4 -6
@@ -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 , };/*
fs/xfs/xfs_ioend.c +5 -9
@@ -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 );
fs/xfs/xfs_ioend.h +1 -2
@@ -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 */
include/linux/iomap.h +20 -2
@@ -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; };/*
Signature · 1 line
2.53.0