Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / md / dm-zero.c
blobfaa1dbffc8b4a0f4b31cf07588a5a8b932ffb742
1 /*
2 * Copyright (C) 2003 Jana Saout <jana@saout.de>
4 * This file is released under the GPL.
5 */
7 #include <linux/device-mapper.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/bio.h>
13 #define DM_MSG_PREFIX "zero"
16 * Construct a dummy mapping that only returns zeros
18 static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
20 if (argc != 0) {
21 ti->error = "No arguments required";
22 return -EINVAL;
26 * Silently drop discards, avoiding -EOPNOTSUPP.
28 ti->num_discard_bios = 1;
30 return 0;
34 * Return zeros only on reads
36 static int zero_map(struct dm_target *ti, struct bio *bio)
38 switch (bio_op(bio)) {
39 case REQ_OP_READ:
40 if (bio->bi_opf & REQ_RAHEAD) {
41 /* readahead of null bytes only wastes buffer cache */
42 return DM_MAPIO_KILL;
44 zero_fill_bio(bio);
45 break;
46 case REQ_OP_WRITE:
47 /* writes get silently dropped */
48 break;
49 default:
50 return DM_MAPIO_KILL;
53 bio_endio(bio);
55 /* accepted bio, don't make new request */
56 return DM_MAPIO_SUBMITTED;
59 static struct target_type zero_target = {
60 .name = "zero",
61 .version = {1, 1, 0},
62 .features = DM_TARGET_NOWAIT,
63 .module = THIS_MODULE,
64 .ctr = zero_ctr,
65 .map = zero_map,
68 static int __init dm_zero_init(void)
70 int r = dm_register_target(&zero_target);
72 if (r < 0)
73 DMERR("register failed %d", r);
75 return r;
78 static void __exit dm_zero_exit(void)
80 dm_unregister_target(&zero_target);
83 module_init(dm_zero_init)
84 module_exit(dm_zero_exit)
86 MODULE_AUTHOR("Jana Saout <jana@saout.de>");
87 MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
88 MODULE_LICENSE("GPL");