Skip to content

Commit e875ece

Browse files
committed
md/raid10 record bad blocks as needed during recovery.
When recovering one or more devices, if all the good devices have bad blocks we should record a bad block on the device being rebuilt. If this fails, we need to abort the recovery. To ensure we don't think that we aborted later than we actually did, we need to move the check for MD_RECOVERY_INTR earlier in md_do_sync, in particular before mddev->curr_resync is updated. Signed-off-by: NeilBrown <neilb@suse.de>
1 parent 40c356c commit e875ece

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

‎drivers/md/md.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7165,11 +7165,14 @@ void md_do_sync(mddev_t *mddev)
71657165
atomic_add(sectors, &mddev->recovery_active);
71667166
}
71677167

7168+
if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
7169+
break;
7170+
71687171
j += sectors;
71697172
if (j>1) mddev->curr_resync = j;
71707173
mddev->curr_mark_cnt = io_sectors;
71717174
if (last_check == 0)
7172-
/* this is the earliers that rebuilt will be
7175+
/* this is the earliest that rebuild will be
71737176
* visible in /proc/mdstat
71747177
*/
71757178
md_new_event(mddev);
@@ -7178,10 +7181,6 @@ void md_do_sync(mddev_t *mddev)
71787181
continue;
71797182

71807183
last_check = io_sectors;
7181-
7182-
if (test_bit(MD_RECOVERY_INTR, &mddev->recovery))
7183-
break;
7184-
71857184
repeat:
71867185
if (time_after_eq(jiffies, mark[last_mark] + SYNC_MARK_STEP )) {
71877186
/* step marks */

‎drivers/md/raid10.c‎

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,14 +2005,15 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr,
20052005
max_sync = RESYNC_PAGES << (PAGE_SHIFT-9);
20062006
if (!test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
20072007
/* recovery... the complicated one */
2008-
int j, k;
2008+
int j;
20092009
r10_bio = NULL;
20102010

20112011
for (i=0 ; i<conf->raid_disks; i++) {
20122012
int still_degraded;
20132013
r10bio_t *rb2;
20142014
sector_t sect;
20152015
int must_sync;
2016+
int any_working;
20162017

20172018
if (conf->mirrors[i].rdev == NULL ||
20182019
test_bit(In_sync, &conf->mirrors[i].rdev->flags))
@@ -2064,7 +2065,9 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr,
20642065
must_sync = bitmap_start_sync(mddev->bitmap, sect,
20652066
&sync_blocks, still_degraded);
20662067

2068+
any_working = 0;
20672069
for (j=0; j<conf->copies;j++) {
2070+
int k;
20682071
int d = r10_bio->devs[j].devnum;
20692072
mdk_rdev_t *rdev;
20702073
sector_t sector, first_bad;
@@ -2073,6 +2076,7 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr,
20732076
!test_bit(In_sync, &conf->mirrors[d].rdev->flags))
20742077
continue;
20752078
/* This is where we read from */
2079+
any_working = 1;
20762080
rdev = conf->mirrors[d].rdev;
20772081
sector = r10_bio->devs[j].addr;
20782082

@@ -2121,16 +2125,35 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr,
21212125
break;
21222126
}
21232127
if (j == conf->copies) {
2124-
/* Cannot recover, so abort the recovery */
2128+
/* Cannot recover, so abort the recovery or
2129+
* record a bad block */
21252130
put_buf(r10_bio);
21262131
if (rb2)
21272132
atomic_dec(&rb2->remaining);
21282133
r10_bio = rb2;
2129-
if (!test_and_set_bit(MD_RECOVERY_INTR,
2130-
&mddev->recovery))
2131-
printk(KERN_INFO "md/raid10:%s: insufficient "
2132-
"working devices for recovery.\n",
2133-
mdname(mddev));
2134+
if (any_working) {
2135+
/* problem is that there are bad blocks
2136+
* on other device(s)
2137+
*/
2138+
int k;
2139+
for (k = 0; k < conf->copies; k++)
2140+
if (r10_bio->devs[k].devnum == i)
2141+
break;
2142+
if (!rdev_set_badblocks(
2143+
conf->mirrors[i].rdev,
2144+
r10_bio->devs[k].addr,
2145+
max_sync, 0))
2146+
any_working = 0;
2147+
}
2148+
if (!any_working) {
2149+
if (!test_and_set_bit(MD_RECOVERY_INTR,
2150+
&mddev->recovery))
2151+
printk(KERN_INFO "md/raid10:%s: insufficient "
2152+
"working devices for recovery.\n",
2153+
mdname(mddev));
2154+
conf->mirrors[i].recovery_disabled
2155+
= mddev->recovery_disabled;
2156+
}
21342157
break;
21352158
}
21362159
}
@@ -2290,7 +2313,8 @@ static sector_t sync_request(mddev_t *mddev, sector_t sector_nr,
22902313
return sectors_skipped + nr_sectors;
22912314
giveup:
22922315
/* There is nowhere to write, so all non-sync
2293-
* drives must be failed, so try the next chunk...
2316+
* drives must be failed or in resync, all drives
2317+
* have a bad block, so try the next chunk...
22942318
*/
22952319
if (sector_nr + max_sync < max_sector)
22962320
max_sector = sector_nr + max_sync;

0 commit comments

Comments
 (0)