Skip to content

Commit 00065f9

Browse files
Mikulas PatockaMike Snitzer
authored andcommitted
dm zero: add discard support
Add zero_io_hints() and set discard limits so that the zero target advertises support for discards. The zero target will ignore discards. This 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@redhat.com> Tested-by: Milan Broz <gmazyland@gmail.com> Signed-off-by: Mike Snitzer <snitzer@kernel.org>
1 parent 85c938e commit 00065f9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

drivers/md/dm-zero.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
2727
* Silently drop discards, avoiding -EOPNOTSUPP.
2828
*/
2929
ti->num_discard_bios = 1;
30+
ti->discards_supported = true;
3031

3132
return 0;
3233
}
@@ -45,6 +46,7 @@ static int zero_map(struct dm_target *ti, struct bio *bio)
4546
zero_fill_bio(bio);
4647
break;
4748
case REQ_OP_WRITE:
49+
case REQ_OP_DISCARD:
4850
/* writes get silently dropped */
4951
break;
5052
default:
@@ -57,13 +59,21 @@ static int zero_map(struct dm_target *ti, struct bio *bio)
5759
return DM_MAPIO_SUBMITTED;
5860
}
5961

62+
static void zero_io_hints(struct dm_target *ti, struct queue_limits *limits)
63+
{
64+
limits->max_discard_sectors = UINT_MAX;
65+
limits->max_hw_discard_sectors = UINT_MAX;
66+
limits->discard_granularity = 512;
67+
}
68+
6069
static struct target_type zero_target = {
6170
.name = "zero",
62-
.version = {1, 1, 0},
71+
.version = {1, 2, 0},
6372
.features = DM_TARGET_NOWAIT,
6473
.module = THIS_MODULE,
6574
.ctr = zero_ctr,
6675
.map = zero_map,
76+
.io_hints = zero_io_hints,
6777
};
6878

6979
static int __init dm_zero_init(void)

0 commit comments

Comments
 (0)