Skip to content

Commit b1a7ad8

Browse files
johnpgarryaxboe
authored andcommitted
md/raid1: Handle bio_split() errors
Add proper bio_split() error handling. For any error, call raid_end_bio_io() and return. For the case of an in the write path, we need to undo the increment in the rdev pending count and NULLify the r1_bio->bios[] pointers. For read path failure, we need to undo rdev pending count increment from the earlier read_balance() call. Reviewed-by: Yu Kuai <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: John Garry <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 74538fd commit b1a7ad8

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

drivers/md/raid1.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
13221322
const enum req_op op = bio_op(bio);
13231323
const blk_opf_t do_sync = bio->bi_opf & REQ_SYNC;
13241324
int max_sectors;
1325-
int rdisk;
1325+
int rdisk, error;
13261326
bool r1bio_existed = !!r1_bio;
13271327

13281328
/*
@@ -1383,6 +1383,11 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
13831383
if (max_sectors < bio_sectors(bio)) {
13841384
struct bio *split = bio_split(bio, max_sectors,
13851385
gfp, &conf->bio_split);
1386+
1387+
if (IS_ERR(split)) {
1388+
error = PTR_ERR(split);
1389+
goto err_handle;
1390+
}
13861391
bio_chain(split, bio);
13871392
submit_bio_noacct(bio);
13881393
bio = split;
@@ -1410,6 +1415,13 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
14101415
read_bio->bi_private = r1_bio;
14111416
mddev_trace_remap(mddev, read_bio, r1_bio->sector);
14121417
submit_bio_noacct(read_bio);
1418+
return;
1419+
1420+
err_handle:
1421+
atomic_dec(&mirror->rdev->nr_pending);
1422+
bio->bi_status = errno_to_blk_status(error);
1423+
set_bit(R1BIO_Uptodate, &r1_bio->state);
1424+
raid_end_bio_io(r1_bio);
14131425
}
14141426

14151427
static bool wait_blocked_rdev(struct mddev *mddev, struct bio *bio)
@@ -1451,7 +1463,7 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
14511463
{
14521464
struct r1conf *conf = mddev->private;
14531465
struct r1bio *r1_bio;
1454-
int i, disks;
1466+
int i, disks, k, error;
14551467
unsigned long flags;
14561468
int first_clone;
14571469
int max_sectors;
@@ -1579,6 +1591,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
15791591
if (max_sectors < bio_sectors(bio)) {
15801592
struct bio *split = bio_split(bio, max_sectors,
15811593
GFP_NOIO, &conf->bio_split);
1594+
1595+
if (IS_ERR(split)) {
1596+
error = PTR_ERR(split);
1597+
goto err_handle;
1598+
}
15821599
bio_chain(split, bio);
15831600
submit_bio_noacct(bio);
15841601
bio = split;
@@ -1663,6 +1680,18 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
16631680

16641681
/* In case raid1d snuck in to freeze_array */
16651682
wake_up_barrier(conf);
1683+
return;
1684+
err_handle:
1685+
for (k = 0; k < i; k++) {
1686+
if (r1_bio->bios[k]) {
1687+
rdev_dec_pending(conf->mirrors[k].rdev, mddev);
1688+
r1_bio->bios[k] = NULL;
1689+
}
1690+
}
1691+
1692+
bio->bi_status = errno_to_blk_status(error);
1693+
set_bit(R1BIO_Uptodate, &r1_bio->state);
1694+
raid_end_bio_io(r1_bio);
16661695
}
16671696

16681697
static bool raid1_make_request(struct mddev *mddev, struct bio *bio)

0 commit comments

Comments
 (0)