Re: [PATCH] md/raid5: complete unsupported discards successfully
From: yu kuai
Date: Thu Nov 05 2026 - 22:27:05 EST
在 2026/10/26 14:21, Konstantin Nikiforov 写道:
> Since commit 90573092673c ("md/raid5: validate discard support at
> request time") raid5 advertises max_hw_discard_sectors = UINT_MAX no
> matter whether the member devices support discard or
> devices_handle_discard_safely is set, and make_discard_request() fails
> the discards it cannot handle with BLK_STS_NOTSUPP.
>
> Before that commit such arrays did not advertise discard at all, so
> upper layers never sent one. Now they do, and the failure is not
> harmless:
>
> - bcache forwards discards to its backing device whenever
> bdev_max_discard_sectors() is non-zero, and backing_request_endio()
> treats every non-zero bi_status as a media error. After io_error_limit
> (64) of them bch_cached_dev_error() stops the cached device. On a
> machine with root on LVM over bcache over a raid5 of three HDDs the
> root filesystem disappeared a few minutes after every boot.
>
> - btrfs enables discard=async by default on any device that advertises
> discard, which is what generated the discards in the first place.
>
> Discard is advisory: blkdev_issue_discard() already turns -EOPNOTSUPP
> into success for its callers, and md_submit_discard_bio() silently skips
> raid0/raid10 members without discard support. Do the same here and
> complete the bio successfully when the array cannot pass it down safely,
> so that callers submitting their own discard bios, like bcache, see the
> same behaviour.
>
> Fixes: 90573092673c ("md/raid5: validate discard support at request time")
> Cc:stable@xxxxxxxxxxxxxxx # 7.2
> Closes:https://lore.kernel.org/all/CAO96y0V6oncv54ihXnHfJMYiG_QAQ-NM8BOdqPDXKL8r8-kR9Q@xxxxxxxxxxxxxx/
> Signed-off-by: Konstantin Nikiforov<helllamer@xxxxxxxxx>
> ---
> Kuai, this is the raid5-side change you were fine with in the report
> thread. Reproducer: raid5 over three loop devices with a bcache backing
> device on top, four blkdiscard calls on the bcache device. On 7.2.11
> without the patch bcache's io_errors goes to 4 (bch_count_backing_io_errors
> in dmesg); with the patch applied to 7.2.11 it stays at 0, and the
> affected machine (root on LVM over bcache over raid5 of HDDs) boots and
> runs with the patched module without any backing-device errors.
> blkdiscard on the md device itself reports success either way because
> blkdev_issue_discard() masks EOPNOTSUPP.
>
> One correction to my report: the "discard_granularity is 0" observation
> was a side effect of my own workaround (writing 0 to discard_max_bytes
> makes the block layer report granularity 0); on a fresh array the
> granularity is the stripe size as expected.
>
> drivers/md/raid5.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
Applied
--
Thanks,
Kuai