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