@@ -1569,7 +1569,7 @@ u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend)
15691569 return folio_count ;
15701570}
15711571
1572- static void iomap_writepage_end_bio (struct bio * bio )
1572+ static void ioend_writeback_end_bio (struct bio * bio )
15731573{
15741574 struct iomap_ioend * ioend = iomap_ioend_from_bio (bio );
15751575
@@ -1578,42 +1578,30 @@ static void iomap_writepage_end_bio(struct bio *bio)
15781578}
15791579
15801580/*
1581- * Submit an ioend.
1582- *
1583- * If @error is non-zero, it means that we have a situation where some part of
1584- * the submission process has failed after we've marked pages for writeback.
1585- * We cannot cancel ioend directly in that case, so call the bio end I/O handler
1586- * with the error status here to run the normal I/O completion handler to clear
1587- * the writeback bit and let the file system proess the errors.
1581+ * We cannot cancel the ioend directly in case of an error, so call the bio end
1582+ * I/O handler with the error status here to run the normal I/O completion
1583+ * handler.
15881584 */
1589- static int iomap_submit_ioend (struct iomap_writepage_ctx * wpc , int error )
1585+ int iomap_ioend_writeback_submit (struct iomap_writepage_ctx * wpc , int error )
15901586{
1591- if (!wpc -> ioend )
1592- return error ;
1587+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
15931588
1594- /*
1595- * Let the file systems prepare the I/O submission and hook in an I/O
1596- * comletion handler. This also needs to happen in case after a
1597- * failure happened so that the file system end I/O handler gets called
1598- * to clean up.
1599- */
1600- if (wpc -> ops -> submit_ioend ) {
1601- error = wpc -> ops -> submit_ioend (wpc , error );
1602- } else {
1603- if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1604- error = - EIO ;
1605- if (!error )
1606- submit_bio (& wpc -> ioend -> io_bio );
1607- }
1589+ if (!ioend -> io_bio .bi_end_io )
1590+ ioend -> io_bio .bi_end_io = ioend_writeback_end_bio ;
1591+
1592+ if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1593+ error = - EIO ;
16081594
16091595 if (error ) {
1610- wpc -> ioend -> io_bio .bi_status = errno_to_blk_status (error );
1611- bio_endio (& wpc -> ioend -> io_bio );
1596+ ioend -> io_bio .bi_status = errno_to_blk_status (error );
1597+ bio_endio (& ioend -> io_bio );
1598+ return error ;
16121599 }
16131600
1614- wpc -> ioend = NULL ;
1615- return error ;
1601+ submit_bio ( & ioend -> io_bio ) ;
1602+ return 0 ;
16161603}
1604+ EXPORT_SYMBOL_GPL (iomap_ioend_writeback_submit );
16171605
16181606static struct iomap_ioend * iomap_alloc_ioend (struct iomap_writepage_ctx * wpc ,
16191607 loff_t pos , u16 ioend_flags )
@@ -1624,7 +1612,6 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16241612 REQ_OP_WRITE | wbc_to_write_flags (wpc -> wbc ),
16251613 GFP_NOFS , & iomap_ioend_bioset );
16261614 bio -> bi_iter .bi_sector = iomap_sector (& wpc -> iomap , pos );
1627- bio -> bi_end_io = iomap_writepage_end_bio ;
16281615 bio -> bi_write_hint = wpc -> inode -> i_write_hint ;
16291616 wbc_init_bio (wpc -> wbc , bio );
16301617 wpc -> nr_folios = 0 ;
@@ -1634,16 +1621,17 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16341621static bool iomap_can_add_to_ioend (struct iomap_writepage_ctx * wpc , loff_t pos ,
16351622 u16 ioend_flags )
16361623{
1624+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
1625+
16371626 if (ioend_flags & IOMAP_IOEND_BOUNDARY )
16381627 return false;
16391628 if ((ioend_flags & IOMAP_IOEND_NOMERGE_FLAGS ) !=
1640- (wpc -> ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
1629+ (ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
16411630 return false;
1642- if (pos != wpc -> ioend -> io_offset + wpc -> ioend -> io_size )
1631+ if (pos != ioend -> io_offset + ioend -> io_size )
16431632 return false;
16441633 if (!(wpc -> iomap .flags & IOMAP_F_ANON_WRITE ) &&
1645- iomap_sector (& wpc -> iomap , pos ) !=
1646- bio_end_sector (& wpc -> ioend -> io_bio ))
1634+ iomap_sector (& wpc -> iomap , pos ) != bio_end_sector (& ioend -> io_bio ))
16471635 return false;
16481636 /*
16491637 * Limit ioend bio chain lengths to minimise IO completion latency. This
@@ -1669,6 +1657,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
16691657ssize_t iomap_add_to_ioend (struct iomap_writepage_ctx * wpc , struct folio * folio ,
16701658 loff_t pos , loff_t end_pos , unsigned int dirty_len )
16711659{
1660+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
16721661 struct iomap_folio_state * ifs = folio -> private ;
16731662 size_t poff = offset_in_folio (folio , pos );
16741663 unsigned int ioend_flags = 0 ;
@@ -1699,15 +1688,17 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
16991688 if (pos == wpc -> iomap .offset && (wpc -> iomap .flags & IOMAP_F_BOUNDARY ))
17001689 ioend_flags |= IOMAP_IOEND_BOUNDARY ;
17011690
1702- if (!wpc -> ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
1691+ if (!ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
17031692new_ioend :
1704- error = iomap_submit_ioend (wpc , 0 );
1705- if (error )
1706- return error ;
1707- wpc -> ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
1693+ if (ioend ) {
1694+ error = wpc -> ops -> writeback_submit (wpc , 0 );
1695+ if (error )
1696+ return error ;
1697+ }
1698+ wpc -> wb_ctx = ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
17081699 }
17091700
1710- if (!bio_add_folio (& wpc -> ioend -> io_bio , folio , map_len , poff ))
1701+ if (!bio_add_folio (& ioend -> io_bio , folio , map_len , poff ))
17111702 goto new_ioend ;
17121703
17131704 if (ifs )
@@ -1754,9 +1745,9 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
17541745 * Note that this defeats the ability to chain the ioends of
17551746 * appending writes.
17561747 */
1757- wpc -> ioend -> io_size += map_len ;
1758- if (wpc -> ioend -> io_offset + wpc -> ioend -> io_size > end_pos )
1759- wpc -> ioend -> io_size = end_pos - wpc -> ioend -> io_offset ;
1748+ ioend -> io_size += map_len ;
1749+ if (ioend -> io_offset + ioend -> io_size > end_pos )
1750+ ioend -> io_size = end_pos - ioend -> io_offset ;
17601751
17611752 wbc_account_cgroup_owner (wpc -> wbc , folio , map_len );
17621753 return map_len ;
@@ -1951,6 +1942,18 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
19511942
19521943 while ((folio = writeback_iter (mapping , wpc -> wbc , folio , & error )))
19531944 error = iomap_writepage_map (wpc , folio );
1954- return iomap_submit_ioend (wpc , error );
1945+
1946+ /*
1947+ * If @error is non-zero, it means that we have a situation where some
1948+ * part of the submission process has failed after we've marked pages
1949+ * for writeback.
1950+ *
1951+ * We cannot cancel the writeback directly in that case, so always call
1952+ * ->writeback_submit to run the I/O completion handler to clear the
1953+ * writeback bit and let the file system proess the errors.
1954+ */
1955+ if (wpc -> wb_ctx )
1956+ return wpc -> ops -> writeback_submit (wpc , error );
1957+ return error ;
19551958}
19561959EXPORT_SYMBOL_GPL (iomap_writepages );
0 commit comments