Skip to content

Commit 02efa3a

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: raid56: fold rmw_read_wait_recover into rmw_read_bios
There is very little extra code in rmw_read_bios, and a large part of it is the superfluous extra cleanup of the bio list. Merge the two functions, and only clean up the bio list after it has been added to but before it has been emptied again by submit_read_wait_bio_list. Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d838d05 commit 02efa3a

File tree

1 file changed

+23
-46
lines changed

1 file changed

+23
-46
lines changed

fs/btrfs/raid56.c

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,39 +1524,6 @@ static void submit_read_wait_bio_list(struct btrfs_raid_bio *rbio,
15241524
wait_event(rbio->io_wait, atomic_read(&rbio->stripes_pending) == 0);
15251525
}
15261526

1527-
static int rmw_assemble_read_bios(struct btrfs_raid_bio *rbio,
1528-
struct bio_list *bio_list)
1529-
{
1530-
int total_sector_nr;
1531-
int ret = 0;
1532-
1533-
ASSERT(bio_list_size(bio_list) == 0);
1534-
1535-
/*
1536-
* Build a list of bios to read all sectors (including data and P/Q).
1537-
*
1538-
* This behavior is to compensate the later csum verification and
1539-
* recovery.
1540-
*/
1541-
for (total_sector_nr = 0; total_sector_nr < rbio->nr_sectors;
1542-
total_sector_nr++) {
1543-
struct sector_ptr *sector;
1544-
int stripe = total_sector_nr / rbio->stripe_nsectors;
1545-
int sectornr = total_sector_nr % rbio->stripe_nsectors;
1546-
1547-
sector = rbio_stripe_sector(rbio, stripe, sectornr);
1548-
ret = rbio_add_io_sector(rbio, bio_list, sector,
1549-
stripe, sectornr, REQ_OP_READ);
1550-
if (ret)
1551-
goto cleanup;
1552-
}
1553-
return 0;
1554-
1555-
cleanup:
1556-
bio_list_put(bio_list);
1557-
return ret;
1558-
}
1559-
15601527
static int alloc_rbio_data_pages(struct btrfs_raid_bio *rbio)
15611528
{
15621529
const int data_pages = rbio->nr_data * rbio->stripe_npages;
@@ -2176,10 +2143,9 @@ static void fill_data_csums(struct btrfs_raid_bio *rbio)
21762143

21772144
static int rmw_read_wait_recover(struct btrfs_raid_bio *rbio)
21782145
{
2179-
struct bio_list bio_list;
2180-
int ret;
2181-
2182-
bio_list_init(&bio_list);
2146+
struct bio_list bio_list = BIO_EMPTY_LIST;
2147+
int total_sector_nr;
2148+
int ret = 0;
21832149

21842150
/*
21852151
* Fill the data csums we need for data verification. We need to fill
@@ -2188,21 +2154,32 @@ static int rmw_read_wait_recover(struct btrfs_raid_bio *rbio)
21882154
*/
21892155
fill_data_csums(rbio);
21902156

2191-
ret = rmw_assemble_read_bios(rbio, &bio_list);
2192-
if (ret < 0)
2193-
goto out;
2157+
/*
2158+
* Build a list of bios to read all sectors (including data and P/Q).
2159+
*
2160+
* This behavior is to compensate the later csum verification and recovery.
2161+
*/
2162+
for (total_sector_nr = 0; total_sector_nr < rbio->nr_sectors;
2163+
total_sector_nr++) {
2164+
struct sector_ptr *sector;
2165+
int stripe = total_sector_nr / rbio->stripe_nsectors;
2166+
int sectornr = total_sector_nr % rbio->stripe_nsectors;
21942167

2195-
submit_read_wait_bio_list(rbio, &bio_list);
2168+
sector = rbio_stripe_sector(rbio, stripe, sectornr);
2169+
ret = rbio_add_io_sector(rbio, &bio_list, sector,
2170+
stripe, sectornr, REQ_OP_READ);
2171+
if (ret) {
2172+
bio_list_put(&bio_list);
2173+
return ret;
2174+
}
2175+
}
21962176

21972177
/*
21982178
* We may or may not have any corrupted sectors (including missing dev
21992179
* and csum mismatch), just let recover_sectors() to handle them all.
22002180
*/
2201-
ret = recover_sectors(rbio);
2202-
return ret;
2203-
out:
2204-
bio_list_put(&bio_list);
2205-
return ret;
2181+
submit_read_wait_bio_list(rbio, &bio_list);
2182+
return recover_sectors(rbio);
22062183
}
22072184

22082185
static void raid_wait_write_end_io(struct bio *bio)

0 commit comments

Comments
 (0)