acpi_pad: build only on X86
[linux-2.6/linux-acpi-2.6.git] / drivers / md / dm-zero.c
blobbbc97030c0c200eb35160beddb0342693c7c7250
1 /*
2 * Copyright (C) 2003 Christophe Saout <christophe@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;
25 return 0;
29 * Return zeros only on reads
31 static int zero_map(struct dm_target *ti, struct bio *bio,
32 union map_info *map_context)
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;
46 bio_endio(bio, 0);
48 /* accepted bio, don't make new request */
49 return DM_MAPIO_SUBMITTED;
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,
60 static int __init dm_zero_init(void)
62 int r = dm_register_target(&zero_target);
64 if (r < 0)
65 DMERR("register failed %d", r);
67 return r;
70 static void __exit dm_zero_exit(void)
72 dm_unregister_target(&zero_target);
75 module_init(dm_zero_init)
76 module_exit(dm_zero_exit)
78 MODULE_AUTHOR("Christophe Saout <christophe@saout.de>");
79 MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
80 MODULE_LICENSE("GPL");