Skip to content

Commit 2e8ac30

Browse files
majianpengneilbrown
authored andcommitted
md/raid456: When read error cannot be recovered, record bad block
We may not be able to fix a bad block if: - the array is degraded - the over-write fails. In these cases we currently eject the device, but we should record a bad block if possible. Signed-off-by: majianpeng <[email protected]> Signed-off-by: NeilBrown <[email protected]>
1 parent 0232605 commit 2e8ac30

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/md/raid5.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,6 +1743,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
17431743
} else {
17441744
const char *bdn = bdevname(rdev->bdev, b);
17451745
int retry = 0;
1746+
int set_bad = 0;
17461747

17471748
clear_bit(R5_UPTODATE, &sh->dev[i].flags);
17481749
atomic_inc(&rdev->read_errors);
@@ -1754,24 +1755,26 @@ static void raid5_end_read_request(struct bio * bi, int error)
17541755
mdname(conf->mddev),
17551756
(unsigned long long)s,
17561757
bdn);
1757-
else if (conf->mddev->degraded >= conf->max_degraded)
1758+
else if (conf->mddev->degraded >= conf->max_degraded) {
1759+
set_bad = 1;
17581760
printk_ratelimited(
17591761
KERN_WARNING
17601762
"md/raid:%s: read error not correctable "
17611763
"(sector %llu on %s).\n",
17621764
mdname(conf->mddev),
17631765
(unsigned long long)s,
17641766
bdn);
1765-
else if (test_bit(R5_ReWrite, &sh->dev[i].flags))
1767+
} else if (test_bit(R5_ReWrite, &sh->dev[i].flags)) {
17661768
/* Oh, no!!! */
1769+
set_bad = 1;
17671770
printk_ratelimited(
17681771
KERN_WARNING
17691772
"md/raid:%s: read error NOT corrected!! "
17701773
"(sector %llu on %s).\n",
17711774
mdname(conf->mddev),
17721775
(unsigned long long)s,
17731776
bdn);
1774-
else if (atomic_read(&rdev->read_errors)
1777+
} else if (atomic_read(&rdev->read_errors)
17751778
> conf->max_nr_stripes)
17761779
printk(KERN_WARNING
17771780
"md/raid:%s: Too many read errors, failing device %s.\n",
@@ -1783,7 +1786,11 @@ static void raid5_end_read_request(struct bio * bi, int error)
17831786
else {
17841787
clear_bit(R5_ReadError, &sh->dev[i].flags);
17851788
clear_bit(R5_ReWrite, &sh->dev[i].flags);
1786-
md_error(conf->mddev, rdev);
1789+
if (!(set_bad
1790+
&& test_bit(In_sync, &rdev->flags)
1791+
&& rdev_set_badblocks(
1792+
rdev, sh->sector, STRIPE_SECTORS, 0)))
1793+
md_error(conf->mddev, rdev);
17871794
}
17881795
}
17891796
rdev_dec_pending(rdev, conf->mddev);

0 commit comments

Comments
 (0)