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;
35 * Return zeros only on reads
37 static int zero_map(struct dm_target *ti, struct bio *bio)
39 switch (bio_op(bio)) {
41 if (bio->bi_opf & REQ_RAHEAD) {
42 /* readahead of null bytes only wastes buffer cache */
48 /* writes get silently dropped */
56 /* accepted bio, don't make new request */
57 return DM_MAPIO_SUBMITTED;
60 static struct target_type zero_target = {
63 .features = DM_TARGET_NOWAIT,
64 .module = THIS_MODULE,
69 static int __init dm_zero_init(void)
71 int r = dm_register_target(&zero_target);
74 DMERR("register failed %d", r);
79 static void __exit dm_zero_exit(void)
81 dm_unregister_target(&zero_target);
84 module_init(dm_zero_init)
85 module_exit(dm_zero_exit)
88 MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
89 MODULE_LICENSE("GPL");