@@ -579,6 +579,47 @@ static sector_t align_to_barrier_unit_end(sector_t start_sector,
579
579
return len ;
580
580
}
581
581
582
+ static void update_read_sectors (struct r1conf * conf , int disk ,
583
+ sector_t this_sector , int len )
584
+ {
585
+ struct raid1_info * info = & conf -> mirrors [disk ];
586
+
587
+ atomic_inc (& info -> rdev -> nr_pending );
588
+ if (info -> next_seq_sect != this_sector )
589
+ info -> seq_start = this_sector ;
590
+ info -> next_seq_sect = this_sector + len ;
591
+ }
592
+
593
+ static int choose_first_rdev (struct r1conf * conf , struct r1bio * r1_bio ,
594
+ int * max_sectors )
595
+ {
596
+ sector_t this_sector = r1_bio -> sector ;
597
+ int len = r1_bio -> sectors ;
598
+ int disk ;
599
+
600
+ for (disk = 0 ; disk < conf -> raid_disks * 2 ; disk ++ ) {
601
+ struct md_rdev * rdev ;
602
+ int read_len ;
603
+
604
+ if (r1_bio -> bios [disk ] == IO_BLOCKED )
605
+ continue ;
606
+
607
+ rdev = conf -> mirrors [disk ].rdev ;
608
+ if (!rdev || test_bit (Faulty , & rdev -> flags ))
609
+ continue ;
610
+
611
+ /* choose the first disk even if it has some bad blocks. */
612
+ read_len = raid1_check_read_range (rdev , this_sector , & len );
613
+ if (read_len > 0 ) {
614
+ update_read_sectors (conf , disk , this_sector , read_len );
615
+ * max_sectors = read_len ;
616
+ return disk ;
617
+ }
618
+ }
619
+
620
+ return -1 ;
621
+ }
622
+
582
623
/*
583
624
* This routine returns the disk from which the requested read should
584
625
* be done. There is a per-array 'next expected sequential IO' sector
@@ -603,7 +644,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
603
644
sector_t best_dist ;
604
645
unsigned int min_pending ;
605
646
struct md_rdev * rdev ;
606
- int choose_first ;
607
647
608
648
retry :
609
649
sectors = r1_bio -> sectors ;
@@ -614,10 +654,11 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
614
654
best_pending_disk = -1 ;
615
655
min_pending = UINT_MAX ;
616
656
best_good_sectors = 0 ;
617
- choose_first = raid1_should_read_first (conf -> mddev , this_sector ,
618
- sectors );
619
657
clear_bit (R1BIO_FailFast , & r1_bio -> state );
620
658
659
+ if (raid1_should_read_first (conf -> mddev , this_sector , sectors ))
660
+ return choose_first_rdev (conf , r1_bio , max_sectors );
661
+
621
662
for (disk = 0 ; disk < conf -> raid_disks * 2 ; disk ++ ) {
622
663
sector_t dist ;
623
664
sector_t first_bad ;
@@ -663,8 +704,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
663
704
* bad_sectors from another device..
664
705
*/
665
706
bad_sectors -= (this_sector - first_bad );
666
- if (choose_first && sectors > bad_sectors )
667
- sectors = bad_sectors ;
668
707
if (best_good_sectors > sectors )
669
708
best_good_sectors = sectors ;
670
709
@@ -674,8 +713,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
674
713
best_good_sectors = good_sectors ;
675
714
best_disk = disk ;
676
715
}
677
- if (choose_first )
678
- break ;
679
716
}
680
717
continue ;
681
718
} else {
@@ -690,10 +727,6 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
690
727
691
728
pending = atomic_read (& rdev -> nr_pending );
692
729
dist = abs (this_sector - conf -> mirrors [disk ].head_position );
693
- if (choose_first ) {
694
- best_disk = disk ;
695
- break ;
696
- }
697
730
/* Don't change to another disk for sequential reads */
698
731
if (conf -> mirrors [disk ].next_seq_sect == this_sector
699
732
|| dist == 0 ) {
@@ -769,13 +802,9 @@ static int read_balance(struct r1conf *conf, struct r1bio *r1_bio, int *max_sect
769
802
rdev = conf -> mirrors [best_disk ].rdev ;
770
803
if (!rdev )
771
804
goto retry ;
772
- atomic_inc (& rdev -> nr_pending );
773
- sectors = best_good_sectors ;
774
-
775
- if (conf -> mirrors [best_disk ].next_seq_sect != this_sector )
776
- conf -> mirrors [best_disk ].seq_start = this_sector ;
777
805
778
- conf -> mirrors [best_disk ].next_seq_sect = this_sector + sectors ;
806
+ sectors = best_good_sectors ;
807
+ update_read_sectors (conf , disk , this_sector , sectors );
779
808
}
780
809
* max_sectors = sectors ;
781
810
0 commit comments