]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) 2003 Christophe Saout <[email protected]> | |
3 | * | |
4 | * This file is released under the GPL. | |
5 | */ | |
6 | ||
586e80e6 | 7 | #include <linux/device-mapper.h> |
1da177e4 LT |
8 | |
9 | #include <linux/module.h> | |
10 | #include <linux/init.h> | |
11 | #include <linux/bio.h> | |
12 | ||
72d94861 AK |
13 | #define DM_MSG_PREFIX "zero" |
14 | ||
1da177e4 LT |
15 | /* |
16 | * Construct a dummy mapping that only returns zeros | |
17 | */ | |
18 | static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv) | |
19 | { | |
20 | if (argc != 0) { | |
72d94861 | 21 | ti->error = "No arguments required"; |
1da177e4 LT |
22 | return -EINVAL; |
23 | } | |
24 | ||
25 | return 0; | |
26 | } | |
27 | ||
28 | /* | |
29 | * Return zeros only on reads | |
30 | */ | |
31 | static int zero_map(struct dm_target *ti, struct bio *bio, | |
32 | union map_info *map_context) | |
33 | { | |
34 | switch(bio_rw(bio)) { | |
35 | case READ: | |
36 | zero_fill_bio(bio); | |
37 | break; | |
38 | case READA: | |
39 | /* readahead of null bytes only wastes buffer cache */ | |
40 | return -EIO; | |
41 | case WRITE: | |
42 | /* writes get silently dropped */ | |
43 | break; | |
44 | } | |
45 | ||
6712ecf8 | 46 | bio_endio(bio, 0); |
1da177e4 LT |
47 | |
48 | /* accepted bio, don't make new request */ | |
d2a7ad29 | 49 | return DM_MAPIO_SUBMITTED; |
1da177e4 LT |
50 | } |
51 | ||
52 | static struct target_type zero_target = { | |
53 | .name = "zero", | |
54 | .version = {1, 0, 0}, | |
55 | .module = THIS_MODULE, | |
56 | .ctr = zero_ctr, | |
57 | .map = zero_map, | |
58 | }; | |
59 | ||
5e198d94 | 60 | static int __init dm_zero_init(void) |
1da177e4 LT |
61 | { |
62 | int r = dm_register_target(&zero_target); | |
63 | ||
64 | if (r < 0) | |
72d94861 | 65 | DMERR("register failed %d", r); |
1da177e4 LT |
66 | |
67 | return r; | |
68 | } | |
69 | ||
5e198d94 | 70 | static void __exit dm_zero_exit(void) |
1da177e4 LT |
71 | { |
72 | int r = dm_unregister_target(&zero_target); | |
73 | ||
74 | if (r < 0) | |
72d94861 | 75 | DMERR("unregister failed %d", r); |
1da177e4 LT |
76 | } |
77 | ||
78 | module_init(dm_zero_init) | |
79 | module_exit(dm_zero_exit) | |
80 | ||
81 | MODULE_AUTHOR("Christophe Saout <[email protected]>"); | |
82 | MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros"); | |
83 | MODULE_LICENSE("GPL"); |