Sun Dec 8 14:59:42 2019 UTC ()
dm: Add dummy target ->sync()/->secsize() to prevent panic on modload(8)

dm_target_insert() has assertions to ensure targets implement all handlers.
Adding dummy ones at least prevents panic on modload(8).


(tkusumi)
diff -r1.37 -r1.38 src/sys/dev/dm/dm.h
diff -r1.17 -r1.18 src/sys/dev/dm/dm_target_error.c
diff -r1.16 -r1.17 src/sys/dev/dm/dm_target_mirror.c
diff -r1.28 -r1.29 src/sys/dev/dm/dm_target_snapshot.c
diff -r1.19 -r1.20 src/sys/dev/dm/dm_target_zero.c

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

--- src/sys/dev/dm/dm.h 2019/12/08 10:50:21 1.37
+++ src/sys/dev/dm/dm.h 2019/12/08 14:59:42 1.38
@@ -1,298 +1,305 @@ @@ -1,298 +1,305 @@
1/* $NetBSD: dm.h,v 1.37 2019/12/08 10:50:21 tkusumi Exp $ */ 1/* $NetBSD: dm.h,v 1.38 2019/12/08 14:59:42 tkusumi 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/fcntl.h> 41#include <sys/fcntl.h>
42#include <sys/condvar.h> 42#include <sys/condvar.h>
43#include <sys/kauth.h> 43#include <sys/kauth.h>
44#include <sys/mutex.h> 44#include <sys/mutex.h>
45#include <sys/rwlock.h> 45#include <sys/rwlock.h>
46#include <sys/queue.h> 46#include <sys/queue.h>
47#include <sys/vnode.h> 47#include <sys/vnode.h>
48 48
49#include <sys/device.h> 49#include <sys/device.h>
50#include <sys/disk.h> 50#include <sys/disk.h>
51#include <sys/disklabel.h> 51#include <sys/disklabel.h>
52 52
53#include <miscfs/specfs/specdev.h> /* for v_rdev */ 53#include <miscfs/specfs/specdev.h> /* for v_rdev */
54 54
55#include <prop/proplib.h> 55#include <prop/proplib.h>
56 56
57#define DM_MAX_TYPE_NAME 16 57#define DM_MAX_TYPE_NAME 16
58#define DM_NAME_LEN 128 58#define DM_NAME_LEN 128
59#define DM_UUID_LEN 129 59#define DM_UUID_LEN 129
60 60
61#define DM_VERSION_MAJOR 4 61#define DM_VERSION_MAJOR 4
62#define DM_VERSION_MINOR 16 62#define DM_VERSION_MINOR 16
63 63
64#define DM_VERSION_PATCHLEVEL 0 64#define DM_VERSION_PATCHLEVEL 0
65 65
66/*** Internal device-mapper structures ***/ 66/*** Internal device-mapper structures ***/
67 67
68/* 68/*
69 * A device mapper table is a list of physical ranges plus the mapping target 69 * A device mapper table is a list of physical ranges plus the mapping target
70 * applied to them. 70 * applied to them.
71 */ 71 */
72 72
73typedef struct dm_table_entry { 73typedef struct dm_table_entry {
74 struct dm_dev *dm_dev; /* backlink */ 74 struct dm_dev *dm_dev; /* backlink */
75 uint64_t start; 75 uint64_t start;
76 uint64_t length; 76 uint64_t length;
77 77
78 struct dm_target *target; /* Link to table target. */ 78 struct dm_target *target; /* Link to table target. */
79 void *target_config; /* Target specific data. */ 79 void *target_config; /* Target specific data. */
80 SLIST_ENTRY(dm_table_entry) next; 80 SLIST_ENTRY(dm_table_entry) next;
81} dm_table_entry_t; 81} dm_table_entry_t;
82 82
83SLIST_HEAD(dm_table, dm_table_entry); 83SLIST_HEAD(dm_table, dm_table_entry);
84 84
85typedef struct dm_table dm_table_t; 85typedef struct dm_table dm_table_t;
86 86
87typedef struct dm_table_head { 87typedef struct dm_table_head {
88 /* Current active table is selected with this. */ 88 /* Current active table is selected with this. */
89 int cur_active_table; 89 int cur_active_table;
90 struct dm_table tables[2]; 90 struct dm_table tables[2];
91 91
92 kmutex_t table_mtx; 92 kmutex_t table_mtx;
93 kcondvar_t table_cv; /*IO waiting cv */ 93 kcondvar_t table_cv; /*IO waiting cv */
94 94
95 uint32_t io_cnt; 95 uint32_t io_cnt;
96} dm_table_head_t; 96} dm_table_head_t;
97 97
98#define MAX_DEV_NAME 32 98#define MAX_DEV_NAME 32
99 99
100/* 100/*
101 * This structure is used to store opened vnodes for disk with name. 101 * This structure is used to store opened vnodes for disk with name.
102 * I need this because devices can be opened only once, but I can 102 * I need this because devices can be opened only once, but I can
103 * have more than one device on one partition. 103 * have more than one device on one partition.
104 */ 104 */
105 105
106typedef struct dm_pdev { 106typedef struct dm_pdev {
107 char name[MAX_DEV_NAME]; 107 char name[MAX_DEV_NAME];
108 108
109 struct vnode *pdev_vnode; 109 struct vnode *pdev_vnode;
110 uint64_t pdev_numsec; 110 uint64_t pdev_numsec;
111 unsigned pdev_secsize; 111 unsigned pdev_secsize;
112 int ref_cnt; /* reference counter for users ofthis pdev */ 112 int ref_cnt; /* reference counter for users ofthis pdev */
113 113
114 SLIST_ENTRY(dm_pdev) next_pdev; 114 SLIST_ENTRY(dm_pdev) next_pdev;
115} dm_pdev_t; 115} dm_pdev_t;
116 116
117/* 117/*
118 * This structure is called for every device-mapper device. 118 * This structure is called for every device-mapper device.
119 * It points to SLIST of device tables and mirrored, snapshoted etc. devices. 119 * It points to SLIST of device tables and mirrored, snapshoted etc. devices.
120 */ 120 */
121TAILQ_HEAD(dm_dev_head, dm_dev); 121TAILQ_HEAD(dm_dev_head, dm_dev);
122//extern struct dm_dev_head dm_devs; 122//extern struct dm_dev_head dm_devs;
123 123
124typedef struct dm_dev { 124typedef struct dm_dev {
125 char name[DM_NAME_LEN]; 125 char name[DM_NAME_LEN];
126 char uuid[DM_UUID_LEN]; 126 char uuid[DM_UUID_LEN];
127 127
128 device_t devt; /* pointer to autoconf device_t structure */ 128 device_t devt; /* pointer to autoconf device_t structure */
129 uint64_t minor; /* Device minor number */ 129 uint64_t minor; /* Device minor number */
130 uint32_t flags; /* store communication protocol flags */ 130 uint32_t flags; /* store communication protocol flags */
131 131
132 kmutex_t dev_mtx; /* mutex for generall device lock */ 132 kmutex_t dev_mtx; /* mutex for generall device lock */
133 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */ 133 kcondvar_t dev_cv; /* cv for between ioctl synchronisation */
134 134
135 uint32_t event_nr; 135 uint32_t event_nr;
136 uint32_t ref_cnt; 136 uint32_t ref_cnt;
137 137
138 dm_table_head_t table_head; 138 dm_table_head_t table_head;
139 139
140 //struct dm_dev_head upcalls; 140 //struct dm_dev_head upcalls;
141 141
142 struct disk *diskp; 142 struct disk *diskp;
143 kmutex_t diskp_mtx; 143 kmutex_t diskp_mtx;
144 144
145 //TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */ 145 //TAILQ_ENTRY(dm_dev) next_upcall; /* LIST of mirrored, snapshoted devices. */
146 146
147 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */ 147 TAILQ_ENTRY(dm_dev) next_devlist; /* Major device list. */
148} dm_dev_t; 148} dm_dev_t;
149 149
150/* for zero, error : dm_target->target_config == NULL */ 150/* for zero, error : dm_target->target_config == NULL */
151 151
152/* 152/*
153 * Target config is initiated with target_init function. 153 * Target config is initiated with target_init function.
154 */ 154 */
155 155
156/* for linear : */ 156/* for linear : */
157typedef struct target_linear_config { 157typedef struct target_linear_config {
158 dm_pdev_t *pdev; 158 dm_pdev_t *pdev;
159 uint64_t offset; 159 uint64_t offset;
160 TAILQ_ENTRY(target_linear_config) entries; 160 TAILQ_ENTRY(target_linear_config) entries;
161} dm_target_linear_config_t; 161} dm_target_linear_config_t;
162 162
163/* 163/*
164 * Striping devices are stored in a linked list, this might be inefficient 164 * Striping devices are stored in a linked list, this might be inefficient
165 * for more than 8 striping devices and can be changed to something more 165 * for more than 8 striping devices and can be changed to something more
166 * scalable. 166 * scalable.
167 * TODO: look for other options than linked list. 167 * TODO: look for other options than linked list.
168 */ 168 */
169TAILQ_HEAD(target_linear_devs, target_linear_config); 169TAILQ_HEAD(target_linear_devs, target_linear_config);
170 170
171typedef struct target_linear_devs dm_target_linear_devs_t; 171typedef struct target_linear_devs dm_target_linear_devs_t;
172 172
173/* constant dm_target structures for error, zero, linear, stripes etc. */ 173/* constant dm_target structures for error, zero, linear, stripes etc. */
174typedef struct dm_target { 174typedef struct dm_target {
175 char name[DM_MAX_TYPE_NAME]; 175 char name[DM_MAX_TYPE_NAME];
176 /* Initialize target_config area */ 176 /* Initialize target_config area */
177 int (*init)(dm_table_entry_t *, char *); 177 int (*init)(dm_table_entry_t *, char *);
178 178
179 /* Destroy target_config area */ 179 /* Destroy target_config area */
180 int (*destroy)(dm_table_entry_t *); 180 int (*destroy)(dm_table_entry_t *);
181 181
182 int (*deps) (dm_table_entry_t *, prop_array_t); 182 int (*deps) (dm_table_entry_t *, prop_array_t);
183 /* 183 /*
184 * Status routine is called to get params string, which is target 184 * Status routine is called to get params string, which is target
185 * specific. When dm_table_status_ioctl is called with flag 185 * specific. When dm_table_status_ioctl is called with flag
186 * DM_STATUS_TABLE_FLAG I have to sent params string back. 186 * DM_STATUS_TABLE_FLAG I have to sent params string back.
187 */ 187 */
188 char * (*status)(void *); 188 char * (*status)(void *);
189 int (*strategy)(dm_table_entry_t *, struct buf *); 189 int (*strategy)(dm_table_entry_t *, struct buf *);
190 int (*sync)(dm_table_entry_t *); 190 int (*sync)(dm_table_entry_t *);
191 int (*upcall)(dm_table_entry_t *, struct buf *); 191 int (*upcall)(dm_table_entry_t *, struct buf *);
192 int (*secsize)(dm_table_entry_t *, unsigned *); 192 int (*secsize)(dm_table_entry_t *, unsigned *);
193 193
194 uint32_t version[3]; 194 uint32_t version[3];
195 uint32_t ref_cnt; 195 uint32_t ref_cnt;
196 196
197 TAILQ_ENTRY(dm_target) dm_target_next; 197 TAILQ_ENTRY(dm_target) dm_target_next;
198} dm_target_t; 198} dm_target_t;
199 199
200/* Interface structures */ 200/* Interface structures */
201 201
202/* device-mapper */ 202/* device-mapper */
203void dmgetproperties(struct disk *, dm_table_head_t *); 203void dmgetproperties(struct disk *, dm_table_head_t *);
204 204
205/* dm_ioctl.c */ 205/* dm_ioctl.c */
206int dm_dev_create_ioctl(prop_dictionary_t); 206int dm_dev_create_ioctl(prop_dictionary_t);
207int dm_dev_list_ioctl(prop_dictionary_t); 207int dm_dev_list_ioctl(prop_dictionary_t);
208int dm_dev_remove_ioctl(prop_dictionary_t); 208int dm_dev_remove_ioctl(prop_dictionary_t);
209int dm_dev_rename_ioctl(prop_dictionary_t); 209int dm_dev_rename_ioctl(prop_dictionary_t);
210int dm_dev_resume_ioctl(prop_dictionary_t); 210int dm_dev_resume_ioctl(prop_dictionary_t);
211int dm_dev_status_ioctl(prop_dictionary_t); 211int dm_dev_status_ioctl(prop_dictionary_t);
212int dm_dev_suspend_ioctl(prop_dictionary_t); 212int dm_dev_suspend_ioctl(prop_dictionary_t);
213 213
214int dm_check_version(prop_dictionary_t); 214int dm_check_version(prop_dictionary_t);
215int dm_list_versions_ioctl(prop_dictionary_t); 215int dm_list_versions_ioctl(prop_dictionary_t);
216 216
217int dm_table_clear_ioctl(prop_dictionary_t); 217int dm_table_clear_ioctl(prop_dictionary_t);
218int dm_table_deps_ioctl(prop_dictionary_t); 218int dm_table_deps_ioctl(prop_dictionary_t);
219int dm_table_load_ioctl(prop_dictionary_t); 219int dm_table_load_ioctl(prop_dictionary_t);
220int dm_table_status_ioctl(prop_dictionary_t); 220int dm_table_status_ioctl(prop_dictionary_t);
221 221
222/* dm_target.c */ 222/* dm_target.c */
223dm_target_t* dm_target_alloc(const char *); 223dm_target_t* dm_target_alloc(const char *);
224dm_target_t* dm_target_autoload(const char *); 224dm_target_t* dm_target_autoload(const char *);
225int dm_target_destroy(void); 225int dm_target_destroy(void);
226int dm_target_insert(dm_target_t *); 226int dm_target_insert(dm_target_t *);
227prop_array_t dm_target_prop_list(void); 227prop_array_t dm_target_prop_list(void);
228dm_target_t* dm_target_lookup(const char *); 228dm_target_t* dm_target_lookup(const char *);
229int dm_target_rem(const char *); 229int dm_target_rem(const char *);
230void dm_target_unbusy(dm_target_t *); 230void dm_target_unbusy(dm_target_t *);
231void dm_target_busy(dm_target_t *); 231void dm_target_busy(dm_target_t *);
232 232
233/* XXX temporally add */ 233/* XXX temporally add */
234int dm_target_init(void); 234int dm_target_init(void);
235 235
236#define DM_MAX_PARAMS_SIZE 1024 236#define DM_MAX_PARAMS_SIZE 1024
237 237
238/* dm_target_linear.c */ 238/* dm_target_linear.c */
239int dm_target_linear_init(dm_table_entry_t *, char *); 239int dm_target_linear_init(dm_table_entry_t *, char *);
240char *dm_target_linear_status(void *); 240char *dm_target_linear_status(void *);
241int dm_target_linear_strategy(dm_table_entry_t *, struct buf *); 241int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
242int dm_target_linear_sync(dm_table_entry_t *); 242int dm_target_linear_sync(dm_table_entry_t *);
243int dm_target_linear_deps(dm_table_entry_t *, prop_array_t); 243int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
244int dm_target_linear_destroy(dm_table_entry_t *); 244int dm_target_linear_destroy(dm_table_entry_t *);
245int dm_target_linear_upcall(dm_table_entry_t *, struct buf *); 245int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
246int dm_target_linear_secsize(dm_table_entry_t *, unsigned *); 246int dm_target_linear_secsize(dm_table_entry_t *, unsigned *);
247 247
248/* Generic function used to convert char to string */ 248/* Generic function used to convert char to string */
249uint64_t atoi(const char *); 249uint64_t atoi(const char *);
250 250
251/* dm_target_stripe.c */ 251/* dm_target_stripe.c */
252int dm_target_stripe_init(dm_table_entry_t *, char *); 252int dm_target_stripe_init(dm_table_entry_t *, char *);
253char *dm_target_stripe_status(void *); 253char *dm_target_stripe_status(void *);
254int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *); 254int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
255int dm_target_stripe_sync(dm_table_entry_t *); 255int dm_target_stripe_sync(dm_table_entry_t *);
256int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t); 256int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
257int dm_target_stripe_destroy(dm_table_entry_t *); 257int dm_target_stripe_destroy(dm_table_entry_t *);
258int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *); 258int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
259int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *); 259int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *);
260 260
261/* dm_table.c */ 261/* dm_table.c */
262#define DM_TABLE_ACTIVE 0 262#define DM_TABLE_ACTIVE 0
263#define DM_TABLE_INACTIVE 1 263#define DM_TABLE_INACTIVE 1
264 264
265int dm_table_destroy(dm_table_head_t *, uint8_t); 265int dm_table_destroy(dm_table_head_t *, uint8_t);
266uint64_t dm_table_size(dm_table_head_t *); 266uint64_t dm_table_size(dm_table_head_t *);
267uint64_t dm_inactive_table_size(dm_table_head_t *); 267uint64_t dm_inactive_table_size(dm_table_head_t *);
268void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *); 268void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *);
269dm_table_t *dm_table_get_entry(dm_table_head_t *, uint8_t); 269dm_table_t *dm_table_get_entry(dm_table_head_t *, uint8_t);
270int dm_table_get_target_count(dm_table_head_t *, uint8_t); 270int dm_table_get_target_count(dm_table_head_t *, uint8_t);
271void dm_table_release(dm_table_head_t *, uint8_t s); 271void dm_table_release(dm_table_head_t *, uint8_t s);
272void dm_table_switch_tables(dm_table_head_t *); 272void dm_table_switch_tables(dm_table_head_t *);
273void dm_table_head_init(dm_table_head_t *); 273void dm_table_head_init(dm_table_head_t *);
274void dm_table_head_destroy(dm_table_head_t *); 274void dm_table_head_destroy(dm_table_head_t *);
275 275
276/* dm_dev.c */ 276/* dm_dev.c */
277dm_dev_t* dm_dev_alloc(void); 277dm_dev_t* dm_dev_alloc(void);
278void dm_dev_busy(dm_dev_t *); 278void dm_dev_busy(dm_dev_t *);
279int dm_dev_destroy(void); 279int dm_dev_destroy(void);
280dm_dev_t* dm_dev_detach(device_t); 280dm_dev_t* dm_dev_detach(device_t);
281int dm_dev_free(dm_dev_t *); 281int dm_dev_free(dm_dev_t *);
282int dm_dev_init(void); 282int dm_dev_init(void);
283int dm_dev_insert(dm_dev_t *); 283int dm_dev_insert(dm_dev_t *);
284dm_dev_t* dm_dev_lookup(const char *, const char *, int); 284dm_dev_t* dm_dev_lookup(const char *, const char *, int);
285prop_array_t dm_dev_prop_list(void); 285prop_array_t dm_dev_prop_list(void);
286dm_dev_t* dm_dev_rem(const char *, const char *, int); 286dm_dev_t* dm_dev_rem(const char *, const char *, int);
287/*int dm_dev_test_minor(int);*/ 287/*int dm_dev_test_minor(int);*/
288void dm_dev_unbusy(dm_dev_t *); 288void dm_dev_unbusy(dm_dev_t *);
289 289
290/* dm_pdev.c */ 290/* dm_pdev.c */
291int dm_pdev_decr(dm_pdev_t *); 291int dm_pdev_decr(dm_pdev_t *);
292int dm_pdev_destroy(void); 292int dm_pdev_destroy(void);
293int dm_pdev_init(void); 293int dm_pdev_init(void);
294dm_pdev_t* dm_pdev_insert(const char *); 294dm_pdev_t* dm_pdev_insert(const char *);
295 295
 296/* XXX dummy */
 297static __inline int
 298dm_target_dummy_secsize(dm_table_entry_t *table_en, unsigned *secsizep)
 299{
 300 return 0;
 301}
 302
296#endif /*_KERNEL*/ 303#endif /*_KERNEL*/
297 304
298#endif /*_DM_DEV_H_*/ 305#endif /*_DM_DEV_H_*/

cvs diff -r1.17 -r1.18 src/sys/dev/dm/dm_target_error.c (switch to unified diff)

--- src/sys/dev/dm/dm_target_error.c 2019/12/08 04:41:02 1.17
+++ src/sys/dev/dm/dm_target_error.c 2019/12/08 14:59:42 1.18
@@ -1,175 +1,176 @@ @@ -1,175 +1,176 @@
1/* $NetBSD: dm_target_error.c,v 1.17 2019/12/08 04:41:02 tkusumi Exp $ */ 1/* $NetBSD: dm_target_error.c,v 1.18 2019/12/08 14:59:42 tkusumi 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#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: dm_target_error.c,v 1.17 2019/12/08 04:41:02 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_error.c,v 1.18 2019/12/08 14:59:42 tkusumi Exp $");
33 33
34/* 34/*
35 * This file implements initial version of device-mapper error target. 35 * This file implements initial version of device-mapper error target.
36 */ 36 */
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/param.h> 38#include <sys/param.h>
39 39
40#include <sys/buf.h> 40#include <sys/buf.h>
41 41
42#include "dm.h" 42#include "dm.h"
43 43
44/* dm_target_error.c */ 44/* dm_target_error.c */
45int dm_target_error_init(dm_table_entry_t*, char *); 45int dm_target_error_init(dm_table_entry_t*, char *);
46char *dm_target_error_status(void *); 46char *dm_target_error_status(void *);
47int dm_target_error_strategy(dm_table_entry_t *, struct buf *); 47int dm_target_error_strategy(dm_table_entry_t *, struct buf *);
48int dm_target_error_sync(dm_table_entry_t *); 48int dm_target_error_sync(dm_table_entry_t *);
49int dm_target_error_deps(dm_table_entry_t *, prop_array_t); 49int dm_target_error_deps(dm_table_entry_t *, prop_array_t);
50int dm_target_error_destroy(dm_table_entry_t *); 50int dm_target_error_destroy(dm_table_entry_t *);
51int dm_target_error_upcall(dm_table_entry_t *, struct buf *); 51int dm_target_error_upcall(dm_table_entry_t *, struct buf *);
52 52
53#ifdef DM_TARGET_MODULE 53#ifdef DM_TARGET_MODULE
54/* 54/*
55 * Every target can be compiled directly to dm driver or as a 55 * Every target can be compiled directly to dm driver or as a
56 * separate module this part of target is used for loading targets 56 * separate module this part of target is used for loading targets
57 * to dm driver. 57 * to dm driver.
58 * Target can be unloaded from kernel only if there are no users of 58 * Target can be unloaded from kernel only if there are no users of
59 * it e.g. there are no devices which uses that target. 59 * it e.g. there are no devices which uses that target.
60 */ 60 */
61#include <sys/kernel.h> 61#include <sys/kernel.h>
62#include <sys/module.h> 62#include <sys/module.h>
63 63
64MODULE(MODULE_CLASS_MISC, dm_target_error, "dm"); 64MODULE(MODULE_CLASS_MISC, dm_target_error, "dm");
65 65
66static int 66static int
67dm_target_error_modcmd(modcmd_t cmd, void *arg) 67dm_target_error_modcmd(modcmd_t cmd, void *arg)
68{ 68{
69 dm_target_t *dmt; 69 dm_target_t *dmt;
70 int r; 70 int r;
71 dmt = NULL; 71 dmt = NULL;
72 72
73 switch (cmd) { 73 switch (cmd) {
74 case MODULE_CMD_INIT: 74 case MODULE_CMD_INIT:
75 if ((dmt = dm_target_lookup("error")) != NULL) { 75 if ((dmt = dm_target_lookup("error")) != NULL) {
76 dm_target_unbusy(dmt); 76 dm_target_unbusy(dmt);
77 return EEXIST; 77 return EEXIST;
78 } 78 }
79 dmt = dm_target_alloc("error"); 79 dmt = dm_target_alloc("error");
80 80
81 dmt->version[0] = 1; 81 dmt->version[0] = 1;
82 dmt->version[1] = 0; 82 dmt->version[1] = 0;
83 dmt->version[2] = 0; 83 dmt->version[2] = 0;
84 dmt->init = &dm_target_error_init; 84 dmt->init = &dm_target_error_init;
85 dmt->status = &dm_target_error_status; 85 dmt->status = &dm_target_error_status;
86 dmt->strategy = &dm_target_error_strategy; 86 dmt->strategy = &dm_target_error_strategy;
87 dmt->sync = &dm_target_error_sync; 87 dmt->sync = &dm_target_error_sync;
88 dmt->deps = &dm_target_error_deps; 88 dmt->deps = &dm_target_error_deps;
89 dmt->destroy = &dm_target_error_destroy; 89 dmt->destroy = &dm_target_error_destroy;
90 dmt->upcall = &dm_target_error_upcall; 90 dmt->upcall = &dm_target_error_upcall;
 91 dmt->secsize = dm_target_dummy_secsize;
91 92
92 r = dm_target_insert(dmt); 93 r = dm_target_insert(dmt);
93 94
94 break; 95 break;
95 96
96 case MODULE_CMD_FINI: 97 case MODULE_CMD_FINI:
97 r = dm_target_rem("error"); 98 r = dm_target_rem("error");
98 break; 99 break;
99 100
100 case MODULE_CMD_STAT: 101 case MODULE_CMD_STAT:
101 return ENOTTY; 102 return ENOTTY;
102 103
103 default: 104 default:
104 return ENOTTY; 105 return ENOTTY;
105 } 106 }
106 107
107 return r; 108 return r;
108} 109}
109#endif 110#endif
110 111
111/* Init function called from dm_table_load_ioctl. */ 112/* Init function called from dm_table_load_ioctl. */
112int 113int
113dm_target_error_init(dm_table_entry_t *table_en, char *params) 114dm_target_error_init(dm_table_entry_t *table_en, char *params)
114{ 115{
115 116
116 printf("Error target init function called!!\n"); 117 printf("Error target init function called!!\n");
117 118
118 table_en->target_config = NULL; 119 table_en->target_config = NULL;
119 120
120 return 0; 121 return 0;
121} 122}
122 123
123/* Status routine called to get params string. */ 124/* Status routine called to get params string. */
124char * 125char *
125dm_target_error_status(void *target_config) 126dm_target_error_status(void *target_config)
126{ 127{
127 return NULL; 128 return NULL;
128} 129}
129 130
130/* Strategy routine called from dm_strategy. */ 131/* Strategy routine called from dm_strategy. */
131int 132int
132dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp) 133dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
133{ 134{
134 135
135 printf("Error target read function called!!\n"); 136 printf("Error target read function called!!\n");
136 137
137 bp->b_error = EIO; 138 bp->b_error = EIO;
138 bp->b_resid = 0; 139 bp->b_resid = 0;
139 140
140 biodone(bp); 141 biodone(bp);
141 142
142 return 0; 143 return 0;
143} 144}
144 145
145/* Sync underlying disk caches. */ 146/* Sync underlying disk caches. */
146int 147int
147dm_target_error_sync(dm_table_entry_t *table_en) 148dm_target_error_sync(dm_table_entry_t *table_en)
148{ 149{
149 150
150 return 0; 151 return 0;
151} 152}
152 153
153/* Doesn't do anything here. */ 154/* Doesn't do anything here. */
154int 155int
155dm_target_error_destroy(dm_table_entry_t *table_en) 156dm_target_error_destroy(dm_table_entry_t *table_en)
156{ 157{
157 /* Unbusy target so we can unload it */ 158 /* Unbusy target so we can unload it */
158 dm_target_unbusy(table_en->target); 159 dm_target_unbusy(table_en->target);
159 160
160 return 0; 161 return 0;
161} 162}
162 163
163/* Doesn't not need to do anything here. */ 164/* Doesn't not need to do anything here. */
164int 165int
165dm_target_error_deps(dm_table_entry_t *table_en, prop_array_t prop_array) 166dm_target_error_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
166{ 167{
167 return 0; 168 return 0;
168} 169}
169 170
170/* Unsupported for this target. */ 171/* Unsupported for this target. */
171int 172int
172dm_target_error_upcall(dm_table_entry_t *table_en, struct buf *bp) 173dm_target_error_upcall(dm_table_entry_t *table_en, struct buf *bp)
173{ 174{
174 return 0; 175 return 0;
175} 176}

cvs diff -r1.16 -r1.17 src/sys/dev/dm/dm_target_mirror.c (switch to unified diff)

--- src/sys/dev/dm/dm_target_mirror.c 2019/12/08 10:50:21 1.16
+++ src/sys/dev/dm/dm_target_mirror.c 2019/12/08 14:59:42 1.17
@@ -1,191 +1,192 @@ @@ -1,191 +1,192 @@
1/*$NetBSD: dm_target_mirror.c,v 1.16 2019/12/08 10:50:21 tkusumi Exp $*/ 1/*$NetBSD: dm_target_mirror.c,v 1.17 2019/12/08 14:59:42 tkusumi Exp $*/
2 2
3/* 3/*
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 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#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.16 2019/12/08 10:50:21 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.17 2019/12/08 14:59:42 tkusumi Exp $");
33 33
34/* 34/*
35 * This file implements initial version of device-mapper mirror target. 35 * This file implements initial version of device-mapper mirror target.
36 */ 36 */
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/param.h> 38#include <sys/param.h>
39 39
40#include <sys/buf.h> 40#include <sys/buf.h>
41 41
42#include "dm.h" 42#include "dm.h"
43 43
44/* dm_target_mirror.c */ 44/* dm_target_mirror.c */
45int dm_target_mirror_init(dm_table_entry_t *, char *); 45int dm_target_mirror_init(dm_table_entry_t *, char *);
46char *dm_target_mirror_status(void *); 46char *dm_target_mirror_status(void *);
47int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *); 47int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *);
48int dm_target_mirror_sync(dm_table_entry_t *); 48int dm_target_mirror_sync(dm_table_entry_t *);
49int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t); 49int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t);
50int dm_target_mirror_destroy(dm_table_entry_t *); 50int dm_target_mirror_destroy(dm_table_entry_t *);
51int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *); 51int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *);
52 52
53typedef struct target_mirror_config { 53typedef struct target_mirror_config {
54#define MAX_MIRROR_COPIES 4 54#define MAX_MIRROR_COPIES 4
55 dm_pdev_t *orig; 55 dm_pdev_t *orig;
56 dm_pdev_t *copies[MAX_MIRROR_COPIES]; 56 dm_pdev_t *copies[MAX_MIRROR_COPIES];
57 57
58 /* copied blocks bitmaps administration etc*/ 58 /* copied blocks bitmaps administration etc*/
59 dm_pdev_t *log_pdev; /* for administration */ 59 dm_pdev_t *log_pdev; /* for administration */
60 uint64_t log_regionsize; /* blocksize of mirror */ 60 uint64_t log_regionsize; /* blocksize of mirror */
61 61
62 /* list of parts that still need copied etc.; run length encoded? */ 62 /* list of parts that still need copied etc.; run length encoded? */
63} dm_target_mirror_config_t; 63} dm_target_mirror_config_t;
64 64
65#ifdef DM_TARGET_MODULE 65#ifdef DM_TARGET_MODULE
66/* 66/*
67 * Every target can be compiled directly to dm driver or as a 67 * Every target can be compiled directly to dm driver or as a
68 * separate module this part of target is used for loading targets 68 * separate module this part of target is used for loading targets
69 * to dm driver. 69 * to dm driver.
70 * Target can be unloaded from kernel only if there are no users of 70 * Target can be unloaded from kernel only if there are no users of
71 * it e.g. there are no devices which uses that target. 71 * it e.g. there are no devices which uses that target.
72 */ 72 */
73#include <sys/kernel.h> 73#include <sys/kernel.h>
74#include <sys/module.h> 74#include <sys/module.h>
75 75
76MODULE(MODULE_CLASS_MISC, dm_target_mirror, "dm"); 76MODULE(MODULE_CLASS_MISC, dm_target_mirror, "dm");
77 77
78static int 78static int
79dm_target_mirror_modcmd(modcmd_t cmd, void *arg) 79dm_target_mirror_modcmd(modcmd_t cmd, void *arg)
80{ 80{
81 dm_target_t *dmt; 81 dm_target_t *dmt;
82 int r; 82 int r;
83 dmt = NULL; 83 dmt = NULL;
84 84
85 switch (cmd) { 85 switch (cmd) {
86 case MODULE_CMD_INIT: 86 case MODULE_CMD_INIT:
87 if ((dmt = dm_target_lookup("mirror")) != NULL) { 87 if ((dmt = dm_target_lookup("mirror")) != NULL) {
88 dm_target_unbusy(dmt); 88 dm_target_unbusy(dmt);
89 return EEXIST; 89 return EEXIST;
90 } 90 }
91 dmt = dm_target_alloc("mirror"); 91 dmt = dm_target_alloc("mirror");
92 92
93 dmt->version[0] = 1; 93 dmt->version[0] = 1;
94 dmt->version[1] = 0; 94 dmt->version[1] = 0;
95 dmt->version[2] = 0; 95 dmt->version[2] = 0;
96 dmt->init = &dm_target_mirror_init; 96 dmt->init = &dm_target_mirror_init;
97 dmt->status = &dm_target_mirror_status; 97 dmt->status = &dm_target_mirror_status;
98 dmt->strategy = &dm_target_mirror_strategy; 98 dmt->strategy = &dm_target_mirror_strategy;
99 dmt->sync = &dm_target_mirror_sync; 99 dmt->sync = &dm_target_mirror_sync;
100 dmt->deps = &dm_target_mirror_deps; 100 dmt->deps = &dm_target_mirror_deps;
101 dmt->destroy = &dm_target_mirror_destroy; 101 dmt->destroy = &dm_target_mirror_destroy;
102 dmt->upcall = &dm_target_mirror_upcall; 102 dmt->upcall = &dm_target_mirror_upcall;
 103 dmt->secsize = dm_target_dummy_secsize;
103 104
104 r = dm_target_insert(dmt); 105 r = dm_target_insert(dmt);
105 106
106 break; 107 break;
107 108
108 case MODULE_CMD_FINI: 109 case MODULE_CMD_FINI:
109 r = dm_target_rem("mirror"); 110 r = dm_target_rem("mirror");
110 break; 111 break;
111 112
112 case MODULE_CMD_STAT: 113 case MODULE_CMD_STAT:
113 return ENOTTY; 114 return ENOTTY;
114 115
115 default: 116 default:
116 return ENOTTY; 117 return ENOTTY;
117 } 118 }
118 119
119 return r; 120 return r;
120} 121}
121#endif 122#endif
122 123
123/* 124/*
124 * Init function called from dm_table_load_ioctl. 125 * Init function called from dm_table_load_ioctl.
125 * start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ... deviceN offsetN 126 * start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ... deviceN offsetN
126 * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0 127 * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0
127 */ 128 */
128int 129int
129dm_target_mirror_init(dm_table_entry_t *table_en, char *params) 130dm_target_mirror_init(dm_table_entry_t *table_en, char *params)
130{ 131{
131 132
132 printf("Mirror target init function called!!\n"); 133 printf("Mirror target init function called!!\n");
133 134
134 table_en->target_config = NULL; 135 table_en->target_config = NULL;
135 136
136 return ENOSYS; 137 return ENOSYS;
137} 138}
138 139
139/* Status routine called to get params string. */ 140/* Status routine called to get params string. */
140char * 141char *
141dm_target_mirror_status(void *target_config) 142dm_target_mirror_status(void *target_config)
142{ 143{
143 return NULL; 144 return NULL;
144} 145}
145 146
146/* Strategy routine called from dm_strategy. */ 147/* Strategy routine called from dm_strategy. */
147int 148int
148dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp) 149dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
149{ 150{
150 151
151 printf("Mirror target read function called!!\n"); 152 printf("Mirror target read function called!!\n");
152 153
153 bp->b_error = EIO; 154 bp->b_error = EIO;
154 bp->b_resid = 0; 155 bp->b_resid = 0;
155 156
156 biodone(bp); 157 biodone(bp);
157 158
158 return 0; 159 return 0;
159} 160}
160 161
161/* Sync underlying disk caches. */ 162/* Sync underlying disk caches. */
162int 163int
163dm_target_mirror_sync(dm_table_entry_t *table_en) 164dm_target_mirror_sync(dm_table_entry_t *table_en)
164{ 165{
165 166
166 return 0; 167 return 0;
167} 168}
168 169
169/* Doesn't do anything here. */ 170/* Doesn't do anything here. */
170int 171int
171dm_target_mirror_destroy(dm_table_entry_t *table_en) 172dm_target_mirror_destroy(dm_table_entry_t *table_en)
172{ 173{
173 /* Unbusy target so we can unload it */ 174 /* Unbusy target so we can unload it */
174 dm_target_unbusy(table_en->target); 175 dm_target_unbusy(table_en->target);
175 176
176 return 0; 177 return 0;
177} 178}
178 179
179/* Doesn't not need to do anything here. */ 180/* Doesn't not need to do anything here. */
180int 181int
181dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array) 182dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
182{ 183{
183 return 0; 184 return 0;
184} 185}
185 186
186/* Unsupported for this target. */ 187/* Unsupported for this target. */
187int 188int
188dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp) 189dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
189{ 190{
190 return 0; 191 return 0;
191} 192}

cvs diff -r1.28 -r1.29 src/sys/dev/dm/dm_target_snapshot.c (switch to unified diff)

--- src/sys/dev/dm/dm_target_snapshot.c 2019/12/08 10:50:21 1.28
+++ src/sys/dev/dm/dm_target_snapshot.c 2019/12/08 14:59:42 1.29
@@ -1,549 +1,560 @@ @@ -1,549 +1,560 @@
1/* $NetBSD: dm_target_snapshot.c,v 1.28 2019/12/08 10:50:21 tkusumi Exp $ */ 1/* $NetBSD: dm_target_snapshot.c,v 1.29 2019/12/08 14:59:42 tkusumi 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#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.28 2019/12/08 10:50:21 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.29 2019/12/08 14:59:42 tkusumi Exp $");
33 33
34/* 34/*
35 * 1. Suspend my_data to temporarily stop any I/O while the snapshot is being 35 * 1. Suspend my_data to temporarily stop any I/O while the snapshot is being
36 * activated. 36 * activated.
37 * dmsetup suspend my_data 37 * dmsetup suspend my_data
38 * 38 *
39 * 2. Create the snapshot-origin device with no table. 39 * 2. Create the snapshot-origin device with no table.
40 * dmsetup create my_data_org 40 * dmsetup create my_data_org
41 * 41 *
42 * 3. Read the table from my_data and load it into my_data_org. 42 * 3. Read the table from my_data and load it into my_data_org.
43 * dmsetup table my_data | dmsetup load my_data_org 43 * dmsetup table my_data | dmsetup load my_data_org
44 * 44 *
45 * 4. Resume this new table. 45 * 4. Resume this new table.
46 * dmsetup resume my_data_org 46 * dmsetup resume my_data_org
47 * 47 *
48 * 5. Create the snapshot device with no table. 48 * 5. Create the snapshot device with no table.
49 * dmsetup create my_data_snap 49 * dmsetup create my_data_snap
50 * 50 *
51 * 6. Load the table into my_data_snap. This uses /dev/hdd1 as the COW device and 51 * 6. Load the table into my_data_snap. This uses /dev/hdd1 as the COW device and
52 * uses a 32kB chunk-size. 52 * uses a 32kB chunk-size.
53 * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot \ 53 * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot \
54 * /dev/mapper/my_data_org /dev/hdd1 p 64" | dmsetup load my_data_snap 54 * /dev/mapper/my_data_org /dev/hdd1 p 64" | dmsetup load my_data_snap
55 * 55 *
56 * 7. Reload my_data as a snapshot-origin device that points to my_data_org. 56 * 7. Reload my_data as a snapshot-origin device that points to my_data_org.
57 * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot-origin \ 57 * echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot-origin \
58 * /dev/mapper/my_data_org" | dmsetup load my_data 58 * /dev/mapper/my_data_org" | dmsetup load my_data
59 * 59 *
60 * 8. Resume the snapshot and origin devices. 60 * 8. Resume the snapshot and origin devices.
61 * dmsetup resume my_data_snap 61 * dmsetup resume my_data_snap
62 * dmsetup resume my_data 62 * dmsetup resume my_data
63 * 63 *
64 * Before snapshot creation 64 * Before snapshot creation
65 * dev_name; dev table 65 * dev_name; dev table
66 * | my_data; 0 1024 linear /dev/sd1a 384| 66 * | my_data; 0 1024 linear /dev/sd1a 384|
67 * 67 *
68 * After snapshot creation 68 * After snapshot creation
69 * |my_data_org;0 1024 linear /dev/sd1a 384| 69 * |my_data_org;0 1024 linear /dev/sd1a 384|
70 * / 70 * /
71 * |my_data; 0 1024 snapshot-origin /dev/vg00/my_data_org| 71 * |my_data; 0 1024 snapshot-origin /dev/vg00/my_data_org|
72 * / 72 * /
73 * |my_data_snap; 0 1024 snapshot /dev/vg00/my_data /dev/mapper/my_data_cow P 8 73 * |my_data_snap; 0 1024 snapshot /dev/vg00/my_data /dev/mapper/my_data_cow P 8
74 * \ 74 * \
75 * |my_data_cow; 0 256 linear /dev/sd1a 1408| 75 * |my_data_cow; 0 256 linear /dev/sd1a 1408|
76 */ 76 */
77 77
78/* 78/*
79 * This file implements initial version of device-mapper snapshot target. 79 * This file implements initial version of device-mapper snapshot target.
80 */ 80 */
81#include <sys/types.h> 81#include <sys/types.h>
82#include <sys/param.h> 82#include <sys/param.h>
83 83
84#include <sys/buf.h> 84#include <sys/buf.h>
85#include <sys/kmem.h> 85#include <sys/kmem.h>
86 86
87#include "dm.h" 87#include "dm.h"
88 88
89/* dm_target_snapshot.c */ 89/* dm_target_snapshot.c */
90int dm_target_snapshot_init(dm_table_entry_t *, char *); 90int dm_target_snapshot_init(dm_table_entry_t *, char *);
91char *dm_target_snapshot_status(void *); 91char *dm_target_snapshot_status(void *);
92int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *); 92int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
 93int dm_target_snapshot_sync(dm_table_entry_t *);
93int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t); 94int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t);
94int dm_target_snapshot_destroy(dm_table_entry_t *); 95int dm_target_snapshot_destroy(dm_table_entry_t *);
95int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *); 96int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
96 97
97/* dm snapshot origin driver */ 98/* dm snapshot origin driver */
98int dm_target_snapshot_orig_init(dm_table_entry_t *, char *); 99int dm_target_snapshot_orig_init(dm_table_entry_t *, char *);
99char *dm_target_snapshot_orig_status(void *); 100char *dm_target_snapshot_orig_status(void *);
100int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *); 101int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
101int dm_target_snapshot_orig_sync(dm_table_entry_t *); 102int dm_target_snapshot_orig_sync(dm_table_entry_t *);
102int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t); 103int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t);
103int dm_target_snapshot_orig_destroy(dm_table_entry_t *); 104int dm_target_snapshot_orig_destroy(dm_table_entry_t *);
104int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *); 105int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
105 106
106typedef struct target_snapshot_config { 107typedef struct target_snapshot_config {
107 dm_pdev_t *tsc_snap_dev; 108 dm_pdev_t *tsc_snap_dev;
108 /* cow dev is set only for persistent snapshot devices */ 109 /* cow dev is set only for persistent snapshot devices */
109 dm_pdev_t *tsc_cow_dev; 110 dm_pdev_t *tsc_cow_dev;
110 111
111 uint64_t tsc_chunk_size; 112 uint64_t tsc_chunk_size;
112 uint32_t tsc_persistent_dev; 113 uint32_t tsc_persistent_dev;
113} dm_target_snapshot_config_t; 114} dm_target_snapshot_config_t;
114 115
115typedef struct target_snapshot_origin_config { 116typedef struct target_snapshot_origin_config {
116 dm_pdev_t *tsoc_real_dev; 117 dm_pdev_t *tsoc_real_dev;
117 /* list of snapshots ? */ 118 /* list of snapshots ? */
118} dm_target_snapshot_origin_config_t; 119} dm_target_snapshot_origin_config_t;
119 120
120#ifdef DM_TARGET_MODULE 121#ifdef DM_TARGET_MODULE
121/* 122/*
122 * Every target can be compiled directly to dm driver or as a 123 * Every target can be compiled directly to dm driver or as a
123 * separate module this part of target is used for loading targets 124 * separate module this part of target is used for loading targets
124 * to dm driver. 125 * to dm driver.
125 * Target can be unloaded from kernel only if there are no users of 126 * Target can be unloaded from kernel only if there are no users of
126 * it e.g. there are no devices which uses that target. 127 * it e.g. there are no devices which uses that target.
127 */ 128 */
128#include <sys/kernel.h> 129#include <sys/kernel.h>
129#include <sys/module.h> 130#include <sys/module.h>
130 131
131MODULE(MODULE_CLASS_MISC, dm_target_snapshot, "dm"); 132MODULE(MODULE_CLASS_MISC, dm_target_snapshot, "dm");
132 133
133static int 134static int
134dm_target_snapshot_modcmd(modcmd_t cmd, void *arg) 135dm_target_snapshot_modcmd(modcmd_t cmd, void *arg)
135{ 136{
136 dm_target_t *dmt, *dmt1; 137 dm_target_t *dmt, *dmt1;
137 int r; 138 int r;
138 139
139 dmt = NULL; 140 dmt = NULL;
140 dmt1 = NULL; 141 dmt1 = NULL;
141 142
142 switch (cmd) { 143 switch (cmd) {
143 case MODULE_CMD_INIT: 144 case MODULE_CMD_INIT:
144 if (((dmt = dm_target_lookup("snapshot")) != NULL)) { 145 if (((dmt = dm_target_lookup("snapshot")) != NULL)) {
145 dm_target_unbusy(dmt); 146 dm_target_unbusy(dmt);
146 return EEXIST; 147 return EEXIST;
147 } 148 }
148 if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)) { 149 if (((dmt = dm_target_lookup("snapshot-origin")) != NULL)) {
149 dm_target_unbusy(dmt); 150 dm_target_unbusy(dmt);
150 return EEXIST; 151 return EEXIST;
151 } 152 }
152 dmt = dm_target_alloc("snapshot"); 153 dmt = dm_target_alloc("snapshot");
153 dmt1 = dm_target_alloc("snapshot-origin"); 154 dmt1 = dm_target_alloc("snapshot-origin");
154 155
155 dmt->version[0] = 1; 156 dmt->version[0] = 1;
156 dmt->version[1] = 0; 157 dmt->version[1] = 0;
157 dmt->version[2] = 5; 158 dmt->version[2] = 5;
158 dmt->init = &dm_target_snapshot_init; 159 dmt->init = &dm_target_snapshot_init;
159 dmt->status = &dm_target_snapshot_status; 160 dmt->status = &dm_target_snapshot_status;
160 dmt->strategy = &dm_target_snapshot_strategy; 161 dmt->strategy = &dm_target_snapshot_strategy;
 162 dmt->sync = &dm_target_snapshot_sync;
161 dmt->deps = &dm_target_snapshot_deps; 163 dmt->deps = &dm_target_snapshot_deps;
162 dmt->destroy = &dm_target_snapshot_destroy; 164 dmt->destroy = &dm_target_snapshot_destroy;
163 dmt->upcall = &dm_target_snapshot_upcall; 165 dmt->upcall = &dm_target_snapshot_upcall;
 166 dmt->secsize = dm_target_dummy_secsize;
164 167
165 r = dm_target_insert(dmt); 168 r = dm_target_insert(dmt);
166 169
167 dmt1->version[0] = 1; 170 dmt1->version[0] = 1;
168 dmt1->version[1] = 0; 171 dmt1->version[1] = 0;
169 dmt1->version[2] = 5; 172 dmt1->version[2] = 5;
170 dmt1->init = &dm_target_snapshot_orig_init; 173 dmt1->init = &dm_target_snapshot_orig_init;
171 dmt1->status = &dm_target_snapshot_orig_status; 174 dmt1->status = &dm_target_snapshot_orig_status;
172 dmt1->strategy = &dm_target_snapshot_orig_strategy; 175 dmt1->strategy = &dm_target_snapshot_orig_strategy;
173 dmt1->sync = &dm_target_snapshot_orig_sync; 176 dmt1->sync = &dm_target_snapshot_orig_sync;
174 dmt1->deps = &dm_target_snapshot_orig_deps; 177 dmt1->deps = &dm_target_snapshot_orig_deps;
175 dmt1->destroy = &dm_target_snapshot_orig_destroy; 178 dmt1->destroy = &dm_target_snapshot_orig_destroy;
176 dmt1->upcall = &dm_target_snapshot_orig_upcall; 179 dmt1->upcall = &dm_target_snapshot_orig_upcall;
 180 dmt1->secsize = dm_target_dummy_secsize;
177 181
178 r = dm_target_insert(dmt1); 182 r = dm_target_insert(dmt1);
179 break; 183 break;
180 184
181 case MODULE_CMD_FINI: 185 case MODULE_CMD_FINI:
182 /* 186 /*
183 * Try to remove snapshot target if it works remove snap-origin 187 * Try to remove snapshot target if it works remove snap-origin
184 * it is not possible to remove snapshot and do not remove 188 * it is not possible to remove snapshot and do not remove
185 * snap-origin because they are used together. 189 * snap-origin because they are used together.
186 */ 190 */
187 if ((r = dm_target_rem("snapshot")) == 0) 191 if ((r = dm_target_rem("snapshot")) == 0)
188 r = dm_target_rem("snapshot-origin"); 192 r = dm_target_rem("snapshot-origin");
189 193
190 break; 194 break;
191 195
192 case MODULE_CMD_STAT: 196 case MODULE_CMD_STAT:
193 return ENOTTY; 197 return ENOTTY;
194 198
195 default: 199 default:
196 return ENOTTY; 200 return ENOTTY;
197 } 201 }
198 202
199 return r; 203 return r;
200} 204}
201#endif 205#endif
202 206
203/* 207/*
204 * Init function called from dm_table_load_ioctl. 208 * Init function called from dm_table_load_ioctl.
205 * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64 209 * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64
206 * snapshot_origin device, cow device, persistent flag, chunk size 210 * snapshot_origin device, cow device, persistent flag, chunk size
207 */ 211 */
208int 212int
209dm_target_snapshot_init(dm_table_entry_t *table_en, char *params) 213dm_target_snapshot_init(dm_table_entry_t *table_en, char *params)
210{ 214{
211 dm_target_snapshot_config_t *tsc; 215 dm_target_snapshot_config_t *tsc;
212 dm_pdev_t *dmp_snap, *dmp_cow; 216 dm_pdev_t *dmp_snap, *dmp_cow;
213 char **ap, *argv[5]; 217 char **ap, *argv[5];
214 218
215 dmp_cow = NULL; 219 dmp_cow = NULL;
216 220
217 if (params == NULL) 221 if (params == NULL)
218 return EINVAL; 222 return EINVAL;
219 /* 223 /*
220 * Parse a string, containing tokens delimited by white space, 224 * Parse a string, containing tokens delimited by white space,
221 * into an argument vector 225 * into an argument vector
222 */ 226 */
223 for (ap = argv; ap < &argv[4] && 227 for (ap = argv; ap < &argv[4] &&
224 (*ap = strsep(&params, " \t")) != NULL;) { 228 (*ap = strsep(&params, " \t")) != NULL;) {
225 if (**ap != '\0') 229 if (**ap != '\0')
226 ap++; 230 ap++;
227 } 231 }
228 232
229 printf("Snapshot target init function called!!\n"); 233 printf("Snapshot target init function called!!\n");
230 printf("Snapshotted device: %s, cow device %s,\n\t persistent flag: %s, " 234 printf("Snapshotted device: %s, cow device %s,\n\t persistent flag: %s, "
231 "chunk size: %s\n", argv[0], argv[1], argv[2], argv[3]); 235 "chunk size: %s\n", argv[0], argv[1], argv[2], argv[3]);
232 236
233 /* Insert snap device to global pdev list */ 237 /* Insert snap device to global pdev list */
234 if ((dmp_snap = dm_pdev_insert(argv[0])) == NULL) 238 if ((dmp_snap = dm_pdev_insert(argv[0])) == NULL)
235 return ENOENT; 239 return ENOENT;
236 240
237 tsc = kmem_alloc(sizeof(*tsc), KM_SLEEP); 241 tsc = kmem_alloc(sizeof(*tsc), KM_SLEEP);
238 tsc->tsc_persistent_dev = 0; 242 tsc->tsc_persistent_dev = 0;
239 243
240 /* There is now cow device for nonpersistent snapshot devices */ 244 /* There is now cow device for nonpersistent snapshot devices */
241 if (strcmp(argv[2], "p") == 0) { 245 if (strcmp(argv[2], "p") == 0) {
242 tsc->tsc_persistent_dev = 1; 246 tsc->tsc_persistent_dev = 1;
243 247
244 /* Insert cow device to global pdev list */ 248 /* Insert cow device to global pdev list */
245 if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL) { 249 if ((dmp_cow = dm_pdev_insert(argv[1])) == NULL) {
246 kmem_free(tsc, sizeof(*tsc)); 250 kmem_free(tsc, sizeof(*tsc));
247 return ENOENT; 251 return ENOENT;
248 } 252 }
249 } 253 }
250 tsc->tsc_chunk_size = atoi(argv[3]); 254 tsc->tsc_chunk_size = atoi(argv[3]);
251 255
252 tsc->tsc_snap_dev = dmp_snap; 256 tsc->tsc_snap_dev = dmp_snap;
253 tsc->tsc_cow_dev = dmp_cow; 257 tsc->tsc_cow_dev = dmp_cow;
254 258
255 table_en->target_config = tsc; 259 table_en->target_config = tsc;
256 260
257 return 0; 261 return 0;
258} 262}
259 263
260/* 264/*
261 * Status routine is called to get params string, which is target 265 * Status routine is called to get params string, which is target
262 * specific. When dm_table_status_ioctl is called with flag 266 * specific. When dm_table_status_ioctl is called with flag
263 * DM_STATUS_TABLE_FLAG I have to sent params string back. 267 * DM_STATUS_TABLE_FLAG I have to sent params string back.
264 */ 268 */
265char * 269char *
266dm_target_snapshot_status(void *target_config) 270dm_target_snapshot_status(void *target_config)
267{ 271{
268 dm_target_snapshot_config_t *tsc; 272 dm_target_snapshot_config_t *tsc;
269 273
270 uint32_t i; 274 uint32_t i;
271 uint32_t count; 275 uint32_t count;
272 size_t prm_len, cow_len; 276 size_t prm_len, cow_len;
273 char *params; 277 char *params;
274 278
275 tsc = target_config; 279 tsc = target_config;
276 280
277 prm_len = 0; 281 prm_len = 0;
278 cow_len = 0; 282 cow_len = 0;
279 count = 0; 283 count = 0;
280 284
281 printf("Snapshot target status function called\n"); 285 printf("Snapshot target status function called\n");
282 286
283 /* count number of chars in offset */ 287 /* count number of chars in offset */
284 for (i = tsc->tsc_chunk_size; i != 0; i /= 10) 288 for (i = tsc->tsc_chunk_size; i != 0; i /= 10)
285 count++; 289 count++;
286 290
287 if (tsc->tsc_persistent_dev) 291 if (tsc->tsc_persistent_dev)
288 cow_len = strlen(tsc->tsc_cow_dev->name); 292 cow_len = strlen(tsc->tsc_cow_dev->name);
289 293
290 /* length of names + count of chars + spaces and null char */ 294 /* length of names + count of chars + spaces and null char */
291 prm_len = strlen(tsc->tsc_snap_dev->name) + cow_len + count + 5; 295 prm_len = strlen(tsc->tsc_snap_dev->name) + cow_len + count + 5;
292 296
293 params = kmem_alloc(prm_len, KM_SLEEP); 297 params = kmem_alloc(prm_len, KM_SLEEP);
294 298
295 printf("%s %s %s %" PRIu64 "\n", tsc->tsc_snap_dev->name, 299 printf("%s %s %s %" PRIu64 "\n", tsc->tsc_snap_dev->name,
296 tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n", 300 tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n",
297 tsc->tsc_chunk_size); 301 tsc->tsc_chunk_size);
298 302
299 snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name, 303 snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name,
300 tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "", 304 tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
301 tsc->tsc_persistent_dev ? "p" : "n", 305 tsc->tsc_persistent_dev ? "p" : "n",
302 tsc->tsc_chunk_size); 306 tsc->tsc_chunk_size);
303 307
304 return params; 308 return params;
305} 309}
306 310
307/* Strategy routine called from dm_strategy. */ 311/* Strategy routine called from dm_strategy. */
308int 312int
309dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp) 313dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
310{ 314{
311 315
312 printf("Snapshot target read function called!!\n"); 316 printf("Snapshot target read function called!!\n");
313 317
314 bp->b_error = EIO; 318 bp->b_error = EIO;
315 bp->b_resid = 0; 319 bp->b_resid = 0;
316 320
317 biodone(bp); 321 biodone(bp);
318 322
319 return 0; 323 return 0;
320} 324}
321 325
 326/* XXX dummy */
 327int
 328dm_target_snapshot_sync(dm_table_entry_t *table_en)
 329{
 330 return 0;
 331}
 332
322/* Doesn't do anything here. */ 333/* Doesn't do anything here. */
323int 334int
324dm_target_snapshot_destroy(dm_table_entry_t *table_en) 335dm_target_snapshot_destroy(dm_table_entry_t *table_en)
325{ 336{
326 337
327 /* 338 /*
328 * Destroy function is called for every target even if it 339 * Destroy function is called for every target even if it
329 * doesn't have target_config. 340 * doesn't have target_config.
330 */ 341 */
331 if (table_en->target_config == NULL) 342 if (table_en->target_config == NULL)
332 goto out; 343 goto out;
333 344
334 printf("Snapshot target destroy function called\n"); 345 printf("Snapshot target destroy function called\n");
335 346
336 dm_target_snapshot_config_t *tsc = table_en->target_config; 347 dm_target_snapshot_config_t *tsc = table_en->target_config;
337 348
338 /* Decrement pdev ref counter if 0 remove it */ 349 /* Decrement pdev ref counter if 0 remove it */
339 dm_pdev_decr(tsc->tsc_snap_dev); 350 dm_pdev_decr(tsc->tsc_snap_dev);
340 if (tsc->tsc_persistent_dev) 351 if (tsc->tsc_persistent_dev)
341 dm_pdev_decr(tsc->tsc_cow_dev); 352 dm_pdev_decr(tsc->tsc_cow_dev);
342 353
343 kmem_free(tsc, sizeof(*tsc)); 354 kmem_free(tsc, sizeof(*tsc));
344out: 355out:
345 /* Unbusy target so we can unload it */ 356 /* Unbusy target so we can unload it */
346 dm_target_unbusy(table_en->target); 357 dm_target_unbusy(table_en->target);
347 358
348 return 0; 359 return 0;
349} 360}
350 361
351/* Add this target dependencies to prop_array_t */ 362/* Add this target dependencies to prop_array_t */
352int 363int
353dm_target_snapshot_deps(dm_table_entry_t *table_en, prop_array_t prop_array) 364dm_target_snapshot_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
354{ 365{
355 dm_target_snapshot_config_t *tsc; 366 dm_target_snapshot_config_t *tsc;
356 367
357 if (table_en->target_config == NULL) 368 if (table_en->target_config == NULL)
358 return 0; 369 return 0;
359 370
360 tsc = table_en->target_config; 371 tsc = table_en->target_config;
361 372
362 prop_array_add_uint64(prop_array, 373 prop_array_add_uint64(prop_array,
363 (uint64_t) tsc->tsc_snap_dev->pdev_vnode->v_rdev); 374 (uint64_t) tsc->tsc_snap_dev->pdev_vnode->v_rdev);
364 375
365 if (tsc->tsc_persistent_dev) { 376 if (tsc->tsc_persistent_dev) {
366 prop_array_add_uint64(prop_array, 377 prop_array_add_uint64(prop_array,
367 (uint64_t) tsc->tsc_cow_dev->pdev_vnode->v_rdev); 378 (uint64_t) tsc->tsc_cow_dev->pdev_vnode->v_rdev);
368 379
369 } 380 }
370 return 0; 381 return 0;
371} 382}
372 383
373/* Upcall is used to inform other depended devices about IO. */ 384/* Upcall is used to inform other depended devices about IO. */
374int 385int
375dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp) 386dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
376{ 387{
377 printf("dm_target_snapshot_upcall called\n"); 388 printf("dm_target_snapshot_upcall called\n");
378 389
379 printf("upcall buf flags %s %s\n", 390 printf("upcall buf flags %s %s\n",
380 (bp->b_flags & B_WRITE) ? "B_WRITE" : "", 391 (bp->b_flags & B_WRITE) ? "B_WRITE" : "",
381 (bp->b_flags & B_READ) ? "B_READ" : ""); 392 (bp->b_flags & B_READ) ? "B_READ" : "");
382 393
383 return 0; 394 return 0;
384} 395}
385 396
386/* 397/*
387 * dm target snapshot origin routines. 398 * dm target snapshot origin routines.
388 * 399 *
389 * Keep for compatibility with linux lvm2tools. They use two targets 400 * Keep for compatibility with linux lvm2tools. They use two targets
390 * to implement snapshots. Snapshot target will implement exception 401 * to implement snapshots. Snapshot target will implement exception
391 * store and snapshot origin will implement device which calls every 402 * store and snapshot origin will implement device which calls every
392 * snapshot device when write is done on master device. 403 * snapshot device when write is done on master device.
393 */ 404 */
394 405
395/* 406/*
396 * Init function called from dm_table_load_ioctl. 407 * Init function called from dm_table_load_ioctl.
397 * 408 *
398 * argv: /dev/mapper/my_data_real 409 * argv: /dev/mapper/my_data_real
399 */ 410 */
400int 411int
401dm_target_snapshot_orig_init(dm_table_entry_t *table_en, char *params) 412dm_target_snapshot_orig_init(dm_table_entry_t *table_en, char *params)
402{ 413{
403 dm_target_snapshot_origin_config_t *tsoc; 414 dm_target_snapshot_origin_config_t *tsoc;
404 dm_pdev_t *dmp_real; 415 dm_pdev_t *dmp_real;
405 416
406 if (params == NULL) 417 if (params == NULL)
407 return EINVAL; 418 return EINVAL;
408 419
409 printf("Snapshot origin target init function called!!\n"); 420 printf("Snapshot origin target init function called!!\n");
410 printf("Parent device: %s\n", params); 421 printf("Parent device: %s\n", params);
411 422
412 /* Insert snap device to global pdev list */ 423 /* Insert snap device to global pdev list */
413 if ((dmp_real = dm_pdev_insert(params)) == NULL) 424 if ((dmp_real = dm_pdev_insert(params)) == NULL)
414 return ENOENT; 425 return ENOENT;
415 426
416 tsoc = kmem_alloc(sizeof(dm_target_snapshot_origin_config_t), KM_SLEEP); 427 tsoc = kmem_alloc(sizeof(dm_target_snapshot_origin_config_t), KM_SLEEP);
417 tsoc->tsoc_real_dev = dmp_real; 428 tsoc->tsoc_real_dev = dmp_real;
418 429
419 table_en->target_config = tsoc; 430 table_en->target_config = tsoc;
420 431
421 return 0; 432 return 0;
422} 433}
423 434
424/* 435/*
425 * Status routine is called to get params string, which is target 436 * Status routine is called to get params string, which is target
426 * specific. When dm_table_status_ioctl is called with flag 437 * specific. When dm_table_status_ioctl is called with flag
427 * DM_STATUS_TABLE_FLAG I have to sent params string back. 438 * DM_STATUS_TABLE_FLAG I have to sent params string back.
428 */ 439 */
429char * 440char *
430dm_target_snapshot_orig_status(void *target_config) 441dm_target_snapshot_orig_status(void *target_config)
431{ 442{
432 dm_target_snapshot_origin_config_t *tsoc; 443 dm_target_snapshot_origin_config_t *tsoc;
433 444
434 size_t prm_len; 445 size_t prm_len;
435 char *params; 446 char *params;
436 447
437 tsoc = target_config; 448 tsoc = target_config;
438 449
439 prm_len = 0; 450 prm_len = 0;
440 451
441 printf("Snapshot origin target status function called\n"); 452 printf("Snapshot origin target status function called\n");
442 453
443 /* length of names + count of chars + spaces and null char */ 454 /* length of names + count of chars + spaces and null char */
444 prm_len = strlen(tsoc->tsoc_real_dev->name) + 1; 455 prm_len = strlen(tsoc->tsoc_real_dev->name) + 1;
445 456
446 printf("real_dev name %s\n", tsoc->tsoc_real_dev->name); 457 printf("real_dev name %s\n", tsoc->tsoc_real_dev->name);
447 458
448 params = kmem_alloc(prm_len, KM_SLEEP); 459 params = kmem_alloc(prm_len, KM_SLEEP);
449 460
450 printf("%s\n", tsoc->tsoc_real_dev->name); 461 printf("%s\n", tsoc->tsoc_real_dev->name);
451 462
452 snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name); 463 snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name);
453 464
454 return params; 465 return params;
455} 466}
456 467
457/* Strategy routine called from dm_strategy. */ 468/* Strategy routine called from dm_strategy. */
458int 469int
459dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp) 470dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
460{ 471{
461 472
462 printf("Snapshot_Orig target read function called!!\n"); 473 printf("Snapshot_Orig target read function called!!\n");
463 474
464 bp->b_error = EIO; 475 bp->b_error = EIO;
465 bp->b_resid = 0; 476 bp->b_resid = 0;
466 477
467 biodone(bp); 478 biodone(bp);
468 479
469 return 0; 480 return 0;
470} 481}
471 482
472/* 483/*
473 * Sync underlying disk caches. 484 * Sync underlying disk caches.
474 */ 485 */
475int 486int
476dm_target_snapshot_orig_sync(dm_table_entry_t *table_en) 487dm_target_snapshot_orig_sync(dm_table_entry_t *table_en)
477{ 488{
478 int cmd; 489 int cmd;
479 dm_target_snapshot_origin_config_t *tsoc; 490 dm_target_snapshot_origin_config_t *tsoc;
480 491
481 tsoc = table_en->target_config; 492 tsoc = table_en->target_config;
482 493
483 cmd = 1; 494 cmd = 1;
484 495
485 return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC, 496 return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC,
486 &cmd, FREAD|FWRITE, kauth_cred_get()); 497 &cmd, FREAD|FWRITE, kauth_cred_get());
487} 498}
488 499
489/* Decrement pdev and free allocated space. */ 500/* Decrement pdev and free allocated space. */
490int 501int
491dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en) 502dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en)
492{ 503{
493 504
494 /* 505 /*
495 * Destroy function is called for every target even if it 506 * Destroy function is called for every target even if it
496 * doesn't have target_config. 507 * doesn't have target_config.
497 */ 508 */
498 509
499 if (table_en->target_config == NULL) 510 if (table_en->target_config == NULL)
500 goto out; 511 goto out;
501 512
502 dm_target_snapshot_origin_config_t *tsoc = table_en->target_config; 513 dm_target_snapshot_origin_config_t *tsoc = table_en->target_config;
503 514
504 /* Decrement pdev ref counter if 0 remove it */ 515 /* Decrement pdev ref counter if 0 remove it */
505 dm_pdev_decr(tsoc->tsoc_real_dev); 516 dm_pdev_decr(tsoc->tsoc_real_dev);
506 517
507 kmem_free(tsoc, sizeof(*tsoc)); 518 kmem_free(tsoc, sizeof(*tsoc));
508out: 519out:
509 /* Unbusy target so we can unload it */ 520 /* Unbusy target so we can unload it */
510 dm_target_unbusy(table_en->target); 521 dm_target_unbusy(table_en->target);
511 522
512 return 0; 523 return 0;
513} 524}
514 525
515/* 526/*
516 * Get target deps and add them to prop_array_t. 527 * Get target deps and add them to prop_array_t.
517 */ 528 */
518int 529int
519dm_target_snapshot_orig_deps(dm_table_entry_t *table_en, 530dm_target_snapshot_orig_deps(dm_table_entry_t *table_en,
520 prop_array_t prop_array) 531 prop_array_t prop_array)
521{ 532{
522 dm_target_snapshot_origin_config_t *tsoc; 533 dm_target_snapshot_origin_config_t *tsoc;
523 struct vattr va; 534 struct vattr va;
524 535
525 int error; 536 int error;
526 537
527 if (table_en->target_config == NULL) 538 if (table_en->target_config == NULL)
528 return 0; 539 return 0;
529 540
530 tsoc = table_en->target_config; 541 tsoc = table_en->target_config;
531 542
532 vn_lock(tsoc->tsoc_real_dev->pdev_vnode, LK_SHARED | LK_RETRY); 543 vn_lock(tsoc->tsoc_real_dev->pdev_vnode, LK_SHARED | LK_RETRY);
533 error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va, 544 error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va,
534 curlwp->l_cred); 545 curlwp->l_cred);
535 VOP_UNLOCK(tsoc->tsoc_real_dev->pdev_vnode); 546 VOP_UNLOCK(tsoc->tsoc_real_dev->pdev_vnode);
536 if (error != 0) 547 if (error != 0)
537 return error; 548 return error;
538 549
539 prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); 550 prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
540 551
541 return 0; 552 return 0;
542} 553}
543 554
544/* Unsupported for this target. */ 555/* Unsupported for this target. */
545int 556int
546dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp) 557dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp)
547{ 558{
548 return 0; 559 return 0;
549} 560}

cvs diff -r1.19 -r1.20 src/sys/dev/dm/dm_target_zero.c (switch to unified diff)

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