Skip to content

Commit 9f346f7

Browse files
committed
md/raid1,raid10: don't handle IO error for REQ_RAHEAD and REQ_NOWAIT
IO with REQ_RAHEAD or REQ_NOWAIT can fail early, even if the storage medium is fine, hence record badblocks or remove the disk from array does not make sense. This problem if found by lvm2 test lvcreate-large-raid, where dm-zero will fail read ahead IO directly. Fixes: e879a0d ("md/raid1,raid10: don't ignore IO flags") Reported-and-tested-by: Mikulas Patocka <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Link: https://lore.kernel.org/linux-raid/[email protected] Signed-off-by: Yu Kuai <[email protected]>
1 parent 39d86db commit 9f346f7

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

drivers/md/raid1-10.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,13 @@ static inline bool raid1_should_read_first(struct mddev *mddev,
293293

294294
return false;
295295
}
296+
297+
/*
298+
* bio with REQ_RAHEAD or REQ_NOWAIT can fail at anytime, before such IO is
299+
* submitted to the underlying disks, hence don't record badblocks or retry
300+
* in this case.
301+
*/
302+
static inline bool raid1_should_handle_error(struct bio *bio)
303+
{
304+
return !(bio->bi_opf & (REQ_RAHEAD | REQ_NOWAIT));
305+
}

drivers/md/raid1.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,16 @@ static void raid1_end_read_request(struct bio *bio)
373373
*/
374374
update_head_pos(r1_bio->read_disk, r1_bio);
375375

376-
if (uptodate)
376+
if (uptodate) {
377377
set_bit(R1BIO_Uptodate, &r1_bio->state);
378-
else if (test_bit(FailFast, &rdev->flags) &&
379-
test_bit(R1BIO_FailFast, &r1_bio->state))
378+
} else if (test_bit(FailFast, &rdev->flags) &&
379+
test_bit(R1BIO_FailFast, &r1_bio->state)) {
380380
/* This was a fail-fast read so we definitely
381381
* want to retry */
382382
;
383-
else {
383+
} else if (!raid1_should_handle_error(bio)) {
384+
uptodate = 1;
385+
} else {
384386
/* If all other devices have failed, we want to return
385387
* the error upwards rather than fail the last device.
386388
* Here we redefine "uptodate" to mean "Don't want to retry"
@@ -451,16 +453,15 @@ static void raid1_end_write_request(struct bio *bio)
451453
struct bio *to_put = NULL;
452454
int mirror = find_bio_disk(r1_bio, bio);
453455
struct md_rdev *rdev = conf->mirrors[mirror].rdev;
454-
bool discard_error;
455456
sector_t lo = r1_bio->sector;
456457
sector_t hi = r1_bio->sector + r1_bio->sectors;
457-
458-
discard_error = bio->bi_status && bio_op(bio) == REQ_OP_DISCARD;
458+
bool ignore_error = !raid1_should_handle_error(bio) ||
459+
(bio->bi_status && bio_op(bio) == REQ_OP_DISCARD);
459460

460461
/*
461462
* 'one mirror IO has finished' event handler:
462463
*/
463-
if (bio->bi_status && !discard_error) {
464+
if (bio->bi_status && !ignore_error) {
464465
set_bit(WriteErrorSeen, &rdev->flags);
465466
if (!test_and_set_bit(WantReplacement, &rdev->flags))
466467
set_bit(MD_RECOVERY_NEEDED, &
@@ -511,7 +512,7 @@ static void raid1_end_write_request(struct bio *bio)
511512

512513
/* Maybe we can clear some bad blocks. */
513514
if (rdev_has_badblock(rdev, r1_bio->sector, r1_bio->sectors) &&
514-
!discard_error) {
515+
!ignore_error) {
515516
r1_bio->bios[mirror] = IO_MADE_GOOD;
516517
set_bit(R1BIO_MadeGood, &r1_bio->state);
517518
}

drivers/md/raid10.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ static void raid10_end_read_request(struct bio *bio)
399399
* wait for the 'master' bio.
400400
*/
401401
set_bit(R10BIO_Uptodate, &r10_bio->state);
402+
} else if (!raid1_should_handle_error(bio)) {
403+
uptodate = 1;
402404
} else {
403405
/* If all other devices that store this block have
404406
* failed, we want to return the error upwards rather
@@ -456,9 +458,8 @@ static void raid10_end_write_request(struct bio *bio)
456458
int slot, repl;
457459
struct md_rdev *rdev = NULL;
458460
struct bio *to_put = NULL;
459-
bool discard_error;
460-
461-
discard_error = bio->bi_status && bio_op(bio) == REQ_OP_DISCARD;
461+
bool ignore_error = !raid1_should_handle_error(bio) ||
462+
(bio->bi_status && bio_op(bio) == REQ_OP_DISCARD);
462463

463464
dev = find_bio_disk(conf, r10_bio, bio, &slot, &repl);
464465

@@ -472,7 +473,7 @@ static void raid10_end_write_request(struct bio *bio)
472473
/*
473474
* this branch is our 'one mirror IO has finished' event handler:
474475
*/
475-
if (bio->bi_status && !discard_error) {
476+
if (bio->bi_status && !ignore_error) {
476477
if (repl)
477478
/* Never record new bad blocks to replacement,
478479
* just fail it.
@@ -527,7 +528,7 @@ static void raid10_end_write_request(struct bio *bio)
527528
/* Maybe we can clear some bad blocks. */
528529
if (rdev_has_badblock(rdev, r10_bio->devs[slot].addr,
529530
r10_bio->sectors) &&
530-
!discard_error) {
531+
!ignore_error) {
531532
bio_put(bio);
532533
if (repl)
533534
r10_bio->devs[slot].repl_bio = IO_MADE_GOOD;

0 commit comments

Comments
 (0)