@@ -620,6 +620,44 @@ static int choose_first_rdev(struct r1conf *conf, struct r1bio *r1_bio,
620
620
return -1 ;
621
621
}
622
622
623
+ static int choose_bb_rdev (struct r1conf * conf , struct r1bio * r1_bio ,
624
+ int * max_sectors )
625
+ {
626
+ sector_t this_sector = r1_bio -> sector ;
627
+ int best_disk = -1 ;
628
+ int best_len = 0 ;
629
+ int disk ;
630
+
631
+ for (disk = 0 ; disk < conf -> raid_disks * 2 ; disk ++ ) {
632
+ struct md_rdev * rdev ;
633
+ int len ;
634
+ int read_len ;
635
+
636
+ if (r1_bio -> bios [disk ] == IO_BLOCKED )
637
+ continue ;
638
+
639
+ rdev = conf -> mirrors [disk ].rdev ;
640
+ if (!rdev || test_bit (Faulty , & rdev -> flags ) ||
641
+ test_bit (WriteMostly , & rdev -> flags ))
642
+ continue ;
643
+
644
+ /* keep track of the disk with the most readable sectors. */
645
+ len = r1_bio -> sectors ;
646
+ read_len = raid1_check_read_range (rdev , this_sector , & len );
647
+ if (read_len > best_len ) {
648
+ best_disk = disk ;
649
+ best_len = read_len ;
650
+ }
651
+ }
652
+
653
+ if (best_disk != -1 ) {
654
+ * max_sectors = best_len ;
655
+ update_read_sectors (conf , best_disk , this_sector , best_len );
656
+ }
657
+
658
+ return best_disk ;
659
+ }
660
+
623
661
static int choose_slow_rdev (struct r1conf * conf , struct r1bio * r1_bio ,
624
662
int * max_sectors )
625
663
{
@@ -708,8 +746,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
708
746
709
747
for (disk = 0 ; disk < conf -> raid_disks * 2 ; disk ++ ) {
710
748
sector_t dist ;
711
- sector_t first_bad ;
712
- int bad_sectors ;
713
749
unsigned int pending ;
714
750
715
751
rdev = conf -> mirrors [disk ].rdev ;
@@ -722,36 +758,8 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
722
758
continue ;
723
759
if (test_bit (WriteMostly , & rdev -> flags ))
724
760
continue ;
725
- /* This is a reasonable device to use. It might
726
- * even be best.
727
- */
728
- if (is_badblock (rdev , this_sector , sectors ,
729
- & first_bad , & bad_sectors )) {
730
- if (best_dist < MaxSector )
731
- /* already have a better device */
732
- continue ;
733
- if (first_bad <= this_sector ) {
734
- /* cannot read here. If this is the 'primary'
735
- * device, then we must not read beyond
736
- * bad_sectors from another device..
737
- */
738
- bad_sectors -= (this_sector - first_bad );
739
- if (best_good_sectors > sectors )
740
- best_good_sectors = sectors ;
741
-
742
- } else {
743
- sector_t good_sectors = first_bad - this_sector ;
744
- if (good_sectors > best_good_sectors ) {
745
- best_good_sectors = good_sectors ;
746
- best_disk = disk ;
747
- }
748
- }
761
+ if (rdev_has_badblock (rdev , this_sector , sectors ))
749
762
continue ;
750
- } else {
751
- if ((sectors > best_good_sectors ) && (best_disk >= 0 ))
752
- best_disk = -1 ;
753
- best_good_sectors = sectors ;
754
- }
755
763
756
764
if (best_disk >= 0 )
757
765
/* At least two disks to choose from so failfast is OK */
@@ -843,6 +851,15 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
843
851
if (best_disk >= 0 )
844
852
return best_disk ;
845
853
854
+ /*
855
+ * If we are here it means we didn't find a perfectly good disk so
856
+ * now spend a bit more time trying to find one with the most good
857
+ * sectors.
858
+ */
859
+ disk = choose_bb_rdev (conf , r1_bio , max_sectors );
860
+ if (disk >= 0 )
861
+ return disk ;
862
+
846
863
return choose_slow_rdev (conf , r1_bio , max_sectors );
847
864
}
848
865
0 commit comments