]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
md: break remaining operations on badblocks set failure in narrow_write_error
authorLi Nan <linan122@huawei.com>
Mon, 5 Jan 2026 11:02:52 +0000 (19:02 +0800)
committerYu Kuai <yukuai@fnnas.com>
Mon, 26 Jan 2026 05:16:12 +0000 (13:16 +0800)
Mark device faulty and exit at once when setting badblocks fails in
narrow_write_error(). No need to continue processing remaining sections.
With this change, narrow_write_error() no longer needs to return a value,
so adjust its return type to void.

Link: https://lore.kernel.org/linux-raid/20260105110300.1442509-5-linan666@huaweicloud.com
Signed-off-by: Li Nan <linan122@huawei.com>
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
drivers/md/raid1.c
drivers/md/raid10.c

index c65f1bb97aa19f6a32715f349efb68afe55d7cf3..ac8eff3dfb85b8af51de1e5b34f87f6ab6ff29e0 100644 (file)
@@ -2486,7 +2486,7 @@ static void fix_read_error(struct r1conf *conf, struct r1bio *r1_bio)
        }
 }
 
-static bool narrow_write_error(struct r1bio *r1_bio, int i)
+static void narrow_write_error(struct r1bio *r1_bio, int i)
 {
        struct mddev *mddev = r1_bio->mddev;
        struct r1conf *conf = mddev->private;
@@ -2507,7 +2507,6 @@ static bool narrow_write_error(struct r1bio *r1_bio, int i)
        sector_t sector;
        int sectors;
        int sect_to_write = r1_bio->sectors;
-       bool ok = true;
 
        if (rdev->badblocks.shift < 0)
                block_sectors = lbs;
@@ -2541,18 +2540,22 @@ static bool narrow_write_error(struct r1bio *r1_bio, int i)
                bio_trim(wbio, sector - r1_bio->sector, sectors);
                wbio->bi_iter.bi_sector += rdev->data_offset;
 
-               if (submit_bio_wait(wbio) < 0)
-                       /* failure! */
-                       ok = rdev_set_badblocks(rdev, sector,
-                                               sectors, 0)
-                               && ok;
+               if (submit_bio_wait(wbio) &&
+                   !rdev_set_badblocks(rdev, sector, sectors, 0)) {
+                       /*
+                        * Badblocks set failed, disk marked Faulty.
+                        * No further operations needed.
+                        */
+                       md_error(mddev, rdev);
+                       bio_put(wbio);
+                       break;
+               }
 
                bio_put(wbio);
                sect_to_write -= sectors;
                sector += sectors;
                sectors = block_sectors;
        }
-       return ok;
 }
 
 static void handle_sync_write_finished(struct r1conf *conf, struct r1bio *r1_bio)
@@ -2596,10 +2599,7 @@ static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio)
                         * errors.
                         */
                        fail = true;
-                       if (!narrow_write_error(r1_bio, m))
-                               md_error(conf->mddev,
-                                        conf->mirrors[m].rdev);
-                               /* an I/O failed, we can't clear the bitmap */
+                       narrow_write_error(r1_bio, m);
                        rdev_dec_pending(conf->mirrors[m].rdev,
                                         conf->mddev);
                }
index deac7741c4908d59f3f63e5eabaf65e41ed3c49d..233981dac83c9f76b332531feb5c062362e0303b 100644 (file)
@@ -2773,7 +2773,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
        }
 }
 
-static bool narrow_write_error(struct r10bio *r10_bio, int i)
+static void narrow_write_error(struct r10bio *r10_bio, int i)
 {
        struct bio *bio = r10_bio->master_bio;
        struct mddev *mddev = r10_bio->mddev;
@@ -2794,7 +2794,6 @@ static bool narrow_write_error(struct r10bio *r10_bio, int i)
        sector_t sector;
        int sectors;
        int sect_to_write = r10_bio->sectors;
-       bool ok = true;
 
        if (rdev->badblocks.shift < 0)
                block_sectors = lbs;
@@ -2820,18 +2819,22 @@ static bool narrow_write_error(struct r10bio *r10_bio, int i)
                                   choose_data_offset(r10_bio, rdev);
                wbio->bi_opf = REQ_OP_WRITE;
 
-               if (submit_bio_wait(wbio) < 0)
-                       /* Failure! */
-                       ok = rdev_set_badblocks(rdev, wsector,
-                                               sectors, 0)
-                               && ok;
+               if (submit_bio_wait(wbio) &&
+                   !rdev_set_badblocks(rdev, wsector, sectors, 0)) {
+                       /*
+                        * Badblocks set failed, disk marked Faulty.
+                        * No further operations needed.
+                        */
+                       md_error(mddev, rdev);
+                       bio_put(wbio);
+                       break;
+               }
 
                bio_put(wbio);
                sect_to_write -= sectors;
                sector += sectors;
                sectors = block_sectors;
        }
-       return ok;
 }
 
 static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)
@@ -2936,8 +2939,7 @@ static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
                                rdev_dec_pending(rdev, conf->mddev);
                        } else if (bio != NULL && bio->bi_status) {
                                fail = true;
-                               if (!narrow_write_error(r10_bio, m))
-                                       md_error(conf->mddev, rdev);
+                               narrow_write_error(r10_bio, m);
                                rdev_dec_pending(rdev, conf->mddev);
                        }
                        bio = r10_bio->devs[m].repl_bio;