]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
md/raid10: Handle bio_split() errors
authorJohn Garry <john.g.garry@oracle.com>
Mon, 20 Oct 2025 13:06:48 +0000 (09:06 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Oct 2025 14:20:42 +0000 (16:20 +0200)
[ Upstream commit 4cf58d9529097328b669e3c8693ed21e3a041903 ]

Add proper bio_split() error handling. For any error, call
raid_end_bio_io() and return. Except for discard, where we end the bio
directly.

Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: John Garry <john.g.garry@oracle.com>
Link: https://lore.kernel.org/r/20241111112150.3756529-7-john.g.garry@oracle.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Stable-dep-of: 22f166218f73 ("md: fix mssing blktrace bio split events")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/raid10.c

index 6579bbb6a39a5d62c2993c69593b6c812c4242c9..d02bd096824c8026e00da62bab1fcb05df4e17b5 100644 (file)
@@ -1153,6 +1153,7 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
        int slot = r10_bio->read_slot;
        struct md_rdev *err_rdev = NULL;
        gfp_t gfp = GFP_NOIO;
+       int error;
 
        if (slot >= 0 && r10_bio->devs[slot].rdev) {
                /*
@@ -1203,6 +1204,10 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
        if (max_sectors < bio_sectors(bio)) {
                struct bio *split = bio_split(bio, max_sectors,
                                              gfp, &conf->bio_split);
+               if (IS_ERR(split)) {
+                       error = PTR_ERR(split);
+                       goto err_handle;
+               }
                bio_chain(split, bio);
                allow_barrier(conf);
                submit_bio_noacct(bio);
@@ -1233,6 +1238,11 @@ static void raid10_read_request(struct mddev *mddev, struct bio *bio,
        mddev_trace_remap(mddev, read_bio, r10_bio->sector);
        submit_bio_noacct(read_bio);
        return;
+err_handle:
+       atomic_dec(&rdev->nr_pending);
+       bio->bi_status = errno_to_blk_status(error);
+       set_bit(R10BIO_Uptodate, &r10_bio->state);
+       raid_end_bio_io(r10_bio);
 }
 
 static void raid10_write_one_disk(struct mddev *mddev, struct r10bio *r10_bio,
@@ -1341,9 +1351,10 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
                                 struct r10bio *r10_bio)
 {
        struct r10conf *conf = mddev->private;
-       int i;
+       int i, k;
        sector_t sectors;
        int max_sectors;
+       int error;
 
        if ((mddev_is_clustered(mddev) &&
             md_cluster_ops->area_resyncing(mddev, WRITE,
@@ -1469,6 +1480,10 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
        if (r10_bio->sectors < bio_sectors(bio)) {
                struct bio *split = bio_split(bio, r10_bio->sectors,
                                              GFP_NOIO, &conf->bio_split);
+               if (IS_ERR(split)) {
+                       error = PTR_ERR(split);
+                       goto err_handle;
+               }
                bio_chain(split, bio);
                allow_barrier(conf);
                submit_bio_noacct(bio);
@@ -1488,6 +1503,26 @@ static void raid10_write_request(struct mddev *mddev, struct bio *bio,
                        raid10_write_one_disk(mddev, r10_bio, bio, true, i);
        }
        one_write_done(r10_bio);
+       return;
+err_handle:
+       for (k = 0;  k < i; k++) {
+               int d = r10_bio->devs[k].devnum;
+               struct md_rdev *rdev = conf->mirrors[d].rdev;
+               struct md_rdev *rrdev = conf->mirrors[d].replacement;
+
+               if (r10_bio->devs[k].bio) {
+                       rdev_dec_pending(rdev, mddev);
+                       r10_bio->devs[k].bio = NULL;
+               }
+               if (r10_bio->devs[k].repl_bio) {
+                       rdev_dec_pending(rrdev, mddev);
+                       r10_bio->devs[k].repl_bio = NULL;
+               }
+       }
+
+       bio->bi_status = errno_to_blk_status(error);
+       set_bit(R10BIO_Uptodate, &r10_bio->state);
+       raid_end_bio_io(r10_bio);
 }
 
 static void __make_request(struct mddev *mddev, struct bio *bio, int sectors)
@@ -1629,6 +1664,11 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
        if (remainder) {
                split_size = stripe_size - remainder;
                split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
+               if (IS_ERR(split)) {
+                       bio->bi_status = errno_to_blk_status(PTR_ERR(split));
+                       bio_endio(bio);
+                       return 0;
+               }
                bio_chain(split, bio);
                allow_barrier(conf);
                /* Resend the fist split part */
@@ -1639,6 +1679,11 @@ static int raid10_handle_discard(struct mddev *mddev, struct bio *bio)
        if (remainder) {
                split_size = bio_sectors(bio) - remainder;
                split = bio_split(bio, split_size, GFP_NOIO, &conf->bio_split);
+               if (IS_ERR(split)) {
+                       bio->bi_status = errno_to_blk_status(PTR_ERR(split));
+                       bio_endio(bio);
+                       return 0;
+               }
                bio_chain(split, bio);
                allow_barrier(conf);
                /* Resend the second split part */