In preparation for using this function without an iomap_writepage_ctx, pass in the iomap and ioend. Also simplify iomap_add_to_ioend() by using the iomap & ioend directly. Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> --- fs/iomap/buffered-io.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 03c7c97bc871..c91259530ac1 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1273,25 +1273,24 @@ iomap_chain_bio(struct bio *prev) return new; } -static bool -iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t offset, - sector_t sector) +static bool iomap_can_add_to_ioend(struct iomap *iomap, + struct iomap_ioend *ioend, loff_t offset, sector_t sector) { - if ((wpc->iomap.flags & IOMAP_F_SHARED) != - (wpc->ioend->io_flags & IOMAP_F_SHARED)) + if ((iomap->flags & IOMAP_F_SHARED) != + (ioend->io_flags & IOMAP_F_SHARED)) return false; - if (wpc->iomap.type != wpc->ioend->io_type) + if (iomap->type != ioend->io_type) return false; - if (offset != wpc->ioend->io_offset + wpc->ioend->io_size) + if (offset != ioend->io_offset + ioend->io_size) return false; - if (sector != bio_end_sector(wpc->ioend->io_bio)) + if (sector != bio_end_sector(ioend->io_bio)) return false; /* * Limit ioend bio chain lengths to minimise IO completion latency. This * also prevents long tight loops ending page writeback on all the * folios in the ioend. */ - if (wpc->ioend->io_folios >= IOEND_BATCH_SIZE) + if (ioend->io_folios >= IOEND_BATCH_SIZE) return false; return true; } @@ -1306,24 +1305,26 @@ iomap_add_to_ioend(struct inode *inode, loff_t pos, struct folio *folio, struct writeback_control *wbc, struct list_head *iolist) { struct iomap *iomap = &wpc->iomap; + struct iomap_ioend *ioend = wpc->ioend; sector_t sector = iomap_sector(iomap, pos); unsigned len = i_blocksize(inode); size_t poff = offset_in_folio(folio, pos); - if (!wpc->ioend || !iomap_can_add_to_ioend(wpc, pos, sector)) { - if (wpc->ioend) - list_add(&wpc->ioend->io_list, iolist); - wpc->ioend = iomap_alloc_ioend(inode, iomap, pos, sector, wbc); + if (!ioend || !iomap_can_add_to_ioend(iomap, ioend, pos, sector)) { + if (ioend) + list_add(&ioend->io_list, iolist); + ioend = iomap_alloc_ioend(inode, iomap, pos, sector, wbc); + wpc->ioend = ioend; } - if (!bio_add_folio(wpc->ioend->io_bio, folio, len, poff)) { - wpc->ioend->io_bio = iomap_chain_bio(wpc->ioend->io_bio); - bio_add_folio(wpc->ioend->io_bio, folio, len, poff); + if (!bio_add_folio(ioend->io_bio, folio, len, poff)) { + ioend->io_bio = iomap_chain_bio(ioend->io_bio); + bio_add_folio(ioend->io_bio, folio, len, poff); } if (iop) atomic_add(len, &iop->write_bytes_pending); - wpc->ioend->io_size += len; + ioend->io_size += len; wbc_account_cgroup_owner(wbc, &folio->page, len); } -- 2.34.1