| From 4fe2c2baad01da64d47f1a0c8fc093df994bcef5 Mon Sep 17 00:00:00 2001 | |
| From: Chen Cheng <chencheng@fnnas.com> | |
| Date: Fri, 30 Oct 2026 17:21:28 +0800 | |
| Subject: dm snapshot: split discards on chunk boundaries | |
| From: Chen Cheng <chencheng@fnnas.com> | |
| commit 4fe2c2baad01da64d47f1a0c8fc093df994bcef5 upstream. | |
| dm-snapshot did not set ti->max_discard_granularity when it allows | |
| discards, so a discard could reach the target unaligned, or spanning | |
| several chunks. Set the flag, so dm splits discards on chunk | |
| boundaries. | |
| Fixes: 2e6023850e17 ("dm snapshot: add optional discard support features") | |
| Cc: stable@vger.kernel.org | |
| Signed-off-by: Chen Cheng <chencheng@fnnas.com> | |
| Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> | |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
| --- | |
| drivers/md/dm-snap.c | 4 +++- | |
| 1 file changed, 3 insertions(+), 1 deletion(-) | |
| --- a/drivers/md/dm-snap.c | |
| +++ b/drivers/md/dm-snap.c | |
| @@ -1358,8 +1358,10 @@ static int snapshot_ctr(struct dm_target | |
| ti->private = s; | |
| ti->num_flush_bios = num_flush_bios; | |
| - if (s->discard_zeroes_cow) | |
| + if (s->discard_zeroes_cow) { | |
| ti->num_discard_bios = (s->discard_passdown_origin ? 2 : 1); | |
| + ti->max_discard_granularity = true; | |
| + } | |
| ti->per_io_data_size = sizeof(struct dm_snap_tracked_chunk); | |
| /* Add snapshot to the list of snapshots for this origin */ |