提交 550cdeb3 编写于 作者: Q Qu Wenruo 提交者: David Sterba

btrfs: raid56: avoid double for loop inside raid56_rmw_stripe()

This function doesn't even utilize full stripe skip, just iterate all
the data sectors is definitely enough.
Signed-off-by: NQu Wenruo <wqu@suse.com>
Reviewed-by: NDavid Sterba <dsterba@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 aee35e4b
...@@ -1547,9 +1547,9 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio) ...@@ -1547,9 +1547,9 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
{ {
int bios_to_read = 0; int bios_to_read = 0;
struct bio_list bio_list; struct bio_list bio_list;
const int nr_data_sectors = rbio->stripe_nsectors * rbio->nr_data;
int ret; int ret;
int sectornr; int total_sector_nr;
int stripe;
struct bio *bio; struct bio *bio;
bio_list_init(&bio_list); bio_list_init(&bio_list);
...@@ -1561,19 +1561,17 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio) ...@@ -1561,19 +1561,17 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
index_rbio_pages(rbio); index_rbio_pages(rbio);
atomic_set(&rbio->error, 0); atomic_set(&rbio->error, 0);
/* /* Build a list of bios to read all the missing data sectors. */
* build a list of bios to read all the missing parts of this for (total_sector_nr = 0; total_sector_nr < nr_data_sectors;
* stripe total_sector_nr++) {
*/
for (stripe = 0; stripe < rbio->nr_data; stripe++) {
for (sectornr = 0; sectornr < rbio->stripe_nsectors; sectornr++) {
struct sector_ptr *sector; struct sector_ptr *sector;
int stripe = total_sector_nr / rbio->stripe_nsectors;
int sectornr = total_sector_nr % rbio->stripe_nsectors;
/* /*
* We want to find all the sectors missing from the * We want to find all the sectors missing from the rbio and
* rbio and read them from the disk. If * sector_in_rbio() * read them from the disk. If sector_in_rbio() finds a page
* finds a page in the bio list we don't need to read * in the bio list we don't need to read it off the stripe.
* it off the stripe.
*/ */
sector = sector_in_rbio(rbio, stripe, sectornr, 1); sector = sector_in_rbio(rbio, stripe, sectornr, 1);
if (sector) if (sector)
...@@ -1581,8 +1579,8 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio) ...@@ -1581,8 +1579,8 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
sector = rbio_stripe_sector(rbio, stripe, sectornr); sector = rbio_stripe_sector(rbio, stripe, sectornr);
/* /*
* The bio cache may have handed us an uptodate page. * The bio cache may have handed us an uptodate page. If so,
* If so, be happy and use it. * use it.
*/ */
if (sector->uptodate) if (sector->uptodate)
continue; continue;
...@@ -1593,7 +1591,6 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio) ...@@ -1593,7 +1591,6 @@ static int raid56_rmw_stripe(struct btrfs_raid_bio *rbio)
if (ret) if (ret)
goto cleanup; goto cleanup;
} }
}
bios_to_read = bio_list_size(&bio_list); bios_to_read = bio_list_size(&bio_list);
if (!bios_to_read) { if (!bios_to_read) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册