Linux Audio

Check our new training course

Loading...
v6.2
 
 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	.features = DM_TARGET_NOWAIT,
63	.module = THIS_MODULE,
64	.ctr    = zero_ctr,
65	.map    = zero_map,
 
66};
67
68static int __init dm_zero_init(void)
69{
70	int r = dm_register_target(&zero_target);
71
72	if (r < 0)
73		DMERR("register failed %d", r);
74
75	return r;
76}
77
78static void __exit dm_zero_exit(void)
79{
80	dm_unregister_target(&zero_target);
81}
82
83module_init(dm_zero_init)
84module_exit(dm_zero_exit)
85
86MODULE_AUTHOR("Jana Saout <jana@saout.de>");
87MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
88MODULE_LICENSE("GPL");
v6.8
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * Copyright (C) 2003 Jana Saout <jana@saout.de>
 4 *
 5 * This file is released under the GPL.
 6 */
 7
 8#include <linux/device-mapper.h>
 9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/bio.h>
13
14#define DM_MSG_PREFIX "zero"
15
16/*
17 * Construct a dummy mapping that only returns zeros
18 */
19static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
20{
21	if (argc != 0) {
22		ti->error = "No arguments required";
23		return -EINVAL;
24	}
25
26	/*
27	 * Silently drop discards, avoiding -EOPNOTSUPP.
28	 */
29	ti->num_discard_bios = 1;
30	ti->discards_supported = true;
31
32	return 0;
33}
34
35/*
36 * Return zeros only on reads
37 */
38static int zero_map(struct dm_target *ti, struct bio *bio)
39{
40	switch (bio_op(bio)) {
41	case REQ_OP_READ:
42		if (bio->bi_opf & REQ_RAHEAD) {
43			/* readahead of null bytes only wastes buffer cache */
44			return DM_MAPIO_KILL;
45		}
46		zero_fill_bio(bio);
47		break;
48	case REQ_OP_WRITE:
49	case REQ_OP_DISCARD:
50		/* writes get silently dropped */
51		break;
52	default:
53		return DM_MAPIO_KILL;
54	}
55
56	bio_endio(bio);
57
58	/* accepted bio, don't make new request */
59	return DM_MAPIO_SUBMITTED;
60}
61
62static void zero_io_hints(struct dm_target *ti, struct queue_limits *limits)
63{
64	limits->max_discard_sectors = UINT_MAX;
65	limits->max_hw_discard_sectors = UINT_MAX;
66	limits->discard_granularity = 512;
67}
68
69static struct target_type zero_target = {
70	.name   = "zero",
71	.version = {1, 2, 0},
72	.features = DM_TARGET_NOWAIT,
73	.module = THIS_MODULE,
74	.ctr    = zero_ctr,
75	.map    = zero_map,
76	.io_hints = zero_io_hints,
77};
78module_dm(zero);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
80MODULE_AUTHOR("Jana Saout <jana@saout.de>");
81MODULE_DESCRIPTION(DM_NAME " dummy target returning zeros");
82MODULE_LICENSE("GPL");