Skip to content

Commit f109207

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid1-10: factor out a new helper raid1_should_read_first()
If resync is in progress, read_balance() should find the first usable disk, otherwise, data could be inconsistent after resync is done. raid1 and raid10 implement the same checking, hence factor out the checking to make code cleaner. Noted that raid1 is using 'mddev->recovery_cp', which is updated after all resync IO is done, while raid10 is using 'conf->next_resync', which is inaccurate because raid10 update it before submitting resync IO. Fortunately, raid10 read IO can't concurrent with resync IO, hence there is no problem. And this patch also switch raid10 to use 'mddev->recovery_cp'. Co-developed-by: Paul Luse <[email protected]> Signed-off-by: Paul Luse <[email protected]> Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Xiao Ni <[email protected]> Signed-off-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f29841f commit f109207

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

drivers/md/raid1-10.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,23 @@ static inline int raid1_check_read_range(struct md_rdev *rdev,
276276
*len = first_bad + bad_sectors - this_sector;
277277
return 0;
278278
}
279+
280+
/*
281+
* Check if read should choose the first rdev.
282+
*
283+
* Balance on the whole device if no resync is going on (recovery is ok) or
284+
* below the resync window. Otherwise, take the first readable disk.
285+
*/
286+
static inline bool raid1_should_read_first(struct mddev *mddev,
287+
sector_t this_sector, int len)
288+
{
289+
if ((mddev->recovery_cp < this_sector + len))
290+
return true;
291+
292+
if (mddev_is_clustered(mddev) &&
293+
md_cluster_ops->area_resyncing(mddev, READ, this_sector,
294+
this_sector + len))
295+
return true;
296+
297+
return false;
298+
}

drivers/md/raid1.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
605605
struct md_rdev *rdev;
606606
int choose_first;
607607

608-
/*
609-
* Check if we can balance. We can balance on the whole
610-
* device if no resync is going on, or below the resync window.
611-
* We take the first readable disk when above the resync window.
612-
*/
613608
retry:
614609
sectors = r1_bio->sectors;
615610
best_disk = -1;
@@ -619,16 +614,10 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
619614
best_pending_disk = -1;
620615
min_pending = UINT_MAX;
621616
best_good_sectors = 0;
617+
choose_first = raid1_should_read_first(conf->mddev, this_sector,
618+
sectors);
622619
clear_bit(R1BIO_FailFast, &r1_bio->state);
623620

624-
if ((conf->mddev->recovery_cp < this_sector + sectors) ||
625-
(mddev_is_clustered(conf->mddev) &&
626-
md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector,
627-
this_sector + sectors)))
628-
choose_first = 1;
629-
else
630-
choose_first = 0;
631-
632621
for (disk = 0 ; disk < conf->raid_disks * 2 ; disk++) {
633622
sector_t dist;
634623
sector_t first_bad;

drivers/md/raid10.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -748,17 +748,8 @@ static struct md_rdev *read_balance(struct r10conf *conf,
748748
best_good_sectors = 0;
749749
do_balance = 1;
750750
clear_bit(R10BIO_FailFast, &r10_bio->state);
751-
/*
752-
* Check if we can balance. We can balance on the whole
753-
* device if no resync is going on (recovery is ok), or below
754-
* the resync window. We take the first readable disk when
755-
* above the resync window.
756-
*/
757-
if ((conf->mddev->recovery_cp < MaxSector
758-
&& (this_sector + sectors >= conf->next_resync)) ||
759-
(mddev_is_clustered(conf->mddev) &&
760-
md_cluster_ops->area_resyncing(conf->mddev, READ, this_sector,
761-
this_sector + sectors)))
751+
752+
if (raid1_should_read_first(conf->mddev, this_sector, sectors))
762753
do_balance = 0;
763754

764755
for (slot = 0; slot < conf->copies ; slot++) {

0 commit comments

Comments
 (0)