From: Chen Cheng <[email protected]>

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: [email protected]
Signed-off-by: Chen Cheng <[email protected]>
---
 drivers/md/dm-snap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 31676ee05514..e49427bdbeef 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -1356,12 +1356,14 @@ static int snapshot_ctr(struct dm_target *ti, unsigned 
int argc, char **argv)
 
        spin_lock_init(&s->tracked_chunk_lock);
 
        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 */
        /* Exceptions aren't triggered till snapshot_resume() is called */
        r = register_snapshot(s);
-- 
2.56.0

Reply via email to