Re: [PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed
From: yu kuai
Date: Sun Nov 29 2026 - 01:32:18 EST
Hi,
在 2026/11/27 8:32, Miroslav Cimerman 写道:
> md_submit_bio() fails new writes once MD_BROKEN is set. A write that
> arrives while a failed device is being recorded passes that check and
> waits for the superblock update. If the update fails on the last
> working device, MD_BROKEN is set during the wait. The write then
> continues, reaches only the remaining device and completes with
> success. After a restart, both devices assemble as in sync, and reads
> can return the old data.
>
> Check MD_BROKEN again after the wait, and fail the write. dm-raid does
> not go through md_submit_bio(), so leave it unchanged. Large raid10
> discards go through raid10_handle_discard() and are left as they are.
>
> Fixes: 9631abdbf406 ("md: Set MD_BROKEN for RAID1 and RAID10")
> Cc: stable@xxxxxxxxxxxxxxx
I don't think this can fix any problem thoroughly. On the one hand, array can
be broken at any time, just after the new checking. On the other hand, this extreme
case does not make much sense in real world, if array is broken, user data is already
lost for this array.
No need to add workload for stable backport for this.
> Signed-off-by: Miroslav Cimerman <mc@xxxxxxxxxxx>
> ---
> drivers/md/raid1.c | 12 ++++++++++++
> drivers/md/raid10.c | 11 +++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 37d120a63778..88bbe81c7798 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -1489,6 +1489,18 @@ static bool raid1_write_request(struct mddev *mddev, struct bio *bio,
>
> wait_blocked_rdev(mddev, bio);
>
> + /*
> + * If the array failed while this write waited, the failed device
> + * might not be recorded. Fail the write, as md_submit_bio() does,
> + * except for dm-raid.
> + */
> + if (unlikely(!mddev_is_dm(mddev) &&
> + test_bit(MD_BROKEN, &mddev->flags))) {
> + bio_io_error(bio);
> + allow_barrier(conf, sector);
> + return false;
> + }
> +
> r1_bio = alloc_r1bio(mddev, bio);
> r1_bio->sectors = max_sectors;
>
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index a97831823c68..a38b95585e35 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -1378,6 +1378,17 @@ static bool raid10_write_request(struct mddev *mddev, struct bio *bio,
>
> wait_blocked_dev(mddev, r10_bio);
>
> + /*
> + * If the array failed while this write waited, the failed device
> + * might not be recorded. Fail the write, as md_submit_bio() does,
> + * except for dm-raid.
> + */
> + if (unlikely(!mddev_is_dm(mddev) &&
> + test_bit(MD_BROKEN, &mddev->flags))) {
> + raid_end_bio_io(r10_bio);
> + return false;
> + }
> +
> max_sectors = r10_bio->sectors;
>
> for (i = 0; i < conf->copies; i++) {
--
Thanks,
Kuai