dm_target_zero.c revision 1.7.2.4 1 1.7.2.4 yamt /* $NetBSD: dm_target_zero.c,v 1.7.2.4 2010/03/11 15:03:26 yamt Exp $ */
2 1.7.2.2 yamt
3 1.7.2.2 yamt /*
4 1.7.2.2 yamt * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.7.2.2 yamt * All rights reserved.
6 1.7.2.2 yamt *
7 1.7.2.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.7.2.2 yamt * by Adam Hamsik.
9 1.7.2.2 yamt *
10 1.7.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.7.2.2 yamt * modification, are permitted provided that the following conditions
12 1.7.2.2 yamt * are met:
13 1.7.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.7.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.7.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.7.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.7.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.7.2.2 yamt *
19 1.7.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.7.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.7.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.7.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.7.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.7.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.7.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.7.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.7.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.7.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.7.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.7.2.2 yamt */
31 1.7.2.2 yamt
32 1.7.2.2 yamt
33 1.7.2.2 yamt /*
34 1.7.2.2 yamt * This file implements initial version of device-mapper zero target.
35 1.7.2.2 yamt */
36 1.7.2.2 yamt #include <sys/types.h>
37 1.7.2.2 yamt #include <sys/param.h>
38 1.7.2.2 yamt
39 1.7.2.2 yamt #include <sys/buf.h>
40 1.7.2.2 yamt
41 1.7.2.2 yamt #include "dm.h"
42 1.7.2.2 yamt
43 1.7.2.2 yamt #ifdef DM_TARGET_MODULE
44 1.7.2.2 yamt /*
45 1.7.2.2 yamt * Every target can be compiled directly to dm driver or as a
46 1.7.2.2 yamt * separate module this part of target is used for loading targets
47 1.7.2.2 yamt * to dm driver.
48 1.7.2.2 yamt * Target can be unloaded from kernel only if there are no users of
49 1.7.2.2 yamt * it e.g. there are no devices which uses that target.
50 1.7.2.2 yamt */
51 1.7.2.2 yamt #include <sys/kernel.h>
52 1.7.2.2 yamt #include <sys/module.h>
53 1.7.2.2 yamt
54 1.7.2.2 yamt MODULE(MODULE_CLASS_MISC, dm_target_zero, "dm");
55 1.7.2.2 yamt
56 1.7.2.2 yamt static int
57 1.7.2.2 yamt dm_target_zero_modcmd(modcmd_t cmd, void *arg)
58 1.7.2.2 yamt {
59 1.7.2.2 yamt dm_target_t *dmt;
60 1.7.2.2 yamt int r;
61 1.7.2.2 yamt dmt = NULL;
62 1.7.2.4 yamt
63 1.7.2.2 yamt switch (cmd) {
64 1.7.2.2 yamt case MODULE_CMD_INIT:
65 1.7.2.4 yamt if ((dmt = dm_target_lookup("zero")) != NULL) {
66 1.7.2.2 yamt dm_target_unbusy(dmt);
67 1.7.2.2 yamt return EEXIST;
68 1.7.2.2 yamt }
69 1.7.2.2 yamt dmt = dm_target_alloc("zero");
70 1.7.2.4 yamt
71 1.7.2.2 yamt dmt->version[0] = 1;
72 1.7.2.2 yamt dmt->version[1] = 0;
73 1.7.2.2 yamt dmt->version[2] = 0;
74 1.7.2.2 yamt strlcpy(dmt->name, "zero", DM_MAX_TYPE_NAME);
75 1.7.2.2 yamt dmt->init = &dm_target_zero_init;
76 1.7.2.2 yamt dmt->status = &dm_target_zero_status;
77 1.7.2.2 yamt dmt->strategy = &dm_target_zero_strategy;
78 1.7.2.2 yamt dmt->deps = &dm_target_zero_deps;
79 1.7.2.2 yamt dmt->destroy = &dm_target_zero_destroy;
80 1.7.2.2 yamt dmt->upcall = &dm_target_zero_upcall;
81 1.7.2.2 yamt
82 1.7.2.2 yamt r = dm_target_insert(dmt);
83 1.7.2.2 yamt break;
84 1.7.2.2 yamt
85 1.7.2.2 yamt case MODULE_CMD_FINI:
86 1.7.2.2 yamt r = dm_target_rem("zero");
87 1.7.2.2 yamt
88 1.7.2.2 yamt break;
89 1.7.2.2 yamt
90 1.7.2.2 yamt case MODULE_CMD_STAT:
91 1.7.2.2 yamt return ENOTTY;
92 1.7.2.2 yamt
93 1.7.2.2 yamt default:
94 1.7.2.2 yamt return ENOTTY;
95 1.7.2.2 yamt }
96 1.7.2.2 yamt
97 1.7.2.2 yamt return r;
98 1.7.2.2 yamt }
99 1.7.2.2 yamt #endif
100 1.7.2.2 yamt
101 1.7.2.2 yamt /*
102 1.7.2.2 yamt * Zero target init function. This target doesn't need
103 1.7.2.2 yamt * target specific config area.
104 1.7.2.2 yamt */
105 1.7.2.2 yamt int
106 1.7.2.4 yamt dm_target_zero_init(dm_dev_t * dmv, void **target_config, char *argv)
107 1.7.2.2 yamt {
108 1.7.2.2 yamt
109 1.7.2.2 yamt printf("Zero target init function called!!\n");
110 1.7.2.2 yamt
111 1.7.2.2 yamt dmv->dev_type = DM_ZERO_DEV;
112 1.7.2.4 yamt
113 1.7.2.2 yamt *target_config = NULL;
114 1.7.2.4 yamt
115 1.7.2.2 yamt return 0;
116 1.7.2.2 yamt }
117 1.7.2.2 yamt /* Status routine called to get params string. */
118 1.7.2.2 yamt char *
119 1.7.2.2 yamt dm_target_zero_status(void *target_config)
120 1.7.2.2 yamt {
121 1.7.2.2 yamt return NULL;
122 1.7.2.4 yamt }
123 1.7.2.4 yamt
124 1.7.2.2 yamt
125 1.7.2.2 yamt /*
126 1.7.2.2 yamt * This routine does IO operations.
127 1.7.2.2 yamt */
128 1.7.2.2 yamt int
129 1.7.2.4 yamt dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp)
130 1.7.2.2 yamt {
131 1.7.2.2 yamt
132 1.7.2.2 yamt /* printf("Zero target read function called %d!!\n", bp->b_bcount); */
133 1.7.2.2 yamt
134 1.7.2.4 yamt memset(bp->b_data, 0, bp->b_bcount);
135 1.7.2.4 yamt bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure
136 1.7.2.4 yamt * that there is no other io to done */
137 1.7.2.4 yamt
138 1.7.2.2 yamt biodone(bp);
139 1.7.2.2 yamt
140 1.7.2.2 yamt return 0;
141 1.7.2.2 yamt }
142 1.7.2.2 yamt /* Doesn't not need to do anything here. */
143 1.7.2.2 yamt int
144 1.7.2.4 yamt dm_target_zero_destroy(dm_table_entry_t * table_en)
145 1.7.2.2 yamt {
146 1.7.2.2 yamt table_en->target_config = NULL;
147 1.7.2.2 yamt
148 1.7.2.2 yamt /* Unbusy target so we can unload it */
149 1.7.2.2 yamt dm_target_unbusy(table_en->target);
150 1.7.2.4 yamt
151 1.7.2.2 yamt return 0;
152 1.7.2.2 yamt }
153 1.7.2.2 yamt /* Doesn't not need to do anything here. */
154 1.7.2.2 yamt int
155 1.7.2.4 yamt dm_target_zero_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
156 1.7.2.4 yamt {
157 1.7.2.2 yamt return 0;
158 1.7.2.2 yamt }
159 1.7.2.2 yamt /* Unsuported for this target. */
160 1.7.2.2 yamt int
161 1.7.2.4 yamt dm_target_zero_upcall(dm_table_entry_t * table_en, struct buf * bp)
162 1.7.2.2 yamt {
163 1.7.2.2 yamt return 0;
164 1.7.2.2 yamt }
165