@@ -1571,7 +1571,7 @@ u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend)
15711571 return folio_count ;
15721572}
15731573
1574- static void iomap_writepage_end_bio (struct bio * bio )
1574+ static void ioend_writeback_end_bio (struct bio * bio )
15751575{
15761576 struct iomap_ioend * ioend = iomap_ioend_from_bio (bio );
15771577
@@ -1580,42 +1580,30 @@ static void iomap_writepage_end_bio(struct bio *bio)
15801580}
15811581
15821582/*
1583- * Submit an ioend.
1584- *
1585- * If @error is non-zero, it means that we have a situation where some part of
1586- * the submission process has failed after we've marked pages for writeback.
1587- * We cannot cancel ioend directly in that case, so call the bio end I/O handler
1588- * with the error status here to run the normal I/O completion handler to clear
1589- * the writeback bit and let the file system proess the errors.
1583+ * We cannot cancel the ioend directly in case of an error, so call the bio end
1584+ * I/O handler with the error status here to run the normal I/O completion
1585+ * handler.
15901586 */
1591- static int iomap_submit_ioend (struct iomap_writepage_ctx * wpc , int error )
1587+ int iomap_ioend_writeback_submit (struct iomap_writepage_ctx * wpc , int error )
15921588{
1593- if (!wpc -> ioend )
1594- return error ;
1589+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
15951590
1596- /*
1597- * Let the file systems prepare the I/O submission and hook in an I/O
1598- * comletion handler. This also needs to happen in case after a
1599- * failure happened so that the file system end I/O handler gets called
1600- * to clean up.
1601- */
1602- if (wpc -> ops -> submit_ioend ) {
1603- error = wpc -> ops -> submit_ioend (wpc , error );
1604- } else {
1605- if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1606- error = - EIO ;
1607- if (!error )
1608- submit_bio (& wpc -> ioend -> io_bio );
1609- }
1591+ if (!ioend -> io_bio .bi_end_io )
1592+ ioend -> io_bio .bi_end_io = ioend_writeback_end_bio ;
1593+
1594+ if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1595+ error = - EIO ;
16101596
16111597 if (error ) {
1612- wpc -> ioend -> io_bio .bi_status = errno_to_blk_status (error );
1613- bio_endio (& wpc -> ioend -> io_bio );
1598+ ioend -> io_bio .bi_status = errno_to_blk_status (error );
1599+ bio_endio (& ioend -> io_bio );
1600+ return error ;
16141601 }
16151602
1616- wpc -> ioend = NULL ;
1617- return error ;
1603+ submit_bio ( & ioend -> io_bio ) ;
1604+ return 0 ;
16181605}
1606+ EXPORT_SYMBOL_GPL (iomap_ioend_writeback_submit );
16191607
16201608static struct iomap_ioend * iomap_alloc_ioend (struct iomap_writepage_ctx * wpc ,
16211609 loff_t pos , u16 ioend_flags )
@@ -1626,7 +1614,6 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16261614 REQ_OP_WRITE | wbc_to_write_flags (wpc -> wbc ),
16271615 GFP_NOFS , & iomap_ioend_bioset );
16281616 bio -> bi_iter .bi_sector = iomap_sector (& wpc -> iomap , pos );
1629- bio -> bi_end_io = iomap_writepage_end_bio ;
16301617 bio -> bi_write_hint = wpc -> inode -> i_write_hint ;
16311618 wbc_init_bio (wpc -> wbc , bio );
16321619 wpc -> nr_folios = 0 ;
@@ -1636,16 +1623,17 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16361623static bool iomap_can_add_to_ioend (struct iomap_writepage_ctx * wpc , loff_t pos ,
16371624 u16 ioend_flags )
16381625{
1626+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
1627+
16391628 if (ioend_flags & IOMAP_IOEND_BOUNDARY )
16401629 return false;
16411630 if ((ioend_flags & IOMAP_IOEND_NOMERGE_FLAGS ) !=
1642- (wpc -> ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
1631+ (ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
16431632 return false;
1644- if (pos != wpc -> ioend -> io_offset + wpc -> ioend -> io_size )
1633+ if (pos != ioend -> io_offset + ioend -> io_size )
16451634 return false;
16461635 if (!(wpc -> iomap .flags & IOMAP_F_ANON_WRITE ) &&
1647- iomap_sector (& wpc -> iomap , pos ) !=
1648- bio_end_sector (& wpc -> ioend -> io_bio ))
1636+ iomap_sector (& wpc -> iomap , pos ) != bio_end_sector (& ioend -> io_bio ))
16491637 return false;
16501638 /*
16511639 * Limit ioend bio chain lengths to minimise IO completion latency. This
@@ -1671,6 +1659,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
16711659ssize_t iomap_add_to_ioend (struct iomap_writepage_ctx * wpc , struct folio * folio ,
16721660 loff_t pos , loff_t end_pos , unsigned int dirty_len )
16731661{
1662+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
16741663 struct iomap_folio_state * ifs = folio -> private ;
16751664 size_t poff = offset_in_folio (folio , pos );
16761665 unsigned int ioend_flags = 0 ;
@@ -1701,15 +1690,17 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
17011690 if (pos == wpc -> iomap .offset && (wpc -> iomap .flags & IOMAP_F_BOUNDARY ))
17021691 ioend_flags |= IOMAP_IOEND_BOUNDARY ;
17031692
1704- if (!wpc -> ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
1693+ if (!ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
17051694new_ioend :
1706- error = iomap_submit_ioend (wpc , 0 );
1707- if (error )
1708- return error ;
1709- wpc -> ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
1695+ if (ioend ) {
1696+ error = wpc -> ops -> writeback_submit (wpc , 0 );
1697+ if (error )
1698+ return error ;
1699+ }
1700+ wpc -> wb_ctx = ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
17101701 }
17111702
1712- if (!bio_add_folio (& wpc -> ioend -> io_bio , folio , map_len , poff ))
1703+ if (!bio_add_folio (& ioend -> io_bio , folio , map_len , poff ))
17131704 goto new_ioend ;
17141705
17151706 if (ifs )
@@ -1756,9 +1747,9 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
17561747 * Note that this defeats the ability to chain the ioends of
17571748 * appending writes.
17581749 */
1759- wpc -> ioend -> io_size += map_len ;
1760- if (wpc -> ioend -> io_offset + wpc -> ioend -> io_size > end_pos )
1761- wpc -> ioend -> io_size = end_pos - wpc -> ioend -> io_offset ;
1750+ ioend -> io_size += map_len ;
1751+ if (ioend -> io_offset + ioend -> io_size > end_pos )
1752+ ioend -> io_size = end_pos - ioend -> io_offset ;
17621753
17631754 wbc_account_cgroup_owner (wpc -> wbc , folio , map_len );
17641755 return map_len ;
@@ -1953,6 +1944,18 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
19531944
19541945 while ((folio = writeback_iter (mapping , wpc -> wbc , folio , & error )))
19551946 error = iomap_writepage_map (wpc , folio );
1956- return iomap_submit_ioend (wpc , error );
1947+
1948+ /*
1949+ * If @error is non-zero, it means that we have a situation where some
1950+ * part of the submission process has failed after we've marked pages
1951+ * for writeback.
1952+ *
1953+ * We cannot cancel the writeback directly in that case, so always call
1954+ * ->writeback_submit to run the I/O completion handler to clear the
1955+ * writeback bit and let the file system proess the errors.
1956+ */
1957+ if (wpc -> wb_ctx )
1958+ return wpc -> ops -> writeback_submit (wpc , error );
1959+ return error ;
19571960}
19581961EXPORT_SYMBOL_GPL (iomap_writepages );
0 commit comments