On 3/6/23 20:10, Mikulas Patocka wrote:
This patch adds discard support to dm-zero. The discards are ignored.
It is useful when the user combines dm-zero with other discard-supporting
targets in the same table; without dm-zero support, discards would be
disabled for the whole combined device.

Signed-off-by: Mikulas Patocka <mpato...@redhat.com>

Tested-by: Milan Broz <gmazyl...@gmail.com>

Just for the context: cryptsetup use dm-zero to mask certain areas
(in Bitlocker-compatible mapping) and discard flag disappeared in this situation
(discard is not supported configuration here, but it should work :)
Originally reported here https://gitlab.com/cryptsetup/cryptsetup/-/issues/718

Propagating discard support in dm-zero is definitely useful for other uses, 
though.

Thanks,
Milan


---
  drivers/md/dm-table.c |    9 ++++++++-
  drivers/md/dm-zero.c  |    4 +++-
  2 files changed, 11 insertions(+), 2 deletions(-)

Index: linux-2.6/drivers/md/dm-zero.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-zero.c
+++ linux-2.6/drivers/md/dm-zero.c
@@ -27,6 +27,7 @@ static int zero_ctr(struct dm_target *ti
         * Silently drop discards, avoiding -EOPNOTSUPP.
         */
        ti->num_discard_bios = 1;
+       ti->discards_supported = true;
return 0;
  }
@@ -45,6 +46,7 @@ static int zero_map(struct dm_target *ti
                zero_fill_bio(bio);
                break;
        case REQ_OP_WRITE:
+       case REQ_OP_DISCARD:
                /* writes get silently dropped */
                break;
        default:
@@ -59,7 +61,7 @@ static int zero_map(struct dm_target *ti
static struct target_type zero_target = {
        .name   = "zero",
-       .version = {1, 1, 0},
+       .version = {1, 2, 0},
        .features = DM_TARGET_NOWAIT,
        .module = THIS_MODULE,
        .ctr    = zero_ctr,
Index: linux-2.6/drivers/md/dm-table.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-table.c
+++ linux-2.6/drivers/md/dm-table.c
@@ -1670,8 +1670,15 @@ int dm_calculate_queue_limits(struct dm_
blk_set_stacking_limits(&ti_limits); - if (!ti->type->iterate_devices)
+               if (!ti->type->iterate_devices) {
+                       if (ti->discards_supported) {
+                               ti_limits.max_discard_sectors = UINT_MAX;
+                               ti_limits.max_hw_discard_sectors = UINT_MAX;
+                               ti_limits.discard_granularity = 512;
+                               ti_limits.discard_alignment = 0;
+                       }
                        goto combine_limits;
+               }
/*
                 * Combine queue limits of all the devices this target uses.


--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel

Reply via email to