Fri Jan 2 11:03:25 2009 UTC ()
Add stubs for mirror target, too. This target does nothing for now, but lvm
tools support mirror target and trying to create LV with mirrorred backend
caused panic in dm_table_load_ioctl.


(haad)
diff -r1.5 -r1.6 src/sys/dev/dm/dm.h
diff -r1.5 -r1.6 src/sys/dev/dm/dm_target.c
diff -r0 -r1.1 src/sys/dev/dm/dm_target_mirror.c
diff -r1.3 -r1.4 src/sys/dev/dm/files.dm
diff -r1.3 -r1.4 src/sys/modules/dm/Makefile
diff -r0 -r1.1 src/sys/modules/dm/dm_target_mirror/Makefile

cvs diff -r1.5 -r1.6 src/sys/dev/dm/dm.h (switch to unified diff)

--- src/sys/dev/dm/dm.h 2009/01/02 00:42:31 1.5
+++ src/sys/dev/dm/dm.h 2009/01/02 11:03:24 1.6
@@ -1,353 +1,361 @@ @@ -1,353 +1,361 @@
1/* $NetBSD: dm.h,v 1.5 2009/01/02 00:42:31 haad Exp $ */ 1/* $NetBSD: dm.h,v 1.6 2009/01/02 11:03:24 haad Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik. 8 * by Adam Hamsik.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _DM_DEV_H_ 32#ifndef _DM_DEV_H_
33#define _DM_DEV_H_ 33#define _DM_DEV_H_
34 34
35 35
36#ifdef _KERNEL 36#ifdef _KERNEL
37 37
38#include <sys/errno.h> 38#include <sys/errno.h>
39 39
40#include <sys/atomic.h> 40#include <sys/atomic.h>
41#include <sys/condvar.h> 41#include <sys/condvar.h>
42#include <sys/mutex.h> 42#include <sys/mutex.h>
43#include <sys/rwlock.h> 43#include <sys/rwlock.h>
44#include <sys/queue.h> 44#include <sys/queue.h>
45 45
46#define DM_MAX_TYPE_NAME 16 46#define DM_MAX_TYPE_NAME 16
47#define DM_NAME_LEN 128 47#define DM_NAME_LEN 128
48#define DM_UUID_LEN 129 48#define DM_UUID_LEN 129
49 49
50#define DM_VERSION_MAJOR 4 50#define DM_VERSION_MAJOR 4
51#define DM_VERSION_MINOR 13 51#define DM_VERSION_MINOR 13
52#define DM_VERSION_PATCHLEVEL 0 52#define DM_VERSION_PATCHLEVEL 0
53 53
54/*** Internal device-mapper structures ***/ 54/*** Internal device-mapper structures ***/
55 55
56/* 56/*
57 * A table entry describes a physical range of the logical volume. 57 * A table entry describes a physical range of the logical volume.
58 */ 58 */
59#define MAX_TARGET_STRING_LEN 32 59#define MAX_TARGET_STRING_LEN 32
60 60
61/* 61/*
62 * A device mapper table is a list of physical ranges plus the mapping target 62 * A device mapper table is a list of physical ranges plus the mapping target
63 * applied to them. 63 * applied to them.
64 */ 64 */
65 65
66typedef struct dm_table_entry { 66typedef struct dm_table_entry {
67 struct dm_dev *dm_dev; /* backlink */ 67 struct dm_dev *dm_dev; /* backlink */
68 uint64_t start; 68 uint64_t start;
69 uint64_t length; 69 uint64_t length;
70 70
71 struct dm_target *target; /* Link to table target. */ 71 struct dm_target *target; /* Link to table target. */
72 void *target_config; /* Target specific data. */ 72 void *target_config; /* Target specific data. */
73 SLIST_ENTRY(dm_table_entry) next; 73 SLIST_ENTRY(dm_table_entry) next;
74} dm_table_entry_t; 74} dm_table_entry_t;
75 75
76SLIST_HEAD(dm_table, dm_table_entry); 76SLIST_HEAD(dm_table, dm_table_entry);
77 77
78typedef struct dm_table dm_table_t; 78typedef struct dm_table dm_table_t;
79 79
80typedef struct dm_table_head { 80typedef struct dm_table_head {
81 /* Current active table is selected with this. */ 81 /* Current active table is selected with this. */
82 int cur_active_table;  82 int cur_active_table;
83 struct dm_table tables[2]; 83 struct dm_table tables[2];
84 84
85 kmutex_t table_mtx; 85 kmutex_t table_mtx;
86 kcondvar_t table_cv; /*IO waiting cv */ 86 kcondvar_t table_cv; /*IO waiting cv */
87 87
88 uint32_t io_cnt; 88 uint32_t io_cnt;
89} dm_table_head_t; 89} dm_table_head_t;
90 90
91#define MAX_DEV_NAME 32 91#define MAX_DEV_NAME 32
92 92
93/* 93/*
94 * This structure is used to store opened vnodes for disk with name. 94 * This structure is used to store opened vnodes for disk with name.
95 * I need this because devices can be opened only once, but I can 95 * I need this because devices can be opened only once, but I can
96 * have more then one device on one partition. 96 * have more then one device on one partition.
97 */ 97 */
98 98
99typedef struct dm_pdev { 99typedef struct dm_pdev {
100 char name[MAX_DEV_NAME]; 100 char name[MAX_DEV_NAME];
101 101
102 struct vnode *pdev_vnode; 102 struct vnode *pdev_vnode;
103 int ref_cnt; /* reference counter for users ofthis pdev */ 103 int ref_cnt; /* reference counter for users ofthis pdev */
104 104
105 SLIST_ENTRY(dm_pdev) next_pdev; 105 SLIST_ENTRY(dm_pdev) next_pdev;
106} dm_pdev_t; 106} dm_pdev_t;
107 107
108/* 108/*
109 * This structure is called for every device-mapper device. 109 * This structure is called for every device-mapper device.
110 * It points to SLIST of device tables and mirrored, snapshoted etc. devices. 110 * It points to SLIST of device tables and mirrored, snapshoted etc. devices.
111 */ 111 */
112TAILQ_HEAD(dm_dev_head, dm_dev) dm_devs; 112TAILQ_HEAD(dm_dev_head, dm_dev) dm_devs;
113  113
114typedef struct dm_dev { 114typedef struct dm_dev {
115 char name[DM_NAME_LEN]; 115 char name[DM_NAME_LEN];
116 char uuid[DM_UUID_LEN]; 116 char uuid[DM_UUID_LEN];
117 117
118 int minor; 118 int minor;
119 uint32_t flags; /* store communication protocol flags */ 119 uint32_t flags; /* store communication protocol flags */
120 120
121 kmutex_t dev_mtx; /* mutex for generall device lock */ 121 kmutex_t dev_mtx; /* mutex for generall device lock */
122 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */ 122 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */
123  123
124 uint32_t event_nr; 124 uint32_t event_nr;
125 uint32_t ref_cnt; 125 uint32_t ref_cnt;
126 126
127 uint32_t dev_type; 127 uint32_t dev_type;
128 128
129 dm_table_head_t table_head; 129 dm_table_head_t table_head;
130 130
131 struct dm_dev_head upcalls; 131 struct dm_dev_head upcalls;
132  132
133 struct disklabel *dk_label; /* Disklabel for this table. */ 133 struct disklabel *dk_label; /* Disklabel for this table. */
134  134
135 TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */ 135 TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */
136 136
137 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */ 137 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */
138} dm_dev_t; 138} dm_dev_t;
139 139
140/* Device types used for upcalls */ 140/* Device types used for upcalls */
141#define DM_ZERO_DEV (1 << 0) 141#define DM_ZERO_DEV (1 << 0)
142#define DM_ERROR_DEV (1 << 1)  142#define DM_ERROR_DEV (1 << 1)
143#define DM_LINEAR_DEV (1 << 2) 143#define DM_LINEAR_DEV (1 << 2)
144#define DM_MIRROR_DEV (1 << 3) 144#define DM_MIRROR_DEV (1 << 3)
145#define DM_STRIPE_DEV (1 << 4) 145#define DM_STRIPE_DEV (1 << 4)
146#define DM_SNAPSHOT_DEV (1 << 5) 146#define DM_SNAPSHOT_DEV (1 << 5)
147#define DM_SNAPSHOT_ORIG_DEV (1 << 6) 147#define DM_SNAPSHOT_ORIG_DEV (1 << 6)
148#define DM_SPARE_DEV (1 << 7) 148#define DM_SPARE_DEV (1 << 7)
149/* Set this device type only during dev remove ioctl. */ 149/* Set this device type only during dev remove ioctl. */
150#define DM_DELETING_DEV (1 << 8)  150#define DM_DELETING_DEV (1 << 8)
151 151
152 152
153/* for zero, error : dm_target->target_config == NULL */ 153/* for zero, error : dm_target->target_config == NULL */
154  154
155/* 155/*
156 * Target config is initiated with target_init function. 156 * Target config is initiated with target_init function.
157 */ 157 */
158  158
159/* for linear : */ 159/* for linear : */
160typedef struct target_linear_config { 160typedef struct target_linear_config {
161 dm_pdev_t *pdev; 161 dm_pdev_t *pdev;
162 uint64_t offset; 162 uint64_t offset;
163} dm_target_linear_config_t; 163} dm_target_linear_config_t;
164 164
165 165
166/* for mirror : */ 166/* for mirror : */
167typedef struct target_mirror_config { 167typedef struct target_mirror_config {
168#define MAX_MIRROR_COPIES 4 168#define MAX_MIRROR_COPIES 4
169 dm_pdev_t *orig; 169 dm_pdev_t *orig;
170 dm_pdev_t *copies[MAX_MIRROR_COPIES]; 170 dm_pdev_t *copies[MAX_MIRROR_COPIES];
171 171
172 /* copied blocks bitmaps administration etc*/ 172 /* copied blocks bitmaps administration etc*/
173 dm_pdev_t *log_pdev; /* for administration */ 173 dm_pdev_t *log_pdev; /* for administration */
174 uint64_t log_regionsize; /* blocksize of mirror */ 174 uint64_t log_regionsize; /* blocksize of mirror */
175 175
176 /* list of parts that still need copied etc.; run length encoded? */ 176 /* list of parts that still need copied etc.; run length encoded? */
177} dm_target_mirror_config_t; 177} dm_target_mirror_config_t;
178 178
179 179
180/* for snapshot : */ 180/* for snapshot : */
181typedef struct target_snapshot_config { 181typedef struct target_snapshot_config {
182 dm_pdev_t *tsc_snap_dev; 182 dm_pdev_t *tsc_snap_dev;
183 /* cow dev is set only for persistent snapshot devices */ 183 /* cow dev is set only for persistent snapshot devices */
184 dm_pdev_t *tsc_cow_dev; 184 dm_pdev_t *tsc_cow_dev;
185  185
186 uint64_t tsc_chunk_size; 186 uint64_t tsc_chunk_size;
187 uint32_t tsc_persistent_dev; 187 uint32_t tsc_persistent_dev;
188} dm_target_snapshot_config_t; 188} dm_target_snapshot_config_t;
189 189
190/* for snapshot-origin devices */ 190/* for snapshot-origin devices */
191typedef struct target_snapshot_origin_config { 191typedef struct target_snapshot_origin_config {
192 dm_pdev_t *tsoc_real_dev; 192 dm_pdev_t *tsoc_real_dev;
193 /* list of snapshots ? */ 193 /* list of snapshots ? */
194} dm_target_snapshot_origin_config_t; 194} dm_target_snapshot_origin_config_t;
195 195
196/* constant dm_target structures for error, zero, linear, stripes etc. */ 196/* constant dm_target structures for error, zero, linear, stripes etc. */
197typedef struct dm_target { 197typedef struct dm_target {
198 char name[DM_MAX_TYPE_NAME]; 198 char name[DM_MAX_TYPE_NAME];
199 /* Initialize target_config area */ 199 /* Initialize target_config area */
200 int (*init)(dm_dev_t *, void **, char *); 200 int (*init)(dm_dev_t *, void **, char *);
201 201
202 /* Destroy target_config area */ 202 /* Destroy target_config area */
203 int (*destroy)(dm_table_entry_t *); 203 int (*destroy)(dm_table_entry_t *);
204  204
205 int (*deps) (dm_table_entry_t *, prop_array_t); 205 int (*deps) (dm_table_entry_t *, prop_array_t);
206 /* 206 /*
207 * Status routine is called to get params string, which is target 207 * Status routine is called to get params string, which is target
208 * specific. When dm_table_status_ioctl is called with flag 208 * specific. When dm_table_status_ioctl is called with flag
209 * DM_STATUS_TABLE_FLAG I have to sent params string back. 209 * DM_STATUS_TABLE_FLAG I have to sent params string back.
210 */ 210 */
211 char * (*status)(void *); 211 char * (*status)(void *);
212 int (*strategy)(dm_table_entry_t *, struct buf *); 212 int (*strategy)(dm_table_entry_t *, struct buf *);
213 int (*upcall)(dm_table_entry_t *, struct buf *); 213 int (*upcall)(dm_table_entry_t *, struct buf *);
214  214
215 uint32_t version[3]; 215 uint32_t version[3];
216 int ref_cnt; 216 int ref_cnt;
217  217
218 TAILQ_ENTRY(dm_target) dm_target_next; 218 TAILQ_ENTRY(dm_target) dm_target_next;
219} dm_target_t; 219} dm_target_t;
220 220
221/* Interface structures */ 221/* Interface structures */
222 222
223/* 223/*
224 * This structure is used to translate command sent to kernel driver in 224 * This structure is used to translate command sent to kernel driver in
225 * <key>command</key> 225 * <key>command</key>
226 * <value></value> 226 * <value></value>
227 * to function which I can call. 227 * to function which I can call.
228 */ 228 */
229struct cmd_function { 229struct cmd_function {
230 const char *cmd; 230 const char *cmd;
231 int (*fn)(prop_dictionary_t); 231 int (*fn)(prop_dictionary_t);
232}; 232};
233 233
234/* device-mapper */ 234/* device-mapper */
235void dmgetdisklabel(struct disklabel *, dm_table_head_t *); 235void dmgetdisklabel(struct disklabel *, dm_table_head_t *);
236 236
237/* dm_ioctl.c */ 237/* dm_ioctl.c */
238int dm_dev_create_ioctl(prop_dictionary_t); 238int dm_dev_create_ioctl(prop_dictionary_t);
239int dm_dev_list_ioctl(prop_dictionary_t); 239int dm_dev_list_ioctl(prop_dictionary_t);
240int dm_dev_remove_ioctl(prop_dictionary_t); 240int dm_dev_remove_ioctl(prop_dictionary_t);
241int dm_dev_rename_ioctl(prop_dictionary_t); 241int dm_dev_rename_ioctl(prop_dictionary_t);
242int dm_dev_resume_ioctl(prop_dictionary_t); 242int dm_dev_resume_ioctl(prop_dictionary_t);
243int dm_dev_status_ioctl(prop_dictionary_t); 243int dm_dev_status_ioctl(prop_dictionary_t);
244int dm_dev_suspend_ioctl(prop_dictionary_t); 244int dm_dev_suspend_ioctl(prop_dictionary_t);
245 245
246int dm_check_version(prop_dictionary_t); 246int dm_check_version(prop_dictionary_t);
247int dm_get_version_ioctl(prop_dictionary_t); 247int dm_get_version_ioctl(prop_dictionary_t);
248int dm_list_versions_ioctl(prop_dictionary_t); 248int dm_list_versions_ioctl(prop_dictionary_t);
249 249
250int dm_table_clear_ioctl(prop_dictionary_t); 250int dm_table_clear_ioctl(prop_dictionary_t);
251int dm_table_deps_ioctl(prop_dictionary_t); 251int dm_table_deps_ioctl(prop_dictionary_t);
252int dm_table_load_ioctl(prop_dictionary_t); 252int dm_table_load_ioctl(prop_dictionary_t);
253int dm_table_status_ioctl(prop_dictionary_t); 253int dm_table_status_ioctl(prop_dictionary_t);
254 254
255/* dm_target.c */ 255/* dm_target.c */
256dm_target_t* dm_target_alloc(const char *); 256dm_target_t* dm_target_alloc(const char *);
257int dm_target_destroy(void); 257int dm_target_destroy(void);
258int dm_target_insert(dm_target_t *); 258int dm_target_insert(dm_target_t *);
259prop_array_t dm_target_prop_list(void); 259prop_array_t dm_target_prop_list(void);
260dm_target_t* dm_target_lookup(const char *); 260dm_target_t* dm_target_lookup(const char *);
261int dm_target_rem(char *); 261int dm_target_rem(char *);
262void dm_target_unbusy(dm_target_t *); 262void dm_target_unbusy(dm_target_t *);
263void dm_target_busy(dm_target_t *); 263void dm_target_busy(dm_target_t *);
264 264
265/* XXX temporally add */ 265/* XXX temporally add */
266int dm_target_init(void); 266int dm_target_init(void);
267 267
268/* dm_target_zero.c */ 268/* dm_target_zero.c */
269int dm_target_zero_init(dm_dev_t *, void**, char *); 269int dm_target_zero_init(dm_dev_t *, void**, char *);
270char * dm_target_zero_status(void *); 270char * dm_target_zero_status(void *);
271int dm_target_zero_strategy(dm_table_entry_t *, struct buf *); 271int dm_target_zero_strategy(dm_table_entry_t *, struct buf *);
272int dm_target_zero_destroy(dm_table_entry_t *); 272int dm_target_zero_destroy(dm_table_entry_t *);
273int dm_target_zero_deps(dm_table_entry_t *, prop_array_t); 273int dm_target_zero_deps(dm_table_entry_t *, prop_array_t);
274int dm_target_zero_upcall(dm_table_entry_t *, struct buf *); 274int dm_target_zero_upcall(dm_table_entry_t *, struct buf *);
275 275
276/* dm_target_error.c */ 276/* dm_target_error.c */
277int dm_target_error_init(dm_dev_t *, void**, char *); 277int dm_target_error_init(dm_dev_t *, void**, char *);
278char * dm_target_error_status(void *); 278char * dm_target_error_status(void *);
279int dm_target_error_strategy(dm_table_entry_t *, struct buf *); 279int dm_target_error_strategy(dm_table_entry_t *, struct buf *);
280int dm_target_error_deps(dm_table_entry_t *, prop_array_t); 280int dm_target_error_deps(dm_table_entry_t *, prop_array_t);
281int dm_target_error_destroy(dm_table_entry_t *); 281int dm_target_error_destroy(dm_table_entry_t *);
282int dm_target_error_upcall(dm_table_entry_t *, struct buf *); 282int dm_target_error_upcall(dm_table_entry_t *, struct buf *);
283 283
284/* dm_target_linear.c */ 284/* dm_target_linear.c */
285int dm_target_linear_init(dm_dev_t *, void**, char *); 285int dm_target_linear_init(dm_dev_t *, void**, char *);
286char * dm_target_linear_status(void *); 286char * dm_target_linear_status(void *);
287int dm_target_linear_strategy(dm_table_entry_t *, struct buf *); 287int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
288int dm_target_linear_deps(dm_table_entry_t *, prop_array_t); 288int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
289int dm_target_linear_destroy(dm_table_entry_t *); 289int dm_target_linear_destroy(dm_table_entry_t *);
290int dm_target_linear_upcall(dm_table_entry_t *, struct buf *); 290int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
291 291
292/* Generic function used to convert char to string */ 292/* Generic function used to convert char to string */
293uint64_t atoi(const char *);  293uint64_t atoi(const char *);
294 294
 295/* dm_target_mirror.c */
 296int dm_target_mirror_init(dm_dev_t *, void**, char *);
 297char * dm_target_mirror_status(void *);
 298int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *);
 299int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t);
 300int dm_target_mirror_destroy(dm_table_entry_t *);
 301int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *);
 302
295/* dm_target_stripe.c */ 303/* dm_target_stripe.c */
296int dm_target_stripe_init(dm_dev_t *, void**, char *); 304int dm_target_stripe_init(dm_dev_t *, void**, char *);
297char * dm_target_stripe_status(void *); 305char * dm_target_stripe_status(void *);
298int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *); 306int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
299int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t); 307int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
300int dm_target_stripe_destroy(dm_table_entry_t *); 308int dm_target_stripe_destroy(dm_table_entry_t *);
301int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *); 309int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
302 310
303/* dm_target_snapshot.c */ 311/* dm_target_snapshot.c */
304int dm_target_snapshot_init(dm_dev_t *, void**, char *); 312int dm_target_snapshot_init(dm_dev_t *, void**, char *);
305char * dm_target_snapshot_status(void *); 313char * dm_target_snapshot_status(void *);
306int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *); 314int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
307int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t); 315int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t);
308int dm_target_snapshot_destroy(dm_table_entry_t *); 316int dm_target_snapshot_destroy(dm_table_entry_t *);
309int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *); 317int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
310 318
311/* dm snapshot origin driver */ 319/* dm snapshot origin driver */
312int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *); 320int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *);
313char * dm_target_snapshot_orig_status(void *); 321char * dm_target_snapshot_orig_status(void *);
314int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *); 322int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
315int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t); 323int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t);
316int dm_target_snapshot_orig_destroy(dm_table_entry_t *); 324int dm_target_snapshot_orig_destroy(dm_table_entry_t *);
317int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *); 325int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
318 326
319/* dm_table.c */ 327/* dm_table.c */
320#define DM_TABLE_ACTIVE 0 328#define DM_TABLE_ACTIVE 0
321#define DM_TABLE_INACTIVE 1 329#define DM_TABLE_INACTIVE 1
322 330
323int dm_table_destroy(dm_table_head_t *, uint8_t); 331int dm_table_destroy(dm_table_head_t *, uint8_t);
324uint64_t dm_table_size(dm_table_head_t *); 332uint64_t dm_table_size(dm_table_head_t *);
325dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t); 333dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t);
326int dm_table_get_target_count(dm_table_head_t *, uint8_t); 334int dm_table_get_target_count(dm_table_head_t *, uint8_t);
327void dm_table_release(dm_table_head_t *, uint8_t s); 335void dm_table_release(dm_table_head_t *, uint8_t s);
328void dm_table_switch_tables(dm_table_head_t *); 336void dm_table_switch_tables(dm_table_head_t *);
329void dm_table_head_init(dm_table_head_t *); 337void dm_table_head_init(dm_table_head_t *);
330void dm_table_head_destroy(dm_table_head_t *); 338void dm_table_head_destroy(dm_table_head_t *);
331 339
332/* dm_dev.c */ 340/* dm_dev.c */
333dm_dev_t* dm_dev_alloc(void); 341dm_dev_t* dm_dev_alloc(void);
334void dm_dev_busy(dm_dev_t *); 342void dm_dev_busy(dm_dev_t *);
335int dm_dev_destroy(void); 343int dm_dev_destroy(void);
336int dm_dev_free(dm_dev_t *); 344int dm_dev_free(dm_dev_t *);
337int dm_dev_init(void); 345int dm_dev_init(void);
338int dm_dev_insert(dm_dev_t *); 346int dm_dev_insert(dm_dev_t *);
339dm_dev_t* dm_dev_lookup(const char *, const char *, int); 347dm_dev_t* dm_dev_lookup(const char *, const char *, int);
340prop_array_t dm_dev_prop_list(void); 348prop_array_t dm_dev_prop_list(void);
341dm_dev_t* dm_dev_rem(const char *, const char *, int); 349dm_dev_t* dm_dev_rem(const char *, const char *, int);
342/*int dm_dev_test_minor(int);*/ 350/*int dm_dev_test_minor(int);*/
343void dm_dev_unbusy(dm_dev_t *); 351void dm_dev_unbusy(dm_dev_t *);
344 352
345/* dm_pdev.c */ 353/* dm_pdev.c */
346int dm_pdev_decr(dm_pdev_t *); 354int dm_pdev_decr(dm_pdev_t *);
347int dm_pdev_destroy(void); 355int dm_pdev_destroy(void);
348int dm_pdev_init(void); 356int dm_pdev_init(void);
349dm_pdev_t* dm_pdev_insert(const char *); 357dm_pdev_t* dm_pdev_insert(const char *);
350 358
351#endif /*_KERNEL*/ 359#endif /*_KERNEL*/
352 360
353#endif /*_DM_DEV_H_*/ 361#endif /*_DM_DEV_H_*/

cvs diff -r1.5 -r1.6 src/sys/dev/dm/dm_target.c (switch to unified diff)

--- src/sys/dev/dm/dm_target.c 2009/01/02 00:42:31 1.5
+++ src/sys/dev/dm/dm_target.c 2009/01/02 11:03:24 1.6
@@ -1,324 +1,312 @@ @@ -1,324 +1,312 @@
1/* $NetBSD: dm_target.c,v 1.5 2009/01/02 00:42:31 haad Exp $ */ 1/* $NetBSD: dm_target.c,v 1.6 2009/01/02 11:03:24 haad Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Hamsik. 8 * by Adam Hamsik.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code Must retain the above copyright 13 * 1. Redistributions of source code Must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/types.h> 32#include <sys/types.h>
33#include <sys/param.h> 33#include <sys/param.h>
34 34
35#include <sys/kmem.h> 35#include <sys/kmem.h>
36 36
37#include "netbsd-dm.h" 37#include "netbsd-dm.h"
38#include "dm.h" 38#include "dm.h"
39 39
40static dm_target_t* dm_target_lookup_name(const char *); 40static dm_target_t* dm_target_lookup_name(const char *);
41 41
42TAILQ_HEAD(dm_target_head, dm_target); 42TAILQ_HEAD(dm_target_head, dm_target);
43 43
44static struct dm_target_head dm_target_list = 44static struct dm_target_head dm_target_list =
45TAILQ_HEAD_INITIALIZER(dm_target_list); 45TAILQ_HEAD_INITIALIZER(dm_target_list);
46 46
47kmutex_t dm_target_mutex; 47kmutex_t dm_target_mutex;
48 48
49/* 49/*
50 * Called indirectly from dm_table_load_ioct to mark target as used. 50 * Called indirectly from dm_table_load_ioct to mark target as used.
51 */ 51 */
52void 52void
53dm_target_busy(dm_target_t *target) 53dm_target_busy(dm_target_t *target)
54{ 54{
55 target->ref_cnt++;  55 target->ref_cnt++;
56} 56}
57 57
58void 58void
59dm_target_unbusy(dm_target_t *target) 59dm_target_unbusy(dm_target_t *target)
60{ 60{
61 target->ref_cnt--; 61 target->ref_cnt--;
62} 62}
63 63
64dm_target_t * 64dm_target_t *
65dm_target_lookup(const char *dm_target_name) 65dm_target_lookup(const char *dm_target_name)
66{ 66{
67 dm_target_t *dmt; 67 dm_target_t *dmt;
68 68
69 dmt = NULL; 69 dmt = NULL;
70 70
71 mutex_enter(&dm_target_mutex); 71 mutex_enter(&dm_target_mutex);
72 72
73 if (dm_target_name != NULL) 73 if (dm_target_name != NULL)
74 dmt = dm_target_lookup_name(dm_target_name); 74 dmt = dm_target_lookup_name(dm_target_name);
75 75
76 if (dmt != NULL) 76 if (dmt != NULL)
77 dm_target_busy(dmt); 77 dm_target_busy(dmt);
78  78
79 mutex_exit(&dm_target_mutex); 79 mutex_exit(&dm_target_mutex);
80  80
81 return dmt;  81 return dmt;
82} 82}
83  83
84/* 84/*
85 * Search for name in TAIL and return apropriate pointer. 85 * Search for name in TAIL and return apropriate pointer.
86 */ 86 */
87static dm_target_t* 87static dm_target_t*
88dm_target_lookup_name(const char *dm_target_name) 88dm_target_lookup_name(const char *dm_target_name)
89{ 89{
90 dm_target_t *dm_target; 90 dm_target_t *dm_target;
91 int dlen; int slen; 91 int dlen; int slen;
92 92
93 slen = strlen(dm_target_name) + 1; 93 slen = strlen(dm_target_name) + 1;
94 94
95 TAILQ_FOREACH(dm_target, &dm_target_list, dm_target_next) { 95 TAILQ_FOREACH(dm_target, &dm_target_list, dm_target_next) {
96 dlen = strlen(dm_target->name) + 1; 96 dlen = strlen(dm_target->name) + 1;
97 97
98 if (dlen != slen) 98 if (dlen != slen)
99 continue; 99 continue;
100  100
101 if (strncmp(dm_target_name, dm_target->name, slen) == 0){ 101 if (strncmp(dm_target_name, dm_target->name, slen) == 0){
102 return dm_target; 102 return dm_target;
103 } 103 }
104 } 104 }
105 105
106 return NULL; 106 return NULL;
107} 107}
108 108
109/* 109/*
110 * Insert new target struct into the TAIL. 110 * Insert new target struct into the TAIL.
111 * dm_target 111 * dm_target
112 * contains name, version, function pointer to specifif target functions. 112 * contains name, version, function pointer to specifif target functions.
113 */ 113 */
114int 114int
115dm_target_insert(dm_target_t *dm_target) 115dm_target_insert(dm_target_t *dm_target)
116{ 116{
117 dm_target_t *dmt; 117 dm_target_t *dmt;
118  118
119 mutex_enter(&dm_target_mutex); 119 mutex_enter(&dm_target_mutex);
120 120
121 dmt = dm_target_lookup_name(dm_target->name); 121 dmt = dm_target_lookup_name(dm_target->name);
122 if (dmt != NULL) { 122 if (dmt != NULL) {
123 mutex_exit(&dm_target_mutex); 123 mutex_exit(&dm_target_mutex);
124 return EEXIST; 124 return EEXIST;
125 } 125 }
126  126
127 TAILQ_INSERT_TAIL(&dm_target_list, dm_target, dm_target_next); 127 TAILQ_INSERT_TAIL(&dm_target_list, dm_target, dm_target_next);
128 128
129 mutex_exit(&dm_target_mutex); 129 mutex_exit(&dm_target_mutex);
130  130
131 return 0; 131 return 0;
132} 132}
133 133
134 134
135/* 135/*
136 * Remove target from TAIL, target is selected with it's name. 136 * Remove target from TAIL, target is selected with it's name.
137 */ 137 */
138int 138int
139dm_target_rem(char *dm_target_name) 139dm_target_rem(char *dm_target_name)
140{ 140{
141 dm_target_t *dmt; 141 dm_target_t *dmt;
142  142
143 KASSERT(dm_target_name != NULL); 143 KASSERT(dm_target_name != NULL);
144 144
145 mutex_enter(&dm_target_mutex); 145 mutex_enter(&dm_target_mutex);
146  146
147 dmt = dm_target_lookup_name(dm_target_name); 147 dmt = dm_target_lookup_name(dm_target_name);
148 if (dmt == NULL) { 148 if (dmt == NULL) {
149 mutex_exit(&dm_target_mutex); 149 mutex_exit(&dm_target_mutex);
150 return ENOENT; 150 return ENOENT;
151 } 151 }
152  152
153 if (dmt->ref_cnt > 0) { 153 if (dmt->ref_cnt > 0) {
154 mutex_exit(&dm_target_mutex); 154 mutex_exit(&dm_target_mutex);
155 return EBUSY; 155 return EBUSY;
156 } 156 }
157  157
158 TAILQ_REMOVE(&dm_target_list, 158 TAILQ_REMOVE(&dm_target_list,
159 dmt, dm_target_next); 159 dmt, dm_target_next);
160 160
161 mutex_exit(&dm_target_mutex); 161 mutex_exit(&dm_target_mutex);
162  162
163 (void)kmem_free(dmt, sizeof(dm_target_t)); 163 (void)kmem_free(dmt, sizeof(dm_target_t));
164 164
165 return 0; 165 return 0;
166} 166}
167 167
168/* 168/*
169 * Destroy all targets and remove them from queue. 169 * Destroy all targets and remove them from queue.
170 * This routine is called from dm_detach, before module 170 * This routine is called from dm_detach, before module
171 * is unloaded. 171 * is unloaded.
172 */ 172 */
173 173
174int 174int
175dm_target_destroy(void) 175dm_target_destroy(void)
176{ 176{
177 dm_target_t *dm_target; 177 dm_target_t *dm_target;
178 178
179 mutex_enter(&dm_target_mutex); 179 mutex_enter(&dm_target_mutex);
180 while (TAILQ_FIRST(&dm_target_list) != NULL){ 180 while (TAILQ_FIRST(&dm_target_list) != NULL){
181 181
182 dm_target = TAILQ_FIRST(&dm_target_list); 182 dm_target = TAILQ_FIRST(&dm_target_list);
183  183
184 TAILQ_REMOVE(&dm_target_list, TAILQ_FIRST(&dm_target_list), 184 TAILQ_REMOVE(&dm_target_list, TAILQ_FIRST(&dm_target_list),
185 dm_target_next); 185 dm_target_next);
186  186
187 (void)kmem_free(dm_target, sizeof(dm_target_t)); 187 (void)kmem_free(dm_target, sizeof(dm_target_t));
188 } 188 }
189 mutex_exit(&dm_target_mutex); 189 mutex_exit(&dm_target_mutex);
190  190
191 mutex_destroy(&dm_target_mutex); 191 mutex_destroy(&dm_target_mutex);
192  192
193 return 0; 193 return 0;
194} 194}
195 195
196/* 196/*
197 * Allocate new target entry. 197 * Allocate new target entry.
198 */ 198 */
199dm_target_t* 199dm_target_t*
200dm_target_alloc(const char *name) 200dm_target_alloc(const char *name)
201{ 201{
202 return kmem_zalloc(sizeof(dm_target_t), KM_NOSLEEP); 202 return kmem_zalloc(sizeof(dm_target_t), KM_NOSLEEP);
203} 203}
204 204
205/* 205/*
206 * Return prop_array of dm_target dictionaries. 206 * Return prop_array of dm_target dictionaries.
207 */ 207 */
208prop_array_t 208prop_array_t
209dm_target_prop_list(void) 209dm_target_prop_list(void)
210{ 210{
211 prop_array_t target_array,ver; 211 prop_array_t target_array,ver;
212 prop_dictionary_t target_dict; 212 prop_dictionary_t target_dict;
213 dm_target_t *dm_target; 213 dm_target_t *dm_target;
214 214
215 size_t i; 215 size_t i;
216 216
217 target_array = prop_array_create(); 217 target_array = prop_array_create();
218 218
219 mutex_enter(&dm_target_mutex); 219 mutex_enter(&dm_target_mutex);
220  220
221 TAILQ_FOREACH (dm_target, &dm_target_list, dm_target_next){ 221 TAILQ_FOREACH (dm_target, &dm_target_list, dm_target_next){
222 222
223 target_dict = prop_dictionary_create(); 223 target_dict = prop_dictionary_create();
224 ver = prop_array_create(); 224 ver = prop_array_create();
225 prop_dictionary_set_cstring(target_dict, DM_TARGETS_NAME, 225 prop_dictionary_set_cstring(target_dict, DM_TARGETS_NAME,
226 dm_target->name); 226 dm_target->name);
227 227
228 for (i = 0; i < 3; i++) 228 for (i = 0; i < 3; i++)
229 prop_array_add_uint32(ver, dm_target->version[i]); 229 prop_array_add_uint32(ver, dm_target->version[i]);
230 230
231 prop_dictionary_set(target_dict, DM_TARGETS_VERSION, ver); 231 prop_dictionary_set(target_dict, DM_TARGETS_VERSION, ver);
232 prop_array_add(target_array, target_dict); 232 prop_array_add(target_array, target_dict);
233 233
234 prop_object_release(ver); 234 prop_object_release(ver);
235 prop_object_release(target_dict); 235 prop_object_release(target_dict);
236 } 236 }
237 237
238 mutex_exit(&dm_target_mutex); 238 mutex_exit(&dm_target_mutex);
239  239
240 return target_array; 240 return target_array;
241} 241}
242 242
243/* Initialize dm_target subsystem. */ 243/* Initialize dm_target subsystem. */
244int 244int
245dm_target_init(void) 245dm_target_init(void)
246{ 246{
247 dm_target_t *dmt,*dmt3,*dmt4; 247 dm_target_t *dmt,*dmt3;
248 int r; 248 int r;
249 249
250 r = 0; 250 r = 0;
251 251
252 mutex_init(&dm_target_mutex, MUTEX_DEFAULT, IPL_NONE); 252 mutex_init(&dm_target_mutex, MUTEX_DEFAULT, IPL_NONE);
253  253
254 dmt = dm_target_alloc("linear"); 254 dmt = dm_target_alloc("linear");
255 dmt3 = dm_target_alloc("striped"); 255 dmt3 = dm_target_alloc("striped");
256 dmt4 = dm_target_alloc("mirror"); 
257  256
258 dmt->version[0] = 1; 257 dmt->version[0] = 1;
259 dmt->version[1] = 0; 258 dmt->version[1] = 0;
260 dmt->version[2] = 2; 259 dmt->version[2] = 2;
261 strlcpy(dmt->name, "linear", DM_MAX_TYPE_NAME); 260 strlcpy(dmt->name, "linear", DM_MAX_TYPE_NAME);
262 dmt->init = &dm_target_linear_init; 261 dmt->init = &dm_target_linear_init;
263 dmt->status = &dm_target_linear_status; 262 dmt->status = &dm_target_linear_status;
264 dmt->strategy = &dm_target_linear_strategy; 263 dmt->strategy = &dm_target_linear_strategy;
265 dmt->deps = &dm_target_linear_deps; 264 dmt->deps = &dm_target_linear_deps;
266 dmt->destroy = &dm_target_linear_destroy; 265 dmt->destroy = &dm_target_linear_destroy;
267 dmt->upcall = &dm_target_linear_upcall; 266 dmt->upcall = &dm_target_linear_upcall;
268  267
269 r = dm_target_insert(dmt); 268 r = dm_target_insert(dmt);
270  269
271 dmt3->version[0] = 1; 270 dmt3->version[0] = 1;
272 dmt3->version[1] = 0; 271 dmt3->version[1] = 0;
273 dmt3->version[2] = 3; 272 dmt3->version[2] = 3;
274 strlcpy(dmt3->name, "striped", DM_MAX_TYPE_NAME); 273 strlcpy(dmt3->name, "striped", DM_MAX_TYPE_NAME);
275 dmt3->init = &dm_target_stripe_init; 274 dmt3->init = &dm_target_stripe_init;
276 dmt3->status = &dm_target_stripe_status; 275 dmt3->status = &dm_target_stripe_status;
277 dmt3->strategy = &dm_target_stripe_strategy; 276 dmt3->strategy = &dm_target_stripe_strategy;
278 dmt3->deps = &dm_target_stripe_deps; 277 dmt3->deps = &dm_target_stripe_deps;
279 dmt3->destroy = &dm_target_stripe_destroy; 278 dmt3->destroy = &dm_target_stripe_destroy;
280 dmt3->upcall = &dm_target_stripe_upcall; 279 dmt3->upcall = &dm_target_stripe_upcall;
281  280
282 r = dm_target_insert(dmt3); 281 r = dm_target_insert(dmt3);
283 282
284 dmt4->version[0] = 1; 283#ifdef notyet
285 dmt4->version[1] = 0; 284 dmt5->version[0] = 1;
286 dmt4->version[2] = 3; 
287 strlcpy(dmt4->name, "mirror", DM_MAX_TYPE_NAME); 
288 dmt4->init = NULL; 
289 dmt4->status = NULL; 
290 dmt4->strategy = NULL; 
291 dmt4->deps = NULL; 
292 dmt4->destroy = NULL; 
293 dmt4->upcall = NULL; 
294  
295 r = dm_target_insert(dmt4); 
296 
297/* dmt5->version[0] = 1; 
298 dmt5->version[1] = 0; 285 dmt5->version[1] = 0;
299 dmt5->version[2] = 5; 286 dmt5->version[2] = 5;
300 strlcpy(dmt5->name, "snapshot", DM_MAX_TYPE_NAME); 287 strlcpy(dmt5->name, "snapshot", DM_MAX_TYPE_NAME);
301 dmt5->init = &dm_target_snapshot_init; 288 dmt5->init = &dm_target_snapshot_init;
302 dmt5->status = &dm_target_snapshot_status; 289 dmt5->status = &dm_target_snapshot_status;
303 dmt5->strategy = &dm_target_snapshot_strategy; 290 dmt5->strategy = &dm_target_snapshot_strategy;
304 dmt5->deps = &dm_target_snapshot_deps; 291 dmt5->deps = &dm_target_snapshot_deps;
305 dmt5->destroy = &dm_target_snapshot_destroy; 292 dmt5->destroy = &dm_target_snapshot_destroy;
306 dmt5->upcall = &dm_target_snapshot_upcall; 293 dmt5->upcall = &dm_target_snapshot_upcall;
307  294
308 r = dm_target_insert(dmt5); 295 r = dm_target_insert(dmt5);
309  296
310 dmt6->version[0] = 1; 297 dmt6->version[0] = 1;
311 dmt6->version[1] = 0; 298 dmt6->version[1] = 0;
312 dmt6->version[2] = 5; 299 dmt6->version[2] = 5;
313 strlcpy(dmt6->name, "snapshot-origin", DM_MAX_TYPE_NAME); 300 strlcpy(dmt6->name, "snapshot-origin", DM_MAX_TYPE_NAME);
314 dmt6->init = &dm_target_snapshot_orig_init; 301 dmt6->init = &dm_target_snapshot_orig_init;
315 dmt6->status = &dm_target_snapshot_orig_status; 302 dmt6->status = &dm_target_snapshot_orig_status;
316 dmt6->strategy = &dm_target_snapshot_orig_strategy; 303 dmt6->strategy = &dm_target_snapshot_orig_strategy;
317 dmt6->deps = &dm_target_snapshot_orig_deps; 304 dmt6->deps = &dm_target_snapshot_orig_deps;
318 dmt6->destroy = &dm_target_snapshot_orig_destroy; 305 dmt6->destroy = &dm_target_snapshot_orig_destroy;
319 dmt6->upcall = &dm_target_snapshot_orig_upcall; 306 dmt6->upcall = &dm_target_snapshot_orig_upcall;
320 307
321 r = dm_target_insert(dmt6);*/ 308 r = dm_target_insert(dmt6);
 309#endif
322  310
323 return r; 311 return r;
324} 312}

File Added: src/sys/dev/dm/dm_target_mirror.c
/*$NetBSD: dm_target_mirror.c,v 1.1 2009/01/02 11:03:24 haad Exp $*/

/*
 * Copyright (c) 2009 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Adam Hamsik.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * This file implements initial version of device-mapper mirror target.
 */
#include <sys/types.h>
#include <sys/param.h>

#include <sys/buf.h>

#include "dm.h"

#ifdef DM_TARGET_MODULE
/*
 * Every target can be compiled directly to dm driver or as a
 * separate module this part of target is used for loading targets
 * to dm driver.
 * Target can be unloaded from kernel only if there are no users of
 * it e.g. there are no devices which uses that target.
 */
#include <sys/kernel.h>
#include <sys/module.h>

MODULE(MODULE_CLASS_MISC, dm_target_mirror, NULL);

static int
dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
{
	dm_target_t *dmt;
	int r;
	dmt = NULL;
	
	switch (cmd) {
	case MODULE_CMD_INIT:
		if ((r = module_hold("dm")) != 0)
			return r;
		
		if ((dmt = dm_target_lookup("mirror")) != NULL)
			return EEXIST;

		dmt = dm_target_alloc("mirror");
		
		dmt->version[0] = 1;
		dmt->version[1] = 0;
		dmt->version[2] = 0;
		strlcpy(dmt->name, "mirror", DM_MAX_TYPE_NAME);
		dmt->init = &dm_target_mirror_init;
		dmt->status = &dm_target_mirror_status;
		dmt->strategy = &dm_target_mirror_strategy;
		dmt->deps = &dm_target_mirror_deps;
		dmt->destroy = &dm_target_mirror_destroy;
		dmt->upcall = &dm_target_mirror_upcall;

		r = dm_target_insert(dmt);
		
		break;

	case MODULE_CMD_FINI:
		r = dm_target_rem("mirror");
		module_rele("dm"); /* release usage counter on dm module */
		break;

	case MODULE_CMD_STAT:
		return ENOTTY;

	default:
		return ENOTTY;
	}

	return r;
}

#endif

/* Init function called from dm_table_load_ioctl. */
int
dm_target_mirror_init(dm_dev_t *dmv, void **target_config, char *argv)
{

	printf("Mirror target init function called!!\n");

	*target_config = NULL;

	dmv->dev_type = DM_MIRROR_DEV;
	
	return 0;
}

/* Status routine called to get params string. */
char *
dm_target_mirror_status(void *target_config)
{
	return NULL;
}	

/* Strategy routine called from dm_strategy. */
int
dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
{

	printf("Mirror target read function called!!\n");

	bp->b_error = EIO;
	bp->b_resid = 0;

	biodone(bp);
	
	return 0;
}

/* Doesn't do anything here. */
int
dm_target_mirror_destroy(dm_table_entry_t *table_en)
{
	table_en->target_config = NULL;

	/* Unbusy target so we can unload it */
	dm_target_unbusy(table_en->target);
	
	return 0;
}

/* Doesn't not need to do anything here. */
int
dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
{	
	return 0;
}

/* Unsupported for this target. */
int
dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
{
	return 0;
}

cvs diff -r1.3 -r1.4 src/sys/dev/dm/files.dm (switch to unified diff)

--- src/sys/dev/dm/files.dm 2009/01/02 00:42:31 1.3
+++ src/sys/dev/dm/files.dm 2009/01/02 11:03:24 1.4
@@ -1,12 +1,13 @@ @@ -1,12 +1,13 @@
1defpseudo dm 1defpseudo dm
2file dev/dm/device-mapper.c dm 2file dev/dm/device-mapper.c dm
3file dev/dm/dm_dev.c dm 3file dev/dm/dm_dev.c dm
4file dev/dm/dm_ioctl.c dm 4file dev/dm/dm_ioctl.c dm
5file dev/dm/dm_pdev.c dm 5file dev/dm/dm_pdev.c dm
6file dev/dm/dm_table.c dm 6file dev/dm/dm_table.c dm
7file dev/dm/dm_target.c dm 7file dev/dm/dm_target.c dm
8file dev/dm/dm_target_error.c dm 8file dev/dm/dm_target_error.c dm
9file dev/dm/dm_target_linear.c dm 9file dev/dm/dm_target_linear.c dm
 10file dev/dm/dm_target_mirror.c dm
10file dev/dm/dm_target_zero.c dm 11file dev/dm/dm_target_zero.c dm
11file dev/dm/dm_target_snapshot.c dm 12file dev/dm/dm_target_snapshot.c dm
12file dev/dm/dm_target_stripe.c dm 13file dev/dm/dm_target_stripe.c dm

cvs diff -r1.3 -r1.4 src/sys/modules/dm/Makefile (switch to unified diff)

--- src/sys/modules/dm/Makefile 2009/01/02 01:06:16 1.3
+++ src/sys/modules/dm/Makefile 2009/01/02 11:03:24 1.4
@@ -1,21 +1,22 @@ @@ -1,21 +1,22 @@
1$NetBSD: Makefile,v 1.3 2009/01/02 01:06:16 haad Exp $ 1$NetBSD: Makefile,v 1.4 2009/01/02 11:03:24 haad Exp $
2 2
3.include "../Makefile.inc" 3.include "../Makefile.inc"
4 4
5.PATH: ${S}/dev/dm 5.PATH: ${S}/dev/dm
6 6
7KMOD= dm 7KMOD= dm
8SRCS= device-mapper.c dm_dev.c dm_ioctl.c dm_pdev.c dm_table.c dm_target.c \ 8SRCS= device-mapper.c dm_dev.c dm_ioctl.c dm_pdev.c dm_table.c dm_target.c \
9 dm_target_linear.c dm_target_stripe.c 9 dm_target_linear.c dm_target_stripe.c
10 10
11# Do not build unneeded modules now. 11# Do not build unneeded modules now.
12MK_DM_TARGETS= no 12MK_DM_TARGETS= no
13 13
14.if (${MK_DM_TARGETS} != "no") 14.if (${MK_DM_TARGETS} != "no")
15SUBDIR+= dm_target_error 15SUBDIR+= dm_target_error
16SUBDIR+= dm_target_zero 16SUBDIR+= dm_target_mirror
17SUBDIR+= dm_target_snapshot 17SUBDIR+= dm_target_snapshot
 18SUBDIR+= dm_target_zero
18.endif 19.endif
19 20
20.include <bsd.kmodule.mk> 21.include <bsd.kmodule.mk>
21.include <bsd.subdir.mk> 22.include <bsd.subdir.mk>

File Added: src/sys/modules/dm/dm_target_mirror/Makefile
#$NetBSD: Makefile,v 1.1 2009/01/02 11:03:24 haad Exp $

.include "../../Makefile.inc"

S!=     cd ${.CURDIR}/../../..;pwd
.PATH:	${S}/dev/dm

CFLAGS += -DDM_TARGET_MODULE
KMOD=	dm_target_mirror
SRCS=   dm_target_mirror.c

.include <bsd.kmodule.mk>