[PATCH v2 3/3] md/raid5: always convert llbitmap bits for discard

From: Yu Kuai

Date: Fri Jun 05 2026 - 03:44:29 EST


From: Yu Kuai <yukuai@xxxxxxx>

llbitmap discard is useful even when no underlying member device supports
it. The discard still converts the llbitmap range to unwritten, so later
reads and recovery do not rely on stale parity for that range.

Let llbitmap discard bypass the raid5 lower discard support check. If lower
discard is not safe or not supported, complete the accounted clone after
md_account_bio() so the llbitmap conversion callbacks run without member
discard bios.

Signed-off-by: Yu Kuai <yukuai@xxxxxxx>
---
drivers/md/raid5.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 76e736ee48d3..180ff0660b6a 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -1136,10 +1136,13 @@ static void defer_issue_bios(struct r5conf *conf, sector_t sector,

static bool raid5_discard_limits(struct mddev *mddev, struct bio *bi)
{
struct r5conf *conf = mddev->private;

+ if (mddev->bitmap_id == ID_LLBITMAP)
+ return true;
+
if (!conf->raid5_discard_unsupported)
return true;

bi->bi_status = BLK_STS_NOTSUPP;
bio_endio(bi);
@@ -5738,10 +5741,16 @@ static void make_discard_request(struct mddev *mddev, struct bio *bi)
md_account_bio(mddev, &bi);
orig_bi->bi_iter = bi_iter;
bi->bi_iter = bi_iter;
bi->bi_next = NULL;

+ if (mddev->bitmap_id == ID_LLBITMAP &&
+ conf->raid5_discard_unsupported) {
+ bio_endio(bi);
+ return;
+ }
+
logical_sector = first_stripe * conf->chunk_sectors;
last_sector = last_stripe * conf->chunk_sectors;

for (; logical_sector < last_sector;
logical_sector += RAID5_STRIPE_SECTORS(conf)) {
--
2.51.0