@@ -1534,28 +1534,6 @@ static struct bio *raid10_split_bio(struct r10conf *conf,
1534
1534
return bio ;
1535
1535
}
1536
1536
1537
- static void raid_end_discard_bio (struct r10bio * r10bio )
1538
- {
1539
- struct r10conf * conf = r10bio -> mddev -> private ;
1540
- struct r10bio * first_r10bio ;
1541
-
1542
- while (atomic_dec_and_test (& r10bio -> remaining )) {
1543
-
1544
- allow_barrier (conf );
1545
-
1546
- if (!test_bit (R10BIO_Discard , & r10bio -> state )) {
1547
- first_r10bio = (struct r10bio * )r10bio -> master_bio ;
1548
- free_r10bio (r10bio );
1549
- r10bio = first_r10bio ;
1550
- } else {
1551
- md_write_end (r10bio -> mddev );
1552
- bio_endio (r10bio -> master_bio );
1553
- free_r10bio (r10bio );
1554
- break ;
1555
- }
1556
- }
1557
- }
1558
-
1559
1537
static void raid10_end_discard_request (struct bio * bio )
1560
1538
{
1561
1539
struct r10bio * r10_bio = bio -> bi_private ;
@@ -1582,7 +1560,11 @@ static void raid10_end_discard_request(struct bio *bio)
1582
1560
rdev = conf -> mirrors [dev ].rdev ;
1583
1561
}
1584
1562
1585
- raid_end_discard_bio (r10_bio );
1563
+ if (atomic_dec_and_test (& r10_bio -> remaining )) {
1564
+ md_write_end (r10_bio -> mddev );
1565
+ raid_end_bio_io (r10_bio );
1566
+ }
1567
+
1586
1568
rdev_dec_pending (rdev , conf -> mddev );
1587
1569
}
1588
1570
@@ -1595,9 +1577,7 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
1595
1577
{
1596
1578
struct r10conf * conf = mddev -> private ;
1597
1579
struct geom * geo = & conf -> geo ;
1598
- struct r10bio * r10_bio , * first_r10bio ;
1599
- int far_copies = geo -> far_copies ;
1600
- bool first_copy = true;
1580
+ struct r10bio * r10_bio ;
1601
1581
1602
1582
int disk ;
1603
1583
sector_t chunk ;
@@ -1636,20 +1616,30 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
1636
1616
if (bio_sectors (bio ) < stripe_size * 2 )
1637
1617
goto out ;
1638
1618
1639
- /* For far and far offset layout, if bio is not aligned with stripe size,
1640
- * it splits the part that is not aligned with strip size.
1619
+ /* For far offset layout, if bio is not aligned with stripe size, it splits
1620
+ * the part that is not aligned with strip size.
1641
1621
*/
1642
1622
div_u64_rem (bio_start , stripe_size , & remainder );
1643
- if (( far_copies > 1 ) && remainder ) {
1623
+ if (geo -> far_offset && remainder ) {
1644
1624
split_size = stripe_size - remainder ;
1645
1625
bio = raid10_split_bio (conf , bio , split_size , false);
1646
1626
}
1647
1627
div_u64_rem (bio_end , stripe_size , & remainder );
1648
- if (( far_copies > 1 ) && remainder ) {
1628
+ if (geo -> far_offset && remainder ) {
1649
1629
split_size = bio_sectors (bio ) - remainder ;
1650
1630
bio = raid10_split_bio (conf , bio , split_size , true);
1651
1631
}
1652
1632
1633
+ r10_bio = mempool_alloc (& conf -> r10bio_pool , GFP_NOIO );
1634
+ r10_bio -> mddev = mddev ;
1635
+ r10_bio -> state = 0 ;
1636
+ r10_bio -> sectors = 0 ;
1637
+ memset (r10_bio -> devs , 0 , sizeof (r10_bio -> devs [0 ]) * geo -> raid_disks );
1638
+
1639
+ wait_blocked_dev (mddev , r10_bio );
1640
+
1641
+ r10_bio -> master_bio = bio ;
1642
+
1653
1643
bio_start = bio -> bi_iter .bi_sector ;
1654
1644
bio_end = bio_end_sector (bio );
1655
1645
@@ -1675,28 +1665,6 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
1675
1665
end_disk_offset = (bio_end & geo -> chunk_mask ) +
1676
1666
(last_stripe_index << geo -> chunk_shift );
1677
1667
1678
- retry_discard :
1679
- r10_bio = mempool_alloc (& conf -> r10bio_pool , GFP_NOIO );
1680
- r10_bio -> mddev = mddev ;
1681
- r10_bio -> state = 0 ;
1682
- r10_bio -> sectors = 0 ;
1683
- memset (r10_bio -> devs , 0 , sizeof (r10_bio -> devs [0 ]) * geo -> raid_disks );
1684
- wait_blocked_dev (mddev , r10_bio );
1685
-
1686
- /* For far layout it needs more than one r10bio to cover all regions.
1687
- * Inspired by raid10_sync_request, we can use the first r10bio->master_bio
1688
- * to record the discard bio. Other r10bio->master_bio record the first
1689
- * r10bio. The first r10bio only release after all other r10bios finish.
1690
- * The discard bio returns only first r10bio finishes
1691
- */
1692
- if (first_copy ) {
1693
- r10_bio -> master_bio = bio ;
1694
- set_bit (R10BIO_Discard , & r10_bio -> state );
1695
- first_copy = false;
1696
- first_r10bio = r10_bio ;
1697
- } else
1698
- r10_bio -> master_bio = (struct bio * )first_r10bio ;
1699
-
1700
1668
rcu_read_lock ();
1701
1669
for (disk = 0 ; disk < geo -> raid_disks ; disk ++ ) {
1702
1670
struct md_rdev * rdev = rcu_dereference (conf -> mirrors [disk ].rdev );
@@ -1787,19 +1755,11 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
1787
1755
}
1788
1756
}
1789
1757
1790
- if (!geo -> far_offset && -- far_copies ) {
1791
- first_stripe_index += geo -> stride >> geo -> chunk_shift ;
1792
- start_disk_offset += geo -> stride ;
1793
- last_stripe_index += geo -> stride >> geo -> chunk_shift ;
1794
- end_disk_offset += geo -> stride ;
1795
- atomic_inc (& first_r10bio -> remaining );
1796
- raid_end_discard_bio (r10_bio );
1797
- wait_barrier (conf );
1798
- goto retry_discard ;
1758
+ if (atomic_dec_and_test (& r10_bio -> remaining )) {
1759
+ md_write_end (r10_bio -> mddev );
1760
+ raid_end_bio_io (r10_bio );
1799
1761
}
1800
1762
1801
- raid_end_discard_bio (r10_bio );
1802
-
1803
1763
return 0 ;
1804
1764
out :
1805
1765
allow_barrier (conf );
0 commit comments