@@ -1479,40 +1479,23 @@ static u32
1479
1479
iomap_finish_ioend (struct iomap_ioend * ioend , int error )
1480
1480
{
1481
1481
struct inode * inode = ioend -> io_inode ;
1482
- struct bio * bio = & ioend -> io_inline_bio ;
1483
- struct bio * last = ioend -> io_bio , * next ;
1484
- u64 start = bio -> bi_iter .bi_sector ;
1485
- loff_t offset = ioend -> io_offset ;
1486
- bool quiet = bio_flagged (bio , BIO_QUIET );
1482
+ struct bio * bio = & ioend -> io_bio ;
1483
+ struct folio_iter fi ;
1487
1484
u32 folio_count = 0 ;
1488
1485
1489
- for (bio = & ioend -> io_inline_bio ; bio ; bio = next ) {
1490
- struct folio_iter fi ;
1491
-
1492
- /*
1493
- * For the last bio, bi_private points to the ioend, so we
1494
- * need to explicitly end the iteration here.
1495
- */
1496
- if (bio == last )
1497
- next = NULL ;
1498
- else
1499
- next = bio -> bi_private ;
1500
-
1501
- /* walk all folios in bio, ending page IO on them */
1502
- bio_for_each_folio_all (fi , bio ) {
1503
- iomap_finish_folio_write (inode , fi .folio , fi .length ,
1504
- error );
1505
- folio_count ++ ;
1506
- }
1507
- bio_put (bio );
1486
+ /* walk all folios in bio, ending page IO on them */
1487
+ bio_for_each_folio_all (fi , bio ) {
1488
+ iomap_finish_folio_write (inode , fi .folio , fi .length , error );
1489
+ folio_count ++ ;
1508
1490
}
1509
- /* The ioend has been freed by bio_put() */
1510
1491
1511
- if (unlikely (error && !quiet )) {
1492
+ if (unlikely (error && !bio_flagged ( bio , BIO_QUIET ) )) {
1512
1493
printk_ratelimited (KERN_ERR
1513
1494
"%s: writeback error on inode %lu, offset %lld, sector %llu" ,
1514
- inode -> i_sb -> s_id , inode -> i_ino , offset , start );
1495
+ inode -> i_sb -> s_id , inode -> i_ino ,
1496
+ ioend -> io_offset , ioend -> io_sector );
1515
1497
}
1498
+ bio_put (bio ); /* frees the ioend */
1516
1499
return folio_count ;
1517
1500
}
1518
1501
@@ -1553,7 +1536,7 @@ EXPORT_SYMBOL_GPL(iomap_finish_ioends);
1553
1536
static bool
1554
1537
iomap_ioend_can_merge (struct iomap_ioend * ioend , struct iomap_ioend * next )
1555
1538
{
1556
- if (ioend -> io_bio -> bi_status != next -> io_bio -> bi_status )
1539
+ if (ioend -> io_bio . bi_status != next -> io_bio . bi_status )
1557
1540
return false;
1558
1541
if ((ioend -> io_flags & IOMAP_F_SHARED ) ^
1559
1542
(next -> io_flags & IOMAP_F_SHARED ))
@@ -1618,9 +1601,8 @@ EXPORT_SYMBOL_GPL(iomap_sort_ioends);
1618
1601
1619
1602
static void iomap_writepage_end_bio (struct bio * bio )
1620
1603
{
1621
- struct iomap_ioend * ioend = bio -> bi_private ;
1622
-
1623
- iomap_finish_ioend (ioend , blk_status_to_errno (bio -> bi_status ));
1604
+ iomap_finish_ioend (iomap_ioend_from_bio (bio ),
1605
+ blk_status_to_errno (bio -> bi_status ));
1624
1606
}
1625
1607
1626
1608
/*
@@ -1635,9 +1617,6 @@ static int
1635
1617
iomap_submit_ioend (struct iomap_writepage_ctx * wpc , struct iomap_ioend * ioend ,
1636
1618
int error )
1637
1619
{
1638
- ioend -> io_bio -> bi_private = ioend ;
1639
- ioend -> io_bio -> bi_end_io = iomap_writepage_end_bio ;
1640
-
1641
1620
if (wpc -> ops -> prepare_ioend )
1642
1621
error = wpc -> ops -> prepare_ioend (ioend , error );
1643
1622
if (error ) {
@@ -1647,12 +1626,12 @@ iomap_submit_ioend(struct iomap_writepage_ctx *wpc, struct iomap_ioend *ioend,
1647
1626
* as there is only one reference to the ioend at this point in
1648
1627
* time.
1649
1628
*/
1650
- ioend -> io_bio -> bi_status = errno_to_blk_status (error );
1651
- bio_endio (ioend -> io_bio );
1629
+ ioend -> io_bio . bi_status = errno_to_blk_status (error );
1630
+ bio_endio (& ioend -> io_bio );
1652
1631
return error ;
1653
1632
}
1654
1633
1655
- submit_bio (ioend -> io_bio );
1634
+ submit_bio (& ioend -> io_bio );
1656
1635
return 0 ;
1657
1636
}
1658
1637
@@ -1666,44 +1645,22 @@ static struct iomap_ioend *iomap_alloc_ioend(struct iomap_writepage_ctx *wpc,
1666
1645
REQ_OP_WRITE | wbc_to_write_flags (wbc ),
1667
1646
GFP_NOFS , & iomap_ioend_bioset );
1668
1647
bio -> bi_iter .bi_sector = iomap_sector (& wpc -> iomap , pos );
1648
+ bio -> bi_end_io = iomap_writepage_end_bio ;
1669
1649
wbc_init_bio (wbc , bio );
1670
1650
1671
- ioend = container_of (bio , struct iomap_ioend , io_inline_bio );
1651
+ ioend = iomap_ioend_from_bio (bio );
1672
1652
INIT_LIST_HEAD (& ioend -> io_list );
1673
1653
ioend -> io_type = wpc -> iomap .type ;
1674
1654
ioend -> io_flags = wpc -> iomap .flags ;
1675
1655
ioend -> io_inode = inode ;
1676
1656
ioend -> io_size = 0 ;
1677
1657
ioend -> io_offset = pos ;
1678
- ioend -> io_bio = bio ;
1679
1658
ioend -> io_sector = bio -> bi_iter .bi_sector ;
1680
1659
1681
1660
wpc -> nr_folios = 0 ;
1682
1661
return ioend ;
1683
1662
}
1684
1663
1685
- /*
1686
- * Allocate a new bio, and chain the old bio to the new one.
1687
- *
1688
- * Note that we have to perform the chaining in this unintuitive order
1689
- * so that the bi_private linkage is set up in the right direction for the
1690
- * traversal in iomap_finish_ioend().
1691
- */
1692
- static struct bio *
1693
- iomap_chain_bio (struct bio * prev )
1694
- {
1695
- struct bio * new ;
1696
-
1697
- new = bio_alloc (prev -> bi_bdev , BIO_MAX_VECS , prev -> bi_opf , GFP_NOFS );
1698
- bio_clone_blkg_association (new , prev );
1699
- new -> bi_iter .bi_sector = bio_end_sector (prev );
1700
-
1701
- bio_chain (prev , new );
1702
- bio_get (prev ); /* for iomap_finish_ioend */
1703
- submit_bio (prev );
1704
- return new ;
1705
- }
1706
-
1707
1664
static bool iomap_can_add_to_ioend (struct iomap_writepage_ctx * wpc , loff_t pos )
1708
1665
{
1709
1666
if ((wpc -> iomap .flags & IOMAP_F_SHARED ) !=
@@ -1714,7 +1671,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos)
1714
1671
if (pos != wpc -> ioend -> io_offset + wpc -> ioend -> io_size )
1715
1672
return false;
1716
1673
if (iomap_sector (& wpc -> iomap , pos ) !=
1717
- bio_end_sector (wpc -> ioend -> io_bio ))
1674
+ bio_end_sector (& wpc -> ioend -> io_bio ))
1718
1675
return false;
1719
1676
/*
1720
1677
* Limit ioend bio chain lengths to minimise IO completion latency. This
@@ -1739,15 +1696,14 @@ static void iomap_add_to_ioend(struct iomap_writepage_ctx *wpc,
1739
1696
size_t poff = offset_in_folio (folio , pos );
1740
1697
1741
1698
if (!wpc -> ioend || !iomap_can_add_to_ioend (wpc , pos )) {
1699
+ new_ioend :
1742
1700
if (wpc -> ioend )
1743
1701
list_add (& wpc -> ioend -> io_list , iolist );
1744
1702
wpc -> ioend = iomap_alloc_ioend (wpc , wbc , inode , pos );
1745
1703
}
1746
1704
1747
- if (!bio_add_folio (wpc -> ioend -> io_bio , folio , len , poff )) {
1748
- wpc -> ioend -> io_bio = iomap_chain_bio (wpc -> ioend -> io_bio );
1749
- bio_add_folio_nofail (wpc -> ioend -> io_bio , folio , len , poff );
1750
- }
1705
+ if (!bio_add_folio (& wpc -> ioend -> io_bio , folio , len , poff ))
1706
+ goto new_ioend ;
1751
1707
1752
1708
if (ifs )
1753
1709
atomic_add (len , & ifs -> write_bytes_pending );
@@ -1978,7 +1934,7 @@ EXPORT_SYMBOL_GPL(iomap_writepages);
1978
1934
static int __init iomap_init (void )
1979
1935
{
1980
1936
return bioset_init (& iomap_ioend_bioset , 4 * (PAGE_SIZE / SECTOR_SIZE ),
1981
- offsetof(struct iomap_ioend , io_inline_bio ),
1937
+ offsetof(struct iomap_ioend , io_bio ),
1982
1938
BIOSET_NEED_BVECS );
1983
1939
}
1984
1940
fs_initcall (iomap_init );
0 commit comments