@@ -1574,7 +1574,7 @@ u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend)
15741574 return folio_count ;
15751575}
15761576
1577- static void iomap_writepage_end_bio (struct bio * bio )
1577+ static void ioend_writeback_end_bio (struct bio * bio )
15781578{
15791579 struct iomap_ioend * ioend = iomap_ioend_from_bio (bio );
15801580
@@ -1583,42 +1583,30 @@ static void iomap_writepage_end_bio(struct bio *bio)
15831583}
15841584
15851585/*
1586- * Submit an ioend.
1587- *
1588- * If @error is non-zero, it means that we have a situation where some part of
1589- * the submission process has failed after we've marked pages for writeback.
1590- * We cannot cancel ioend directly in that case, so call the bio end I/O handler
1591- * with the error status here to run the normal I/O completion handler to clear
1592- * the writeback bit and let the file system proess the errors.
1586+ * We cannot cancel the ioend directly in case of an error, so call the bio end
1587+ * I/O handler with the error status here to run the normal I/O completion
1588+ * handler.
15931589 */
1594- static int iomap_submit_ioend (struct iomap_writepage_ctx * wpc , int error )
1590+ int iomap_ioend_writeback_submit (struct iomap_writepage_ctx * wpc , int error )
15951591{
1596- if (!wpc -> ioend )
1597- return error ;
1592+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
15981593
1599- /*
1600- * Let the file systems prepare the I/O submission and hook in an I/O
1601- * comletion handler. This also needs to happen in case after a
1602- * failure happened so that the file system end I/O handler gets called
1603- * to clean up.
1604- */
1605- if (wpc -> ops -> submit_ioend ) {
1606- error = wpc -> ops -> submit_ioend (wpc , error );
1607- } else {
1608- if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1609- error = - EIO ;
1610- if (!error )
1611- submit_bio (& wpc -> ioend -> io_bio );
1612- }
1594+ if (!ioend -> io_bio .bi_end_io )
1595+ ioend -> io_bio .bi_end_io = ioend_writeback_end_bio ;
1596+
1597+ if (WARN_ON_ONCE (wpc -> iomap .flags & IOMAP_F_ANON_WRITE ))
1598+ error = - EIO ;
16131599
16141600 if (error ) {
1615- wpc -> ioend -> io_bio .bi_status = errno_to_blk_status (error );
1616- bio_endio (& wpc -> ioend -> io_bio );
1601+ ioend -> io_bio .bi_status = errno_to_blk_status (error );
1602+ bio_endio (& ioend -> io_bio );
1603+ return error ;
16171604 }
16181605
1619- wpc -> ioend = NULL ;
1620- return error ;
1606+ submit_bio ( & ioend -> io_bio ) ;
1607+ return 0 ;
16211608}
1609+ EXPORT_SYMBOL_GPL (iomap_ioend_writeback_submit );
16221610
16231611static struct iomap_ioend * iomap_alloc_ioend (struct iomap_writepage_ctx * wpc ,
16241612 loff_t pos , u16 ioend_flags )
@@ -1629,7 +1617,6 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16291617 REQ_OP_WRITE | wbc_to_write_flags (wpc -> wbc ),
16301618 GFP_NOFS , & iomap_ioend_bioset );
16311619 bio -> bi_iter .bi_sector = iomap_sector (& wpc -> iomap , pos );
1632- bio -> bi_end_io = iomap_writepage_end_bio ;
16331620 bio -> bi_write_hint = wpc -> inode -> i_write_hint ;
16341621 wbc_init_bio (wpc -> wbc , bio );
16351622 wpc -> nr_folios = 0 ;
@@ -1639,16 +1626,17 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
16391626static bool iomap_can_add_to_ioend (struct iomap_writepage_ctx * wpc , loff_t pos ,
16401627 u16 ioend_flags )
16411628{
1629+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
1630+
16421631 if (ioend_flags & IOMAP_IOEND_BOUNDARY )
16431632 return false;
16441633 if ((ioend_flags & IOMAP_IOEND_NOMERGE_FLAGS ) !=
1645- (wpc -> ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
1634+ (ioend -> io_flags & IOMAP_IOEND_NOMERGE_FLAGS ))
16461635 return false;
1647- if (pos != wpc -> ioend -> io_offset + wpc -> ioend -> io_size )
1636+ if (pos != ioend -> io_offset + ioend -> io_size )
16481637 return false;
16491638 if (!(wpc -> iomap .flags & IOMAP_F_ANON_WRITE ) &&
1650- iomap_sector (& wpc -> iomap , pos ) !=
1651- bio_end_sector (& wpc -> ioend -> io_bio ))
1639+ iomap_sector (& wpc -> iomap , pos ) != bio_end_sector (& ioend -> io_bio ))
16521640 return false;
16531641 /*
16541642 * Limit ioend bio chain lengths to minimise IO completion latency. This
@@ -1674,6 +1662,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,
16741662ssize_t iomap_add_to_ioend (struct iomap_writepage_ctx * wpc , struct folio * folio ,
16751663 loff_t pos , loff_t end_pos , unsigned int dirty_len )
16761664{
1665+ struct iomap_ioend * ioend = wpc -> wb_ctx ;
16771666 struct iomap_folio_state * ifs = folio -> private ;
16781667 size_t poff = offset_in_folio (folio , pos );
16791668 unsigned int ioend_flags = 0 ;
@@ -1704,15 +1693,17 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
17041693 if (pos == wpc -> iomap .offset && (wpc -> iomap .flags & IOMAP_F_BOUNDARY ))
17051694 ioend_flags |= IOMAP_IOEND_BOUNDARY ;
17061695
1707- if (!wpc -> ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
1696+ if (!ioend || !iomap_can_add_to_ioend (wpc , pos , ioend_flags )) {
17081697new_ioend :
1709- error = iomap_submit_ioend (wpc , 0 );
1710- if (error )
1711- return error ;
1712- wpc -> ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
1698+ if (ioend ) {
1699+ error = wpc -> ops -> writeback_submit (wpc , 0 );
1700+ if (error )
1701+ return error ;
1702+ }
1703+ wpc -> wb_ctx = ioend = iomap_alloc_ioend (wpc , pos , ioend_flags );
17131704 }
17141705
1715- if (!bio_add_folio (& wpc -> ioend -> io_bio , folio , map_len , poff ))
1706+ if (!bio_add_folio (& ioend -> io_bio , folio , map_len , poff ))
17161707 goto new_ioend ;
17171708
17181709 if (ifs )
@@ -1759,9 +1750,9 @@ ssize_t iomap_add_to_ioend(struct iomap_writepage_ctx *wpc, struct folio *folio,
17591750 * Note that this defeats the ability to chain the ioends of
17601751 * appending writes.
17611752 */
1762- wpc -> ioend -> io_size += map_len ;
1763- if (wpc -> ioend -> io_offset + wpc -> ioend -> io_size > end_pos )
1764- wpc -> ioend -> io_size = end_pos - wpc -> ioend -> io_offset ;
1753+ ioend -> io_size += map_len ;
1754+ if (ioend -> io_offset + ioend -> io_size > end_pos )
1755+ ioend -> io_size = end_pos - ioend -> io_offset ;
17651756
17661757 wbc_account_cgroup_owner (wpc -> wbc , folio , map_len );
17671758 return map_len ;
@@ -1956,6 +1947,18 @@ iomap_writepages(struct iomap_writepage_ctx *wpc)
19561947
19571948 while ((folio = writeback_iter (mapping , wpc -> wbc , folio , & error )))
19581949 error = iomap_writepage_map (wpc , folio );
1959- return iomap_submit_ioend (wpc , error );
1950+
1951+ /*
1952+ * If @error is non-zero, it means that we have a situation where some
1953+ * part of the submission process has failed after we've marked pages
1954+ * for writeback.
1955+ *
1956+ * We cannot cancel the writeback directly in that case, so always call
1957+ * ->writeback_submit to run the I/O completion handler to clear the
1958+ * writeback bit and let the file system proess the errors.
1959+ */
1960+ if (wpc -> wb_ctx )
1961+ return wpc -> ops -> writeback_submit (wpc , error );
1962+ return error ;
19601963}
19611964EXPORT_SYMBOL_GPL (iomap_writepages );
0 commit comments