dm_target_zero.c revision 1.7.2.5 1 1.7.2.5 yamt /* $NetBSD: dm_target_zero.c,v 1.7.2.5 2010/08/11 22:53:21 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.5 yamt /* dm_target_zero.c */
44 1.7.2.5 yamt int dm_target_zero_init(dm_dev_t *, void**, char *);
45 1.7.2.5 yamt char * dm_target_zero_status(void *);
46 1.7.2.5 yamt int dm_target_zero_strategy(dm_table_entry_t *, struct buf *);
47 1.7.2.5 yamt int dm_target_zero_sync(dm_table_entry_t *);
48 1.7.2.5 yamt int dm_target_zero_destroy(dm_table_entry_t *);
49 1.7.2.5 yamt int dm_target_zero_deps(dm_table_entry_t *, prop_array_t);
50 1.7.2.5 yamt int dm_target_zero_upcall(dm_table_entry_t *, struct buf *);
51 1.7.2.5 yamt
52 1.7.2.2 yamt #ifdef DM_TARGET_MODULE
53 1.7.2.2 yamt /*
54 1.7.2.2 yamt * Every target can be compiled directly to dm driver or as a
55 1.7.2.2 yamt * separate module this part of target is used for loading targets
56 1.7.2.2 yamt * to dm driver.
57 1.7.2.2 yamt * Target can be unloaded from kernel only if there are no users of
58 1.7.2.2 yamt * it e.g. there are no devices which uses that target.
59 1.7.2.2 yamt */
60 1.7.2.2 yamt #include <sys/kernel.h>
61 1.7.2.2 yamt #include <sys/module.h>
62 1.7.2.2 yamt
63 1.7.2.2 yamt MODULE(MODULE_CLASS_MISC, dm_target_zero, "dm");
64 1.7.2.2 yamt
65 1.7.2.2 yamt static int
66 1.7.2.2 yamt dm_target_zero_modcmd(modcmd_t cmd, void *arg)
67 1.7.2.2 yamt {
68 1.7.2.2 yamt dm_target_t *dmt;
69 1.7.2.2 yamt int r;
70 1.7.2.2 yamt dmt = NULL;
71 1.7.2.4 yamt
72 1.7.2.2 yamt switch (cmd) {
73 1.7.2.2 yamt case MODULE_CMD_INIT:
74 1.7.2.4 yamt if ((dmt = dm_target_lookup("zero")) != NULL) {
75 1.7.2.2 yamt dm_target_unbusy(dmt);
76 1.7.2.2 yamt return EEXIST;
77 1.7.2.2 yamt }
78 1.7.2.2 yamt dmt = dm_target_alloc("zero");
79 1.7.2.4 yamt
80 1.7.2.2 yamt dmt->version[0] = 1;
81 1.7.2.2 yamt dmt->version[1] = 0;
82 1.7.2.2 yamt dmt->version[2] = 0;
83 1.7.2.2 yamt strlcpy(dmt->name, "zero", DM_MAX_TYPE_NAME);
84 1.7.2.2 yamt dmt->init = &dm_target_zero_init;
85 1.7.2.2 yamt dmt->status = &dm_target_zero_status;
86 1.7.2.2 yamt dmt->strategy = &dm_target_zero_strategy;
87 1.7.2.5 yamt dmt->sync = &dm_target_zero_sync;
88 1.7.2.2 yamt dmt->deps = &dm_target_zero_deps;
89 1.7.2.2 yamt dmt->destroy = &dm_target_zero_destroy;
90 1.7.2.2 yamt dmt->upcall = &dm_target_zero_upcall;
91 1.7.2.2 yamt
92 1.7.2.2 yamt r = dm_target_insert(dmt);
93 1.7.2.2 yamt break;
94 1.7.2.2 yamt
95 1.7.2.2 yamt case MODULE_CMD_FINI:
96 1.7.2.2 yamt r = dm_target_rem("zero");
97 1.7.2.2 yamt
98 1.7.2.2 yamt break;
99 1.7.2.2 yamt
100 1.7.2.2 yamt case MODULE_CMD_STAT:
101 1.7.2.2 yamt return ENOTTY;
102 1.7.2.2 yamt
103 1.7.2.2 yamt default:
104 1.7.2.2 yamt return ENOTTY;
105 1.7.2.2 yamt }
106 1.7.2.2 yamt
107 1.7.2.2 yamt return r;
108 1.7.2.2 yamt }
109 1.7.2.2 yamt #endif
110 1.7.2.2 yamt
111 1.7.2.2 yamt /*
112 1.7.2.2 yamt * Zero target init function. This target doesn't need
113 1.7.2.2 yamt * target specific config area.
114 1.7.2.2 yamt */
115 1.7.2.2 yamt int
116 1.7.2.4 yamt dm_target_zero_init(dm_dev_t * dmv, void **target_config, char *argv)
117 1.7.2.2 yamt {
118 1.7.2.2 yamt
119 1.7.2.2 yamt printf("Zero target init function called!!\n");
120 1.7.2.2 yamt
121 1.7.2.2 yamt dmv->dev_type = DM_ZERO_DEV;
122 1.7.2.4 yamt
123 1.7.2.2 yamt *target_config = NULL;
124 1.7.2.4 yamt
125 1.7.2.2 yamt return 0;
126 1.7.2.2 yamt }
127 1.7.2.2 yamt /* Status routine called to get params string. */
128 1.7.2.2 yamt char *
129 1.7.2.2 yamt dm_target_zero_status(void *target_config)
130 1.7.2.2 yamt {
131 1.7.2.2 yamt return NULL;
132 1.7.2.4 yamt }
133 1.7.2.4 yamt
134 1.7.2.2 yamt
135 1.7.2.2 yamt /*
136 1.7.2.2 yamt * This routine does IO operations.
137 1.7.2.2 yamt */
138 1.7.2.2 yamt int
139 1.7.2.4 yamt dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp)
140 1.7.2.2 yamt {
141 1.7.2.2 yamt
142 1.7.2.2 yamt /* printf("Zero target read function called %d!!\n", bp->b_bcount); */
143 1.7.2.2 yamt
144 1.7.2.4 yamt memset(bp->b_data, 0, bp->b_bcount);
145 1.7.2.4 yamt bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure
146 1.7.2.4 yamt * that there is no other io to done */
147 1.7.2.4 yamt
148 1.7.2.2 yamt biodone(bp);
149 1.7.2.2 yamt
150 1.7.2.2 yamt return 0;
151 1.7.2.2 yamt }
152 1.7.2.5 yamt /* Sync underlying disk caches. */
153 1.7.2.5 yamt int
154 1.7.2.5 yamt dm_target_zero_sync(dm_table_entry_t * table_en)
155 1.7.2.5 yamt {
156 1.7.2.5 yamt
157 1.7.2.5 yamt return 0;
158 1.7.2.5 yamt }
159 1.7.2.2 yamt /* Doesn't not need to do anything here. */
160 1.7.2.2 yamt int
161 1.7.2.4 yamt dm_target_zero_destroy(dm_table_entry_t * table_en)
162 1.7.2.2 yamt {
163 1.7.2.2 yamt table_en->target_config = NULL;
164 1.7.2.2 yamt
165 1.7.2.2 yamt /* Unbusy target so we can unload it */
166 1.7.2.2 yamt dm_target_unbusy(table_en->target);
167 1.7.2.4 yamt
168 1.7.2.2 yamt return 0;
169 1.7.2.2 yamt }
170 1.7.2.2 yamt /* Doesn't not need to do anything here. */
171 1.7.2.2 yamt int
172 1.7.2.4 yamt dm_target_zero_deps(dm_table_entry_t * table_en, prop_array_t prop_array)
173 1.7.2.4 yamt {
174 1.7.2.2 yamt return 0;
175 1.7.2.2 yamt }
176 1.7.2.2 yamt /* Unsuported for this target. */
177 1.7.2.2 yamt int
178 1.7.2.4 yamt dm_target_zero_upcall(dm_table_entry_t * table_en, struct buf * bp)
179 1.7.2.2 yamt {
180 1.7.2.2 yamt return 0;
181 1.7.2.2 yamt }
182