Linux Audio

Check our new training course

Loading...
v3.1
 1/*
 2 * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
 3 *
 4 * This file is released under the GPL.
 5 */
 6
 7#include <linux/device-mapper.h>
 8
 9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/bio.h>
12
13#define DM_MSG_PREFIX "zero"
14
15/*
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) {
21		ti->error = "No arguments required";
22		return -EINVAL;
23	}
24
25	/*
26	 * Silently drop discards, avoiding -EOPNOTSUPP.
27	 */
28	ti->num_discard_requests = 1;
29
30	return 0;
31}
32
33/*
34 * Return zeros only on reads
35 */
36static int zero_map(struct dm_target *ti, struct bio *bio,
37		      union map_info *map_context)
38{
39	switch(bio_rw(bio)) {
40	case READ:
 
 
 
 
41		zero_fill_bio(bio);
42		break;
43	case READA:
44		/* readahead of null bytes only wastes buffer cache */
45		return -EIO;
46	case WRITE:
47		/* writes get silently dropped */
48		break;
 
 
49	}
50
51	bio_endio(bio, 0);
52
53	/* accepted bio, don't make new request */
54	return DM_MAPIO_SUBMITTED;
55}
56
57static struct target_type zero_target = {
58	.name   = "zero",
59	.version = {1, 0, 0},
60	.module = THIS_MODULE,
61	.ctr    = zero_ctr,
62	.map    = zero_map,
63};
64
65static int __init dm_zero_init(void)
66{
67	int r = dm_register_target(&zero_target);
68
69	if (r < 0)
70		DMERR("register failed %d", r);
71
72	return r;
73}
74
75static void __exit dm_zero_exit(void)
76{
77	dm_unregister_target(&zero_target);
78}
79
80module_init(dm_zero_init)
81module_exit(dm_zero_exit)
82
83MODULE_AUTHOR("Christophe Saout <christophe@saout.de>");
84MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
85MODULE_LICENSE("GPL");
v5.4
 1/*
 2 * Copyright (C) 2003 Jana Saout <jana@saout.de>
 3 *
 4 * This file is released under the GPL.
 5 */
 6
 7#include <linux/device-mapper.h>
 8
 9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/bio.h>
12
13#define DM_MSG_PREFIX "zero"
14
15/*
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) {
21		ti->error = "No arguments required";
22		return -EINVAL;
23	}
24
25	/*
26	 * Silently drop discards, avoiding -EOPNOTSUPP.
27	 */
28	ti->num_discard_bios = 1;
29
30	return 0;
31}
32
33/*
34 * Return zeros only on reads
35 */
36static int zero_map(struct dm_target *ti, struct bio *bio)
 
37{
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;
43		}
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;
51	}
52
53	bio_endio(bio);
54
55	/* accepted bio, don't make new request */
56	return DM_MAPIO_SUBMITTED;
57}
58
59static struct target_type zero_target = {
60	.name   = "zero",
61	.version = {1, 1, 0},
62	.module = THIS_MODULE,
63	.ctr    = zero_ctr,
64	.map    = zero_map,
65};
66
67static int __init dm_zero_init(void)
68{
69	int r = dm_register_target(&zero_target);
70
71	if (r < 0)
72		DMERR("register failed %d", r);
73
74	return r;
75}
76
77static void __exit dm_zero_exit(void)
78{
79	dm_unregister_target(&zero_target);
80}
81
82module_init(dm_zero_init)
83module_exit(dm_zero_exit)
84
85MODULE_AUTHOR("Jana Saout <jana@saout.de>");
86MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
87MODULE_LICENSE("GPL");