mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "yu kuai" <yukuai@fygo.io>
To: "Miroslav Cimerman" <mc@raidlab.org>,
	"Song Liu" <song@kernel.org>,  "yu kuai" <yukuai@fygo.io>
Cc: "Li Nan" <magiclinan@didiglobal.com>, "Xiao Ni" <xiao@kernel.org>,
	 "NeilBrown" <neil@brown.name>,
	"Mariusz Tkaczyk" <mtkaczyk@kernel.org>,
	 "Kenta Akagi" <k@mgml.me>, <linux-raid@vger.kernel.org>,
	 <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/8] md/raid1,raid10: fail held writes that no working device has
Date: Sun, 29 Nov 2026 14:35:28 +0800	[thread overview]
Message-ID: <40d81b93-e71e-4ed3-894c-bcaa4985b7a9@fygo.io> (raw)
In-Reply-To: <20261127003231.1180197-5-mc@raidlab.org>

Hi,

在 2026/11/27 8:32, Miroslav Cimerman 写道:
> With a bad block log, a failed copy is recorded as a bad block, and its
> device stays in the array. If the superblock write then fails on the
> device with the good copy, md marks that device faulty while the write
> is held. The write still completes with success, although no working
> device has its data, and reads of it return EIO.
>
> Check at release that a working device has all of the write, and fail
> the write otherwise.
>
> Fixes: 55ce74d4bfe1 ("md/raid1: ensure device failure recorded before write request returns.")
> Fixes: 95af587e95aa ("md/raid10: ensure device failure recorded before write request returns.")

Same as patch 3, device can be faulty at any time. And What's the problem here?

> Cc: stable@vger.kernel.org
> Signed-off-by: Miroslav Cimerman <mc@raidlab.org>
> ---
>   drivers/md/raid1.c  | 28 ++++++++++++++++++++++++++++
>   drivers/md/raid10.c | 34 ++++++++++++++++++++++++++++++++++
>   2 files changed, 62 insertions(+)
>
> diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
> index 88bbe81c7798..fcdbccf6e368 100644
> --- a/drivers/md/raid1.c
> +++ b/drivers/md/raid1.c
> @@ -2572,6 +2572,26 @@ static void handle_write_finished(struct r1conf *conf, struct r1bio *r1_bio)
>   	}
>   }
>   
> +/*
> + * A device that is In_sync, not Faulty and has no bad block in the range
> + * of the write was not skipped and did not fail, so it has the whole write.
> + */
> +static bool raid1_held_write_has_copy(struct r1conf *conf,
> +				      struct r1bio *r1_bio)
> +{
> +	int i;
> +
> +	for (i = 0; i < conf->raid_disks * 2; i++) {
> +		struct md_rdev *rdev = READ_ONCE(conf->mirrors[i].rdev);
> +
> +		if (rdev && test_bit(In_sync, &rdev->flags) &&
> +		    !test_bit(Faulty, &rdev->flags) &&
> +		    !rdev_has_badblock(rdev, r1_bio->sector, r1_bio->sectors))
> +			return true;
> +	}
> +	return false;
> +}
> +
>   static void handle_read_error(struct r1conf *conf, struct r1bio *r1_bio)
>   {
>   	struct md_rdev *rdev = conf->mirrors[r1_bio->read_disk].rdev;
> @@ -2649,6 +2669,14 @@ static void raid1d(struct md_thread *thread)
>   			if (!mddev_is_dm(mddev) &&
>   			    test_bit(MD_BROKEN, &mddev->flags))
>   				clear_bit(R1BIO_Uptodate, &r1_bio->state);
> +			/*
> +			 * Fail the write if no working device has it now.
> +			 * Skip write-behind writes: they completed already,
> +			 * and nothing pins their rdevs.
> +			 */
> +			if (!test_bit(R1BIO_Returned, &r1_bio->state) &&
> +			    !raid1_held_write_has_copy(conf, r1_bio))
> +				clear_bit(R1BIO_Uptodate, &r1_bio->state);
>   			if (test_bit(R1BIO_WriteError, &r1_bio->state))
>   				close_write(r1_bio);
>   			raid_end_bio_io(r1_bio);
> diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
> index a38b95585e35..838ae71205c1 100644
> --- a/drivers/md/raid10.c
> +++ b/drivers/md/raid10.c
> @@ -2837,6 +2837,37 @@ static void handle_read_error(struct mddev *mddev, struct r10bio *r10_bio)
>   	allow_barrier(conf);
>   }
>   
> +static bool raid10_rdev_has_copy(struct md_rdev *rdev, sector_t addr,
> +				 int sectors)
> +{
> +	return rdev && test_bit(In_sync, &rdev->flags) &&
> +	       !test_bit(Faulty, &rdev->flags) &&
> +	       !rdev_has_badblock(rdev, addr, sectors);
> +}
> +
> +/*
> + * A device that is In_sync, not Faulty and has no bad block at the copy's
> + * address was not skipped and did not fail, so it has the copy. Check the
> + * replacement too: a finished replacement stays in its slot until moved.
> + */
> +static bool raid10_held_write_has_copy(struct r10conf *conf,
> +				       struct r10bio *r10_bio)
> +{
> +	int i;
> +
> +	for (i = 0; i < conf->copies; i++) {
> +		int d = r10_bio->devs[i].devnum;
> +		sector_t addr = r10_bio->devs[i].addr;
> +		struct md_rdev *rdev = READ_ONCE(conf->mirrors[d].rdev);
> +		struct md_rdev *rrdev = READ_ONCE(conf->mirrors[d].replacement);
> +
> +		if (raid10_rdev_has_copy(rdev, addr, r10_bio->sectors) ||
> +		    raid10_rdev_has_copy(rrdev, addr, r10_bio->sectors))
> +			return true;
> +	}
> +	return false;
> +}
> +
>   static void handle_write_completed(struct r10conf *conf, struct r10bio *r10_bio)
>   {
>   	/* Some sort of write request has finished and it
> @@ -2963,6 +2994,9 @@ static void raid10d(struct md_thread *thread)
>   			if (!mddev_is_dm(mddev) &&
>   			    test_bit(MD_BROKEN, &mddev->flags))
>   				clear_bit(R10BIO_Uptodate, &r10_bio->state);
> +			/* Fail the write if no working device has it now */
> +			if (!raid10_held_write_has_copy(conf, r10_bio))
> +				clear_bit(R10BIO_Uptodate, &r10_bio->state);
>   			if (test_bit(R10BIO_WriteError,
>   				     &r10_bio->state))
>   				close_write(r10_bio);

-- 
Thanks,
Kuai

  reply	other threads:[~2026-11-29  6:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  0:32 [PATCH 0/8] md/raid1,raid10: fix writes acknowledged before a failure is recorded Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 1/8] md/raid1,raid10: fail held writes when the array fails Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 2/8] md/raid10: wait for the devices of the write in wait_blocked_dev() Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 3/8] md/raid1,raid10: fail writes that waited while the array failed Miroslav Cimerman
2026-11-29  6:31   ` yu kuai
2026-11-27  0:32 ` [PATCH 4/8] md/raid1,raid10: fail held writes that no working device has Miroslav Cimerman
2026-11-29  6:35   ` yu kuai [this message]
2026-11-27  0:32 ` [PATCH 5/8] md/raid1,raid10: hold writes that fail on a faulty device Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 6/8] md/raid1: set MD_SB_CHANGE_PENDING under device_lock in raid1_error() Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 7/8] md/raid1,raid10: hold writes that skip a newly failed device Miroslav Cimerman
2026-11-27  0:32 ` [PATCH 8/8] md/raid1: hold write-behind writes that failed on a device Miroslav Cimerman
2026-11-29  6:45 ` [PATCH 0/8] md/raid1,raid10: fix writes acknowledged before a failure is recorded yu kuai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40d81b93-e71e-4ed3-894c-bcaa4985b7a9@fygo.io \
    --to=yukuai@fygo.io \
    --cc=k@mgml.me \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=mc@raidlab.org \
    --cc=mtkaczyk@kernel.org \
    --cc=neil@brown.name \
    --cc=song@kernel.org \
    --cc=xiao@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®