Commit 63a7d0a9160421a23baac407847e484e8488d12a

Authored by Tomáš Hodek
Committed by Greg Kroah-Hartman
1 parent 97ec321278

md/raid1: fix read balance when a drive is write-mostly.

commit d1901ef099c38afd11add4cfb3312c02ef21ec4a upstream.

When a drive is marked write-mostly it should only be the
target of reads if there is no other option.

This behaviour was broken by

commit 9dedf60313fa4dddfd5b9b226a0ef12a512bf9dc
    md/raid1: read balance chooses idlest disk for SSD

which causes a write-mostly device to be *preferred* is some cases.

Restore correct behaviour by checking and setting
best_dist_disk and best_pending_disk rather than best_disk.

We only need to test one of these as they are both changed
from -1 or >=0 at the same time.

As we leave min_pending and best_dist unchanged, any non-write-mostly
device will appear better than the write-mostly device.

Reported-by: Tomáš Hodek <tomas.hodek@volny.cz>
Reported-by: Dark Penguin <darkpenguin@yandex.ru>
Signed-off-by: NeilBrown <neilb@suse.de>
Link: http://marc.info/?l=linux-raid&m=135982797322422
Fixes: 9dedf60313fa4dddfd5b9b226a0ef12a512bf9dc
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 3 additions and 2 deletions Side-by-side Diff

... ... @@ -560,7 +560,7 @@
560 560 if (test_bit(WriteMostly, &rdev->flags)) {
561 561 /* Don't balance among write-mostly, just
562 562 * use the first as a last resort */
563   - if (best_disk < 0) {
  563 + if (best_dist_disk < 0) {
564 564 if (is_badblock(rdev, this_sector, sectors,
565 565 &first_bad, &bad_sectors)) {
566 566 if (first_bad < this_sector)
... ... @@ -569,7 +569,8 @@
569 569 best_good_sectors = first_bad - this_sector;
570 570 } else
571 571 best_good_sectors = sectors;
572   - best_disk = disk;
  572 + best_dist_disk = disk;
  573 + best_pending_disk = disk;
573 574 }
574 575 continue;
575 576 }