[dm-devel] [PATCH] dm-zero: support discards
Mikulas Patocka
mpatocka at redhat.com
Mon Mar 6 19:10:25 UTC 2023
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 <mpatocka at redhat.com>
---
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.
More information about the dm-devel
mailing list