aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/md/raid10.c83
1 files changed, 74 insertions, 9 deletions
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index b2c8998e1397..813f52464f8a 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -396,17 +396,29 @@ static void raid10_end_write_request(struct bio *bio, int error)
396 int dev; 396 int dev;
397 int dec_rdev = 1; 397 int dec_rdev = 1;
398 struct r10conf *conf = r10_bio->mddev->private; 398 struct r10conf *conf = r10_bio->mddev->private;
399 int slot; 399 int slot, repl;
400 struct md_rdev *rdev;
400 401
401 dev = find_bio_disk(conf, r10_bio, bio, &slot, NULL); 402 dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl);
402 403
404 if (repl)
405 rdev = conf->mirrors[dev].replacement;
406 else
407 rdev = conf->mirrors[dev].rdev;
403 /* 408 /*
404 * this branch is our 'one mirror IO has finished' event handler: 409 * this branch is our 'one mirror IO has finished' event handler:
405 */ 410 */
406 if (!uptodate) { 411 if (!uptodate) {
407 set_bit(WriteErrorSeen, &conf->mirrors[dev].rdev->flags); 412 if (repl)
408 set_bit(R10BIO_WriteError, &r10_bio->state); 413 /* Never record new bad blocks to replacement,
409 dec_rdev = 0; 414 * just fail it.
415 */
416 md_error(rdev->mddev, rdev);
417 else {
418 set_bit(WriteErrorSeen, &rdev->flags);
419 set_bit(R10BIO_WriteError, &r10_bio->state);
420 dec_rdev = 0;
421 }
410 } else { 422 } else {
411 /* 423 /*
412 * Set R10BIO_Uptodate in our master bio, so that 424 * Set R10BIO_Uptodate in our master bio, so that
@@ -423,12 +435,15 @@ static void raid10_end_write_request(struct bio *bio, int error)
423 set_bit(R10BIO_Uptodate, &r10_bio->state); 435 set_bit(R10BIO_Uptodate, &r10_bio->state);
424 436
425 /* Maybe we can clear some bad blocks. */ 437 /* Maybe we can clear some bad blocks. */
426 if (is_badblock(conf->mirrors[dev].rdev, 438 if (is_badblock(rdev,
427 r10_bio->devs[slot].addr, 439 r10_bio->devs[slot].addr,
428 r10_bio->sectors, 440 r10_bio->sectors,
429 &first_bad, &bad_sectors)) { 441 &first_bad, &bad_sectors)) {
430 bio_put(bio); 442 bio_put(bio);
431 r10_bio->devs[slot].bio = IO_MADE_GOOD; 443 if (repl)
444 r10_bio->devs[slot].repl_bio = IO_MADE_GOOD;
445 else
446 r10_bio->devs[slot].bio = IO_MADE_GOOD;
432 dec_rdev = 0; 447 dec_rdev = 0;
433 set_bit(R10BIO_MadeGood, &r10_bio->state); 448 set_bit(R10BIO_MadeGood, &r10_bio->state);
434 } 449 }
@@ -444,7 +459,6 @@ static void raid10_end_write_request(struct bio *bio, int error)
444 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); 459 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev);
445} 460}
446 461
447
448/* 462/*
449 * RAID10 layout manager 463 * RAID10 layout manager
450 * As well as the chunksize and raid_disks count, there are two 464 * As well as the chunksize and raid_disks count, there are two
@@ -1073,12 +1087,23 @@ retry_write:
1073 for (i = 0; i < conf->copies; i++) { 1087 for (i = 0; i < conf->copies; i++) {
1074 int d = r10_bio->devs[i].devnum; 1088 int d = r10_bio->devs[i].devnum;
1075 struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev); 1089 struct md_rdev *rdev = rcu_dereference(conf->mirrors[d].rdev);
1090 struct md_rdev *rrdev = rcu_dereference(
1091 conf->mirrors[d].replacement);
1076 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) { 1092 if (rdev && unlikely(test_bit(Blocked, &rdev->flags))) {
1077 atomic_inc(&rdev->nr_pending); 1093 atomic_inc(&rdev->nr_pending);
1078 blocked_rdev = rdev; 1094 blocked_rdev = rdev;
1079 break; 1095 break;
1080 } 1096 }
1097 if (rrdev && unlikely(test_bit(Blocked, &rrdev->flags))) {
1098 atomic_inc(&rrdev->nr_pending);
1099 blocked_rdev = rrdev;
1100 break;
1101 }
1102 if (rrdev && test_bit(Faulty, &rrdev->flags))
1103 rrdev = NULL;
1104
1081 r10_bio->devs[i].bio = NULL; 1105 r10_bio->devs[i].bio = NULL;
1106 r10_bio->devs[i].repl_bio = NULL;
1082 if (!rdev || test_bit(Faulty, &rdev->flags)) { 1107 if (!rdev || test_bit(Faulty, &rdev->flags)) {
1083 set_bit(R10BIO_Degraded, &r10_bio->state); 1108 set_bit(R10BIO_Degraded, &r10_bio->state);
1084 continue; 1109 continue;
@@ -1127,6 +1152,10 @@ retry_write:
1127 } 1152 }
1128 r10_bio->devs[i].bio = bio; 1153 r10_bio->devs[i].bio = bio;
1129 atomic_inc(&rdev->nr_pending); 1154 atomic_inc(&rdev->nr_pending);
1155 if (rrdev) {
1156 r10_bio->devs[i].repl_bio = bio;
1157 atomic_inc(&rrdev->nr_pending);
1158 }
1130 } 1159 }
1131 rcu_read_unlock(); 1160 rcu_read_unlock();
1132 1161
@@ -1135,11 +1164,17 @@ retry_write:
1135 int j; 1164 int j;
1136 int d; 1165 int d;
1137 1166
1138 for (j = 0; j < i; j++) 1167 for (j = 0; j < i; j++) {
1139 if (r10_bio->devs[j].bio) { 1168 if (r10_bio->devs[j].bio) {
1140 d = r10_bio->devs[j].devnum; 1169 d = r10_bio->devs[j].devnum;
1141 rdev_dec_pending(conf->mirrors[d].rdev, mddev); 1170 rdev_dec_pending(conf->mirrors[d].rdev, mddev);
1142 } 1171 }
1172 if (r10_bio->devs[j].repl_bio) {
1173 d = r10_bio->devs[j].devnum;
1174 rdev_dec_pending(
1175 conf->mirrors[d].replacement, mddev);
1176 }
1177 }
1143 allow_barrier(conf); 1178 allow_barrier(conf);
1144 md_wait_for_blocked_rdev(blocked_rdev, mddev); 1179 md_wait_for_blocked_rdev(blocked_rdev, mddev);
1145 wait_barrier(conf); 1180 wait_barrier(conf);
@@ -1186,6 +1221,27 @@ retry_write:
1186 bio_list_add(&conf->pending_bio_list, mbio); 1221 bio_list_add(&conf->pending_bio_list, mbio);
1187 conf->pending_count++; 1222 conf->pending_count++;
1188 spin_unlock_irqrestore(&conf->device_lock, flags); 1223 spin_unlock_irqrestore(&conf->device_lock, flags);
1224
1225 if (!r10_bio->devs[i].repl_bio)
1226 continue;
1227
1228 mbio = bio_clone_mddev(bio, GFP_NOIO, mddev);
1229 md_trim_bio(mbio, r10_bio->sector - bio->bi_sector,
1230 max_sectors);
1231 r10_bio->devs[i].repl_bio = mbio;
1232
1233 mbio->bi_sector = (r10_bio->devs[i].addr+
1234 conf->mirrors[d].replacement->data_offset);
1235 mbio->bi_bdev = conf->mirrors[d].replacement->bdev;
1236 mbio->bi_end_io = raid10_end_write_request;
1237 mbio->bi_rw = WRITE | do_sync | do_fua;
1238 mbio->bi_private = r10_bio;
1239
1240 atomic_inc(&r10_bio->remaining);
1241 spin_lock_irqsave(&conf->device_lock, flags);
1242 bio_list_add(&conf->pending_bio_list, mbio);
1243 conf->pending_count++;
1244 spin_unlock_irqrestore(&conf->device_lock, flags);
1189 } 1245 }
1190 1246
1191 /* Don't remove the bias on 'remaining' (one_write_done) until 1247 /* Don't remove the bias on 'remaining' (one_write_done) until
@@ -2253,6 +2309,15 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
2253 } 2309 }
2254 rdev_dec_pending(rdev, conf->mddev); 2310 rdev_dec_pending(rdev, conf->mddev);
2255 } 2311 }
2312 bio = r10_bio->devs[m].repl_bio;
2313 rdev = conf->mirrors[dev].replacement;
2314 if (bio == IO_MADE_GOOD) {
2315 rdev_clear_badblocks(
2316 rdev,
2317 r10_bio->devs[m].addr,
2318 r10_bio->sectors);
2319 rdev_dec_pending(rdev, conf->mddev);
2320 }
2256 } 2321 }
2257 if (test_bit(R10BIO_WriteError, 2322 if (test_bit(R10BIO_WriteError,
2258 &r10_bio->state)) 2323 &r10_bio->state))