1 // SPDX-License-Identifier: GPL-2.0-only
5 * This file is released under the GPL.
8 #include <linux/device-mapper.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/bio.h>
14 #define DM_MSG_PREFIX "zero"
17 * Construct a dummy mapping that only returns zeros
19 static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
22 ti->error = "No arguments required";
27 * Silently drop discards, avoiding -EOPNOTSUPP.
29 ti->num_discard_bios = 1;
30 ti->discards_supported = true;
36 * Return zeros only on reads
38 static int zero_map(struct dm_target *ti, struct bio *bio)
40 switch (bio_op(bio)) {
42 if (bio->bi_opf & REQ_RAHEAD) {
43 /* readahead of null bytes only wastes buffer cache */
50 /* writes get silently dropped */
58 /* accepted bio, don't make new request */
59 return DM_MAPIO_SUBMITTED;
62 static void zero_io_hints(struct dm_target *ti, struct queue_limits *limits)
64 limits->max_hw_discard_sectors = UINT_MAX;
65 limits->discard_granularity = 512;
68 static struct target_type zero_target = {
71 .features = DM_TARGET_NOWAIT,
72 .module = THIS_MODULE,
75 .io_hints = zero_io_hints,
80 MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
81 MODULE_LICENSE("GPL");