blob: bbc97030c0c200eb35160beddb0342693c7c7250 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
3 *
4 * This file is released under the GPL.
5 */
6
Mikulas Patocka586e80e2008-10-21 17:44:59 +01007#include <linux/device-mapper.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/bio.h>
12
Alasdair G Kergon72d94862006-06-26 00:27:35 -070013#define DM_MSG_PREFIX "zero"
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*
16 * Construct a dummy mapping that only returns zeros
17 */
18static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
19{
20 if (argc != 0) {
Alasdair G Kergon72d94862006-06-26 00:27:35 -070021 ti->error = "No arguments required";
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 return -EINVAL;
23 }
24
25 return 0;
26}
27
28/*
29 * Return zeros only on reads
30 */
31static 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
NeilBrown6712ecf2007-09-27 12:47:43 +020046 bio_endio(bio, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48 /* accepted bio, don't make new request */
Kiyoshi Uedad2a7ad22006-12-08 02:41:06 -080049 return DM_MAPIO_SUBMITTED;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
52static 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
Alasdair G Kergon5e198d92005-05-05 16:16:09 -070060static int __init dm_zero_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
62 int r = dm_register_target(&zero_target);
63
64 if (r < 0)
Alasdair G Kergon72d94862006-06-26 00:27:35 -070065 DMERR("register failed %d", r);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 return r;
68}
69
Alasdair G Kergon5e198d92005-05-05 16:16:09 -070070static void __exit dm_zero_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Mikulas Patocka10d3bd02009-01-06 03:04:58 +000072 dm_unregister_target(&zero_target);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
75module_init(dm_zero_init)
76module_exit(dm_zero_exit)
77
78MODULE_AUTHOR("Christophe Saout <christophe@saout.de>");
79MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
80MODULE_LICENSE("GPL");