Skip to content

Commit 74dc8c2

Browse files
johnpgarrygregkh
authored andcommitted
md/raid1: Handle bio_split() errors
[ Upstream commit b1a7ad8 ] 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]> Stable-dep-of: 22f1662 ("md: fix mssing blktrace bio split events") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 069e7bb commit 74dc8c2

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
@@ -1317,7 +1317,7 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
13171317
struct raid1_info *mirror;
13181318
struct bio *read_bio;
13191319
int max_sectors;
1320-
int rdisk;
1320+
int rdisk, error;
13211321
bool r1bio_existed = !!r1_bio;
13221322

13231323
/*
@@ -1378,6 +1378,11 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
13781378
if (max_sectors < bio_sectors(bio)) {
13791379
struct bio *split = bio_split(bio, max_sectors,
13801380
gfp, &conf->bio_split);
1381+
1382+
if (IS_ERR(split)) {
1383+
error = PTR_ERR(split);
1384+
goto err_handle;
1385+
}
13811386
bio_chain(split, bio);
13821387
submit_bio_noacct(bio);
13831388
bio = split;
@@ -1404,14 +1409,21 @@ static void raid1_read_request(struct mddev *mddev, struct bio *bio,
14041409
read_bio->bi_private = r1_bio;
14051410
mddev_trace_remap(mddev, read_bio, r1_bio->sector);
14061411
submit_bio_noacct(read_bio);
1412+
return;
1413+
1414+
err_handle:
1415+
atomic_dec(&mirror->rdev->nr_pending);
1416+
bio->bi_status = errno_to_blk_status(error);
1417+
set_bit(R1BIO_Uptodate, &r1_bio->state);
1418+
raid_end_bio_io(r1_bio);
14071419
}
14081420

14091421
static void raid1_write_request(struct mddev *mddev, struct bio *bio,
14101422
int max_write_sectors)
14111423
{
14121424
struct r1conf *conf = mddev->private;
14131425
struct r1bio *r1_bio;
1414-
int i, disks;
1426+
int i, disks, k, error;
14151427
unsigned long flags;
14161428
struct md_rdev *blocked_rdev;
14171429
int first_clone;
@@ -1557,6 +1569,11 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
15571569
if (max_sectors < bio_sectors(bio)) {
15581570
struct bio *split = bio_split(bio, max_sectors,
15591571
GFP_NOIO, &conf->bio_split);
1572+
1573+
if (IS_ERR(split)) {
1574+
error = PTR_ERR(split);
1575+
goto err_handle;
1576+
}
15601577
bio_chain(split, bio);
15611578
submit_bio_noacct(bio);
15621579
bio = split;
@@ -1640,6 +1657,18 @@ static void raid1_write_request(struct mddev *mddev, struct bio *bio,
16401657

16411658
/* In case raid1d snuck in to freeze_array */
16421659
wake_up_barrier(conf);
1660+
return;
1661+
err_handle:
1662+
for (k = 0; k < i; k++) {
1663+
if (r1_bio->bios[k]) {
1664+
rdev_dec_pending(conf->mirrors[k].rdev, mddev);
1665+
r1_bio->bios[k] = NULL;
1666+
}
1667+
}
1668+
1669+
bio->bi_status = errno_to_blk_status(error);
1670+
set_bit(R1BIO_Uptodate, &r1_bio->state);
1671+
raid_end_bio_io(r1_bio);
16431672
}
16441673

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

0 commit comments

Comments
 (0)