Sat Dec 7 15:28:39 2019 UTC ()
dm: Fix strange pointer declarations

Should be "type *name" or "type* name", but not "type * name".
taken-from: DragonFlyBSD


(tkusumi)
diff -r1.33 -r1.34 src/sys/dev/dm/dm.h
diff -r1.13 -r1.14 src/sys/dev/dm/dm_dev.c
diff -r1.13 -r1.14 src/sys/dev/dm/dm_target_mirror.c
diff -r1.17 -r1.18 src/sys/dev/dm/dm_pdev.c
diff -r1.17 -r1.18 src/sys/dev/dm/dm_target_zero.c
diff -r1.11 -r1.12 src/sys/dev/dm/dm_table.c
diff -r1.24 -r1.25 src/sys/dev/dm/dm_target.c
diff -r1.24 -r1.25 src/sys/dev/dm/dm_target_snapshot.c
diff -r1.15 -r1.16 src/sys/dev/dm/dm_target_error.c
diff -r1.23 -r1.24 src/sys/dev/dm/dm_target_linear.c
diff -r1.29 -r1.30 src/sys/dev/dm/dm_target_stripe.c
diff -r1.2 -r1.3 src/sys/dev/dm/doc/locking.txt

cvs diff -r1.33 -r1.34 src/sys/dev/dm/dm.h (expand / switch to unified diff)

--- src/sys/dev/dm/dm.h 2019/12/05 15:52:39 1.33
+++ src/sys/dev/dm/dm.h 2019/12/07 15:28:39 1.34
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm.h,v 1.33 2019/12/05 15:52:39 tkusumi Exp $ */ 1/* $NetBSD: dm.h,v 1.34 2019/12/07 15:28:39 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.
@@ -266,56 +266,56 @@ int dm_target_insert(dm_target_t *); @@ -266,56 +266,56 @@ int dm_target_insert(dm_target_t *);
266prop_array_t dm_target_prop_list(void); 266prop_array_t dm_target_prop_list(void);
267dm_target_t* dm_target_lookup(const char *); 267dm_target_t* dm_target_lookup(const char *);
268int dm_target_rem(char *); 268int dm_target_rem(char *);
269void dm_target_unbusy(dm_target_t *); 269void dm_target_unbusy(dm_target_t *);
270void dm_target_busy(dm_target_t *); 270void dm_target_busy(dm_target_t *);
271 271
272/* XXX temporally add */ 272/* XXX temporally add */
273int dm_target_init(void); 273int dm_target_init(void);
274 274
275#define DM_MAX_PARAMS_SIZE 1024 275#define DM_MAX_PARAMS_SIZE 1024
276 276
277/* dm_target_linear.c */ 277/* dm_target_linear.c */
278int dm_target_linear_init(dm_dev_t *, void**, char *); 278int dm_target_linear_init(dm_dev_t *, void**, char *);
279char * dm_target_linear_status(void *); 279char *dm_target_linear_status(void *);
280int dm_target_linear_strategy(dm_table_entry_t *, struct buf *); 280int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
281int dm_target_linear_sync(dm_table_entry_t *); 281int dm_target_linear_sync(dm_table_entry_t *);
282int dm_target_linear_deps(dm_table_entry_t *, prop_array_t); 282int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
283int dm_target_linear_destroy(dm_table_entry_t *); 283int dm_target_linear_destroy(dm_table_entry_t *);
284int dm_target_linear_upcall(dm_table_entry_t *, struct buf *); 284int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
285int dm_target_linear_secsize(dm_table_entry_t *, unsigned *); 285int dm_target_linear_secsize(dm_table_entry_t *, unsigned *);
286 286
287/* Generic function used to convert char to string */ 287/* Generic function used to convert char to string */
288uint64_t atoi(const char *); 288uint64_t atoi(const char *);
289 289
290/* dm_target_stripe.c */ 290/* dm_target_stripe.c */
291int dm_target_stripe_init(dm_dev_t *, void**, char *); 291int dm_target_stripe_init(dm_dev_t *, void**, char *);
292char * dm_target_stripe_status(void *); 292char *dm_target_stripe_status(void *);
293int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *); 293int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
294int dm_target_stripe_sync(dm_table_entry_t *); 294int dm_target_stripe_sync(dm_table_entry_t *);
295int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t); 295int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
296int dm_target_stripe_destroy(dm_table_entry_t *); 296int dm_target_stripe_destroy(dm_table_entry_t *);
297int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *); 297int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
298int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *); 298int dm_target_stripe_secsize(dm_table_entry_t *, unsigned *);
299 299
300/* dm_table.c */ 300/* dm_table.c */
301#define DM_TABLE_ACTIVE 0 301#define DM_TABLE_ACTIVE 0
302#define DM_TABLE_INACTIVE 1 302#define DM_TABLE_INACTIVE 1
303 303
304int dm_table_destroy(dm_table_head_t *, uint8_t); 304int dm_table_destroy(dm_table_head_t *, uint8_t);
305uint64_t dm_table_size(dm_table_head_t *); 305uint64_t dm_table_size(dm_table_head_t *);
306uint64_t dm_inactive_table_size(dm_table_head_t *); 306uint64_t dm_inactive_table_size(dm_table_head_t *);
307void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *); 307void dm_table_disksize(dm_table_head_t *, uint64_t *, unsigned *);
308dm_table_t * dm_table_get_entry(dm_table_head_t *, uint8_t); 308dm_table_t *dm_table_get_entry(dm_table_head_t *, uint8_t);
309int dm_table_get_target_count(dm_table_head_t *, uint8_t); 309int dm_table_get_target_count(dm_table_head_t *, uint8_t);
310void dm_table_release(dm_table_head_t *, uint8_t s); 310void dm_table_release(dm_table_head_t *, uint8_t s);
311void dm_table_switch_tables(dm_table_head_t *); 311void dm_table_switch_tables(dm_table_head_t *);
312void dm_table_head_init(dm_table_head_t *); 312void dm_table_head_init(dm_table_head_t *);
313void dm_table_head_destroy(dm_table_head_t *); 313void dm_table_head_destroy(dm_table_head_t *);
314 314
315/* dm_dev.c */ 315/* dm_dev.c */
316dm_dev_t* dm_dev_alloc(void); 316dm_dev_t* dm_dev_alloc(void);
317void dm_dev_busy(dm_dev_t *); 317void dm_dev_busy(dm_dev_t *);
318int dm_dev_destroy(void); 318int dm_dev_destroy(void);
319dm_dev_t* dm_dev_detach(device_t); 319dm_dev_t* dm_dev_detach(device_t);
320int dm_dev_free(dm_dev_t *); 320int dm_dev_free(dm_dev_t *);
321int dm_dev_init(void); 321int dm_dev_init(void);

cvs diff -r1.13 -r1.14 src/sys/dev/dm/dm_dev.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_dev.c 2019/12/04 15:31:12 1.13
+++ src/sys/dev/dm/dm_dev.c 2019/12/07 15:28:39 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_dev.c,v 1.13 2019/12/04 15:31:12 tkusumi Exp $ */ 1/* $NetBSD: dm_dev.c,v 1.14 2019/12/07 15:28:39 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.
@@ -19,52 +19,52 @@ @@ -19,52 +19,52 @@
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_dev.c,v 1.13 2019/12/04 15:31:12 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_dev.c,v 1.14 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/param.h> 35#include <sys/param.h>
36 36
37#include <sys/disk.h> 37#include <sys/disk.h>
38#include <sys/disklabel.h> 38#include <sys/disklabel.h>
39#include <sys/ioctl.h> 39#include <sys/ioctl.h>
40#include <sys/ioccom.h> 40#include <sys/ioccom.h>
41#include <sys/kmem.h> 41#include <sys/kmem.h>
42 42
43#include "netbsd-dm.h" 43#include "netbsd-dm.h"
44#include "dm.h" 44#include "dm.h"
45 45
46static dm_dev_t *dm_dev_lookup_name(const char *); 46static dm_dev_t *dm_dev_lookup_name(const char *);
47static dm_dev_t *dm_dev_lookup_uuid(const char *); 47static dm_dev_t *dm_dev_lookup_uuid(const char *);
48static dm_dev_t *dm_dev_lookup_minor(int); 48static dm_dev_t *dm_dev_lookup_minor(int);
49 49
50static struct dm_dev_head dm_dev_list = 50static struct dm_dev_head dm_dev_list =
51TAILQ_HEAD_INITIALIZER(dm_dev_list); 51TAILQ_HEAD_INITIALIZER(dm_dev_list);
52 52
53static kmutex_t dm_dev_mutex; 53static kmutex_t dm_dev_mutex;
54 54
55/* dm_dev_mutex must be holdby caller before using disable_dev. */ 55/* dm_dev_mutex must be holdby caller before using disable_dev. */
56__inline static void 56__inline static void
57disable_dev(dm_dev_t * dmv) 57disable_dev(dm_dev_t *dmv)
58{ 58{
59 TAILQ_REMOVE(&dm_dev_list, dmv, next_devlist); 59 TAILQ_REMOVE(&dm_dev_list, dmv, next_devlist);
60 mutex_enter(&dmv->dev_mtx); 60 mutex_enter(&dmv->dev_mtx);
61 mutex_exit(&dm_dev_mutex); 61 mutex_exit(&dm_dev_mutex);
62 while (dmv->ref_cnt != 0) 62 while (dmv->ref_cnt != 0)
63 cv_wait(&dmv->dev_cv, &dmv->dev_mtx); 63 cv_wait(&dmv->dev_cv, &dmv->dev_mtx);
64 mutex_exit(&dmv->dev_mtx); 64 mutex_exit(&dmv->dev_mtx);
65} 65}
66 66
67/* 67/*
68 * Generic function used to lookup dm_dev_t. Calling with dm_dev_name 68 * Generic function used to lookup dm_dev_t. Calling with dm_dev_name
69 * and dm_dev_uuid NULL is allowed. 69 * and dm_dev_uuid NULL is allowed.
70 */ 70 */
@@ -165,27 +165,27 @@ dm_dev_lookup_uuid(const char *dm_dev_uu @@ -165,27 +165,27 @@ dm_dev_lookup_uuid(const char *dm_dev_uu
165 continue; 165 continue;
166 166
167 if (strncmp(dm_dev_uuid, dmv->uuid, strlen(dmv->uuid)) == 0) 167 if (strncmp(dm_dev_uuid, dmv->uuid, strlen(dmv->uuid)) == 0)
168 return dmv; 168 return dmv;
169 } 169 }
170 170
171 return NULL; 171 return NULL;
172} 172}
173 173
174/* 174/*
175 * Insert new device to the global list of devices. 175 * Insert new device to the global list of devices.
176 */ 176 */
177int 177int
178dm_dev_insert(dm_dev_t * dev) 178dm_dev_insert(dm_dev_t *dev)
179{ 179{
180 dm_dev_t *dmv; 180 dm_dev_t *dmv;
181 int r; 181 int r;
182 182
183 dmv = NULL; 183 dmv = NULL;
184 r = 0; 184 r = 0;
185 185
186 KASSERT(dev != NULL); 186 KASSERT(dev != NULL);
187 mutex_enter(&dm_dev_mutex); 187 mutex_enter(&dm_dev_mutex);
188 if (((dmv = dm_dev_lookup_uuid(dev->uuid)) == NULL) && 188 if (((dmv = dm_dev_lookup_uuid(dev->uuid)) == NULL) &&
189 ((dmv = dm_dev_lookup_name(dev->name)) == NULL) && 189 ((dmv = dm_dev_lookup_name(dev->name)) == NULL) &&
190 ((dmv = dm_dev_lookup_minor(dev->minor)) == NULL)) { 190 ((dmv = dm_dev_lookup_minor(dev->minor)) == NULL)) {
191 TAILQ_INSERT_TAIL(&dm_dev_list, dev, next_devlist); 191 TAILQ_INSERT_TAIL(&dm_dev_list, dev, next_devlist);
@@ -321,52 +321,52 @@ dm_dev_t * @@ -321,52 +321,52 @@ dm_dev_t *
321dm_dev_alloc(void) 321dm_dev_alloc(void)
322{ 322{
323 dm_dev_t *dmv; 323 dm_dev_t *dmv;
324 324
325 dmv = kmem_zalloc(sizeof(dm_dev_t), KM_SLEEP); 325 dmv = kmem_zalloc(sizeof(dm_dev_t), KM_SLEEP);
326 dmv->diskp = kmem_zalloc(sizeof(struct disk), KM_SLEEP); 326 dmv->diskp = kmem_zalloc(sizeof(struct disk), KM_SLEEP);
327 return dmv; 327 return dmv;
328} 328}
329 329
330/* 330/*
331 * Freed device entry. 331 * Freed device entry.
332 */ 332 */
333int 333int
334dm_dev_free(dm_dev_t * dmv) 334dm_dev_free(dm_dev_t *dmv)
335{ 335{
336 KASSERT(dmv != NULL); 336 KASSERT(dmv != NULL);
337 337
338 mutex_destroy(&dmv->dev_mtx); 338 mutex_destroy(&dmv->dev_mtx);
339 mutex_destroy(&dmv->diskp_mtx); 339 mutex_destroy(&dmv->diskp_mtx);
340 cv_destroy(&dmv->dev_cv); 340 cv_destroy(&dmv->dev_cv);
341 341
342 if (dmv->diskp != NULL) 342 if (dmv->diskp != NULL)
343 (void)kmem_free(dmv->diskp, sizeof(struct disk)); 343 (void)kmem_free(dmv->diskp, sizeof(struct disk));
344 344
345 (void)kmem_free(dmv, sizeof(dm_dev_t)); 345 (void)kmem_free(dmv, sizeof(dm_dev_t));
346 346
347 return 0; 347 return 0;
348} 348}
349 349
350void 350void
351dm_dev_busy(dm_dev_t * dmv) 351dm_dev_busy(dm_dev_t *dmv)
352{ 352{
353 mutex_enter(&dmv->dev_mtx); 353 mutex_enter(&dmv->dev_mtx);
354 dmv->ref_cnt++; 354 dmv->ref_cnt++;
355 mutex_exit(&dmv->dev_mtx); 355 mutex_exit(&dmv->dev_mtx);
356} 356}
357 357
358void 358void
359dm_dev_unbusy(dm_dev_t * dmv) 359dm_dev_unbusy(dm_dev_t *dmv)
360{ 360{
361 KASSERT(dmv->ref_cnt != 0); 361 KASSERT(dmv->ref_cnt != 0);
362 362
363 mutex_enter(&dmv->dev_mtx); 363 mutex_enter(&dmv->dev_mtx);
364 if (--dmv->ref_cnt == 0) 364 if (--dmv->ref_cnt == 0)
365 cv_broadcast(&dmv->dev_cv); 365 cv_broadcast(&dmv->dev_cv);
366 mutex_exit(&dmv->dev_mtx); 366 mutex_exit(&dmv->dev_mtx);
367} 367}
368 368
369/* 369/*
370 * Return prop_array of dm_targer_list dictionaries. 370 * Return prop_array of dm_targer_list dictionaries.
371 */ 371 */
372prop_array_t 372prop_array_t

cvs diff -r1.13 -r1.14 src/sys/dev/dm/dm_target_mirror.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target_mirror.c 2019/12/06 16:11:59 1.13
+++ src/sys/dev/dm/dm_target_mirror.c 2019/12/07 15:28:39 1.14
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/*$NetBSD: dm_target_mirror.c,v 1.13 2019/12/06 16:11:59 tkusumi Exp $*/ 1/*$NetBSD: dm_target_mirror.c,v 1.14 2019/12/07 15:28:39 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.
@@ -19,41 +19,41 @@ @@ -19,41 +19,41 @@
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.13 2019/12/06 16:11:59 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.14 2019/12/07 15:28:39 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_dev_t *, void**, char *); 45int dm_target_mirror_init(dm_dev_t *, void**, 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
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.
@@ -104,76 +104,76 @@ dm_target_mirror_modcmd(modcmd_t cmd, vo @@ -104,76 +104,76 @@ dm_target_mirror_modcmd(modcmd_t cmd, vo
104 return ENOTTY; 104 return ENOTTY;
105 } 105 }
106 106
107 return r; 107 return r;
108} 108}
109#endif 109#endif
110 110
111/* 111/*
112 * Init function called from dm_table_load_ioctl. 112 * Init function called from dm_table_load_ioctl.
113 * start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ... deviceN offsetN 113 * start length mirror log_type #logargs logarg1 ... logargN #devs device1 offset1 ... deviceN offsetN
114 * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0 114 * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0
115 */ 115 */
116int 116int
117dm_target_mirror_init(dm_dev_t * dmv, void **target_config, char *argv) 117dm_target_mirror_init(dm_dev_t *dmv, void **target_config, char *argv)
118{ 118{
119 119
120 printf("Mirror target init function called!!\n"); 120 printf("Mirror target init function called!!\n");
121 121
122 *target_config = NULL; 122 *target_config = NULL;
123 123
124 return ENOSYS; 124 return ENOSYS;
125} 125}
126 126
127/* Status routine called to get params string. */ 127/* Status routine called to get params string. */
128char * 128char *
129dm_target_mirror_status(void *target_config) 129dm_target_mirror_status(void *target_config)
130{ 130{
131 return NULL; 131 return NULL;
132} 132}
133 133
134/* Strategy routine called from dm_strategy. */ 134/* Strategy routine called from dm_strategy. */
135int 135int
136dm_target_mirror_strategy(dm_table_entry_t * table_en, struct buf * bp) 136dm_target_mirror_strategy(dm_table_entry_t *table_en, struct buf *bp)
137{ 137{
138 138
139 printf("Mirror target read function called!!\n"); 139 printf("Mirror target read function called!!\n");
140 140
141 bp->b_error = EIO; 141 bp->b_error = EIO;
142 bp->b_resid = 0; 142 bp->b_resid = 0;
143 143
144 biodone(bp); 144 biodone(bp);
145 145
146 return 0; 146 return 0;
147} 147}
148 148
149/* Sync underlying disk caches. */ 149/* Sync underlying disk caches. */
150int 150int
151dm_target_mirror_sync(dm_table_entry_t * table_en) 151dm_target_mirror_sync(dm_table_entry_t *table_en)
152{ 152{
153 153
154 return 0; 154 return 0;
155} 155}
156 156
157/* Doesn't do anything here. */ 157/* Doesn't do anything here. */
158int 158int
159dm_target_mirror_destroy(dm_table_entry_t * table_en) 159dm_target_mirror_destroy(dm_table_entry_t *table_en)
160{ 160{
161 /* Unbusy target so we can unload it */ 161 /* Unbusy target so we can unload it */
162 dm_target_unbusy(table_en->target); 162 dm_target_unbusy(table_en->target);
163 163
164 return 0; 164 return 0;
165} 165}
166 166
167/* Doesn't not need to do anything here. */ 167/* Doesn't not need to do anything here. */
168int 168int
169dm_target_mirror_deps(dm_table_entry_t * table_en, prop_array_t prop_array) 169dm_target_mirror_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
170{ 170{
171 return 0; 171 return 0;
172} 172}
173 173
174/* Unsupported for this target. */ 174/* Unsupported for this target. */
175int 175int
176dm_target_mirror_upcall(dm_table_entry_t * table_en, struct buf * bp) 176dm_target_mirror_upcall(dm_table_entry_t *table_en, struct buf *bp)
177{ 177{
178 return 0; 178 return 0;
179} 179}

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

--- src/sys/dev/dm/dm_pdev.c 2019/12/07 06:26:31 1.17
+++ src/sys/dev/dm/dm_pdev.c 2019/12/07 15:28:39 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $ */ 1/* $NetBSD: dm_pdev.c,v 1.18 2019/12/07 15:28:39 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.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
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_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_pdev.c,v 1.18 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/param.h> 35#include <sys/param.h>
36 36
37#include <sys/disk.h> 37#include <sys/disk.h>
38#include <sys/fcntl.h> 38#include <sys/fcntl.h>
39#include <sys/kmem.h> 39#include <sys/kmem.h>
40#include <sys/namei.h> 40#include <sys/namei.h>
41 41
42#include <dev/dkvar.h> 42#include <dev/dkvar.h>
43 43
44#include "dm.h" 44#include "dm.h"
45 45
@@ -157,27 +157,27 @@ dm_pdev_alloc(const char *name) @@ -157,27 +157,27 @@ dm_pdev_alloc(const char *name)
157 157
158 dmp = kmem_zalloc(sizeof(*dmp), KM_SLEEP); 158 dmp = kmem_zalloc(sizeof(*dmp), KM_SLEEP);
159 strlcpy(dmp->name, name, sizeof(dmp->name)); 159 strlcpy(dmp->name, name, sizeof(dmp->name));
160 dmp->ref_cnt = 0; 160 dmp->ref_cnt = 0;
161 dmp->pdev_vnode = NULL; 161 dmp->pdev_vnode = NULL;
162 162
163 return dmp; 163 return dmp;
164} 164}
165 165
166/* 166/*
167 * Destroy allocated dm_pdev. 167 * Destroy allocated dm_pdev.
168 */ 168 */
169static int 169static int
170dm_pdev_rem(dm_pdev_t * dmp) 170dm_pdev_rem(dm_pdev_t *dmp)
171{ 171{
172 172
173 KASSERT(dmp != NULL); 173 KASSERT(dmp != NULL);
174 174
175 if (dmp->pdev_vnode != NULL) { 175 if (dmp->pdev_vnode != NULL) {
176 int error = vn_close(dmp->pdev_vnode, FREAD | FWRITE, FSCRED); 176 int error = vn_close(dmp->pdev_vnode, FREAD | FWRITE, FSCRED);
177 if (error != 0) 177 if (error != 0)
178 return error; 178 return error;
179 } 179 }
180 kmem_free(dmp, sizeof(*dmp)); 180 kmem_free(dmp, sizeof(*dmp));
181 181
182 return 0; 182 return 0;
183} 183}
@@ -206,27 +206,27 @@ dm_pdev_destroy(void) @@ -206,27 +206,27 @@ dm_pdev_destroy(void)
206 206
207/* 207/*
208 * This funcion is called from dm_dev_remove_ioctl. 208 * This funcion is called from dm_dev_remove_ioctl.
209 * When I'm removing device from list, I have to decrement 209 * When I'm removing device from list, I have to decrement
210 * reference counter. If reference counter is 0 I will remove 210 * reference counter. If reference counter is 0 I will remove
211 * dmp from global list and from device list to. And I will CLOSE 211 * dmp from global list and from device list to. And I will CLOSE
212 * dmp vnode too. 212 * dmp vnode too.
213 */ 213 */
214 214
215/* 215/*
216 * Decrement pdev reference counter if 0 remove it. 216 * Decrement pdev reference counter if 0 remove it.
217 */ 217 */
218int 218int
219dm_pdev_decr(dm_pdev_t * dmp) 219dm_pdev_decr(dm_pdev_t *dmp)
220{ 220{
221 KASSERT(dmp != NULL); 221 KASSERT(dmp != NULL);
222 /* 222 /*
223 * If this was last reference remove dmp from 223 * If this was last reference remove dmp from
224 * global list also. 224 * global list also.
225 */ 225 */
226 mutex_enter(&dm_pdev_mutex); 226 mutex_enter(&dm_pdev_mutex);
227 227
228 if (--dmp->ref_cnt == 0) { 228 if (--dmp->ref_cnt == 0) {
229 SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev); 229 SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev);
230 mutex_exit(&dm_pdev_mutex); 230 mutex_exit(&dm_pdev_mutex);
231 dm_pdev_rem(dmp); 231 dm_pdev_rem(dmp);
232 return 0; 232 return 0;

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

--- src/sys/dev/dm/dm_target_zero.c 2019/12/06 16:46:14 1.17
+++ src/sys/dev/dm/dm_target_zero.c 2019/12/07 15:28:39 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_target_zero.c,v 1.17 2019/12/06 16:46:14 tkusumi Exp $ */ 1/* $NetBSD: dm_target_zero.c,v 1.18 2019/12/07 15:28:39 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.
@@ -19,41 +19,41 @@ @@ -19,41 +19,41 @@
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.17 2019/12/06 16:46:14 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_zero.c,v 1.18 2019/12/07 15:28:39 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_dev_t *, void**, char *); 45int dm_target_zero_init(dm_dev_t *, void**, 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.
@@ -103,80 +103,80 @@ dm_target_zero_modcmd(modcmd_t cmd, void @@ -103,80 +103,80 @@ dm_target_zero_modcmd(modcmd_t cmd, void
103 default: 103 default:
104 return ENOTTY; 104 return ENOTTY;
105 } 105 }
106 106
107 return r; 107 return r;
108} 108}
109#endif 109#endif
110 110
111/* 111/*
112 * Zero target init function. This target doesn't need 112 * Zero target init function. This target doesn't need
113 * target specific config area. 113 * target specific config area.
114 */ 114 */
115int 115int
116dm_target_zero_init(dm_dev_t * dmv, void **target_config, char *argv) 116dm_target_zero_init(dm_dev_t *dmv, void **target_config, char *argv)
117{ 117{
118 118
119 printf("Zero target init function called!!\n"); 119 printf("Zero target init function called!!\n");
120 120
121 *target_config = NULL; 121 *target_config = NULL;
122 122
123 return 0; 123 return 0;
124} 124}
125 125
126/* Status routine called to get params string. */ 126/* Status routine called to get params string. */
127char * 127char *
128dm_target_zero_status(void *target_config) 128dm_target_zero_status(void *target_config)
129{ 129{
130 return NULL; 130 return NULL;
131} 131}
132 132
133 133
134/* 134/*
135 * This routine does IO operations. 135 * This routine does IO operations.
136 */ 136 */
137int 137int
138dm_target_zero_strategy(dm_table_entry_t * table_en, struct buf * bp) 138dm_target_zero_strategy(dm_table_entry_t *table_en, struct buf *bp)
139{ 139{
140 140
141 /* printf("Zero target read function called %d!!\n", bp->b_bcount); */ 141 /* printf("Zero target read function called %d!!\n", bp->b_bcount); */
142 142
143 memset(bp->b_data, 0, bp->b_bcount); 143 memset(bp->b_data, 0, bp->b_bcount);
144 bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure 144 bp->b_resid = 0; /* nestiobuf_done wants b_resid = 0 to be sure
145 * that there is no other io to done */ 145 * that there is no other io to done */
146 146
147 biodone(bp); 147 biodone(bp);
148 148
149 return 0; 149 return 0;
150} 150}
151 151
152/* Sync underlying disk caches. */ 152/* Sync underlying disk caches. */
153int 153int
154dm_target_zero_sync(dm_table_entry_t * table_en) 154dm_target_zero_sync(dm_table_entry_t *table_en)
155{ 155{
156 156
157 return 0; 157 return 0;
158} 158}
159 159
160/* Does not need to do anything here. */ 160/* Does not need to do anything here. */
161int 161int
162dm_target_zero_destroy(dm_table_entry_t * table_en) 162dm_target_zero_destroy(dm_table_entry_t *table_en)
163{ 163{
164 /* Unbusy target so we can unload it */ 164 /* Unbusy target so we can unload it */
165 dm_target_unbusy(table_en->target); 165 dm_target_unbusy(table_en->target);
166 166
167 return 0; 167 return 0;
168} 168}
169 169
170/* Does not need to do anything here. */ 170/* Does not need to do anything here. */
171int 171int
172dm_target_zero_deps(dm_table_entry_t * table_en, prop_array_t prop_array) 172dm_target_zero_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
173{ 173{
174 return 0; 174 return 0;
175} 175}
176 176
177/* Unsuported for this target. */ 177/* Unsuported for this target. */
178int 178int
179dm_target_zero_upcall(dm_table_entry_t * table_en, struct buf * bp) 179dm_target_zero_upcall(dm_table_entry_t *table_en, struct buf *bp)
180{ 180{
181 return 0; 181 return 0;
182} 182}

cvs diff -r1.11 -r1.12 src/sys/dev/dm/dm_table.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_table.c 2019/12/07 06:26:31 1.11
+++ src/sys/dev/dm/dm_table.c 2019/12/07 15:28:39 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $ */ 1/* $NetBSD: dm_table.c,v 1.12 2019/12/07 15:28:39 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.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
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_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.12 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/param.h> 35#include <sys/param.h>
36 36
37#include <sys/kmem.h> 37#include <sys/kmem.h>
38 38
39#include "dm.h" 39#include "dm.h"
40 40
41/* 41/*
42 * There are two types of users of this interface: 42 * There are two types of users of this interface:
43 * 43 *
44 * a) Readers such as 44 * a) Readers such as
45 * dmstrategy, dmgetdisklabel, dmsize, dm_dev_status_ioctl, 45 * dmstrategy, dmgetdisklabel, dmsize, dm_dev_status_ioctl,
@@ -53,104 +53,104 @@ __KERNEL_RCSID(0, "$NetBSD: dm_table.c,v @@ -53,104 +53,104 @@ __KERNEL_RCSID(0, "$NetBSD: dm_table.c,v
53 * 53 *
54 */ 54 */
55 55
56static int dm_table_busy(dm_table_head_t *, uint8_t); 56static int dm_table_busy(dm_table_head_t *, uint8_t);
57static void dm_table_unbusy(dm_table_head_t *); 57static void dm_table_unbusy(dm_table_head_t *);
58 58
59/* 59/*
60 * Function to increment table user reference counter. Return id 60 * Function to increment table user reference counter. Return id
61 * of table_id table. 61 * of table_id table.
62 * DM_TABLE_ACTIVE will return active table id. 62 * DM_TABLE_ACTIVE will return active table id.
63 * DM_TABLE_INACTIVE will return inactive table id. 63 * DM_TABLE_INACTIVE will return inactive table id.
64 */ 64 */
65static int 65static int
66dm_table_busy(dm_table_head_t * head, uint8_t table_id) 66dm_table_busy(dm_table_head_t *head, uint8_t table_id)
67{ 67{
68 uint8_t id; 68 uint8_t id;
69 69
70 mutex_enter(&head->table_mtx); 70 mutex_enter(&head->table_mtx);
71 71
72 if (table_id == DM_TABLE_ACTIVE) 72 if (table_id == DM_TABLE_ACTIVE)
73 id = head->cur_active_table; 73 id = head->cur_active_table;
74 else 74 else
75 id = 1 - head->cur_active_table; 75 id = 1 - head->cur_active_table;
76 76
77 head->io_cnt++; 77 head->io_cnt++;
78 78
79 mutex_exit(&head->table_mtx); 79 mutex_exit(&head->table_mtx);
80 return id; 80 return id;
81} 81}
82 82
83/* 83/*
84 * Function release table lock and eventually wakeup all waiters. 84 * Function release table lock and eventually wakeup all waiters.
85 */ 85 */
86static void 86static void
87dm_table_unbusy(dm_table_head_t * head) 87dm_table_unbusy(dm_table_head_t *head)
88{ 88{
89 KASSERT(head->io_cnt != 0); 89 KASSERT(head->io_cnt != 0);
90 90
91 mutex_enter(&head->table_mtx); 91 mutex_enter(&head->table_mtx);
92 92
93 if (--head->io_cnt == 0) 93 if (--head->io_cnt == 0)
94 cv_broadcast(&head->table_cv); 94 cv_broadcast(&head->table_cv);
95 95
96 mutex_exit(&head->table_mtx); 96 mutex_exit(&head->table_mtx);
97} 97}
98 98
99/* 99/*
100 * Return current active table to caller, increment io_cnt reference counter. 100 * Return current active table to caller, increment io_cnt reference counter.
101 */ 101 */
102dm_table_t * 102dm_table_t *
103dm_table_get_entry(dm_table_head_t * head, uint8_t table_id) 103dm_table_get_entry(dm_table_head_t *head, uint8_t table_id)
104{ 104{
105 uint8_t id; 105 uint8_t id;
106 106
107 id = dm_table_busy(head, table_id); 107 id = dm_table_busy(head, table_id);
108 108
109 return &head->tables[id]; 109 return &head->tables[id];
110} 110}
111/* 111/*
112 * Decrement io reference counter and wake up all callers, with table_head cv. 112 * Decrement io reference counter and wake up all callers, with table_head cv.
113 */ 113 */
114void 114void
115dm_table_release(dm_table_head_t * head, uint8_t table_id) 115dm_table_release(dm_table_head_t *head, uint8_t table_id)
116{ 116{
117 dm_table_unbusy(head); 117 dm_table_unbusy(head);
118} 118}
119 119
120/* 120/*
121 * Switch table from inactive to active mode. Have to wait until io_cnt is 0. 121 * Switch table from inactive to active mode. Have to wait until io_cnt is 0.
122 */ 122 */
123void 123void
124dm_table_switch_tables(dm_table_head_t * head) 124dm_table_switch_tables(dm_table_head_t *head)
125{ 125{
126 mutex_enter(&head->table_mtx); 126 mutex_enter(&head->table_mtx);
127 127
128 while (head->io_cnt != 0) 128 while (head->io_cnt != 0)
129 cv_wait(&head->table_cv, &head->table_mtx); 129 cv_wait(&head->table_cv, &head->table_mtx);
130 130
131 head->cur_active_table = 1 - head->cur_active_table; 131 head->cur_active_table = 1 - head->cur_active_table;
132 132
133 mutex_exit(&head->table_mtx); 133 mutex_exit(&head->table_mtx);
134} 134}
135 135
136/* 136/*
137 * Destroy all table data. This function can run when there are no 137 * Destroy all table data. This function can run when there are no
138 * readers on table lists. 138 * readers on table lists.
139 * 139 *
140 * XXX Is it ok to call kmem_free and potentialy VOP_CLOSE with held mutex ?xs 140 * XXX Is it ok to call kmem_free and potentialy VOP_CLOSE with held mutex ?xs
141 */ 141 */
142int 142int
143dm_table_destroy(dm_table_head_t * head, uint8_t table_id) 143dm_table_destroy(dm_table_head_t *head, uint8_t table_id)
144{ 144{
145 dm_table_t *tbl; 145 dm_table_t *tbl;
146 dm_table_entry_t *table_en; 146 dm_table_entry_t *table_en;
147 uint8_t id; 147 uint8_t id;
148 148
149 mutex_enter(&head->table_mtx); 149 mutex_enter(&head->table_mtx);
150 150
151 aprint_debug("dm_Table_destroy called with %d--%d\n", table_id, head->io_cnt); 151 aprint_debug("dm_Table_destroy called with %d--%d\n", table_id, head->io_cnt);
152 152
153 while (head->io_cnt != 0) 153 while (head->io_cnt != 0)
154 cv_wait(&head->table_cv, &head->table_mtx); 154 cv_wait(&head->table_cv, &head->table_mtx);
155 155
156 if (table_id == DM_TABLE_ACTIVE) 156 if (table_id == DM_TABLE_ACTIVE)
@@ -168,27 +168,27 @@ dm_table_destroy(dm_table_head_t * head, @@ -168,27 +168,27 @@ dm_table_destroy(dm_table_head_t * head,
168 kmem_free(table_en, sizeof(*table_en)); 168 kmem_free(table_en, sizeof(*table_en));
169 } 169 }
170 KASSERT(SLIST_EMPTY(tbl)); 170 KASSERT(SLIST_EMPTY(tbl));
171 171
172 mutex_exit(&head->table_mtx); 172 mutex_exit(&head->table_mtx);
173 173
174 return 0; 174 return 0;
175} 175}
176 176
177/* 177/*
178 * Return length of active table in device. 178 * Return length of active table in device.
179 */ 179 */
180static inline uint64_t 180static inline uint64_t
181dm_table_size_impl(dm_table_head_t * head, int table) 181dm_table_size_impl(dm_table_head_t *head, int table)
182{ 182{
183 dm_table_t *tbl; 183 dm_table_t *tbl;
184 dm_table_entry_t *table_en; 184 dm_table_entry_t *table_en;
185 uint64_t length; 185 uint64_t length;
186 uint8_t id; 186 uint8_t id;
187 187
188 length = 0; 188 length = 0;
189 189
190 id = dm_table_busy(head, table); 190 id = dm_table_busy(head, table);
191 191
192 /* Select active table */ 192 /* Select active table */
193 tbl = &head->tables[id]; 193 tbl = &head->tables[id];
194 194
@@ -198,45 +198,45 @@ dm_table_size_impl(dm_table_head_t * hea @@ -198,45 +198,45 @@ dm_table_size_impl(dm_table_head_t * hea
198 */ 198 */
199 SLIST_FOREACH(table_en, tbl, next) 199 SLIST_FOREACH(table_en, tbl, next)
200 length += table_en->length; 200 length += table_en->length;
201 201
202 dm_table_unbusy(head); 202 dm_table_unbusy(head);
203 203
204 return length; 204 return length;
205} 205}
206 206
207/* 207/*
208 * Return length of active table in device. 208 * Return length of active table in device.
209 */ 209 */
210uint64_t 210uint64_t
211dm_table_size(dm_table_head_t * head) 211dm_table_size(dm_table_head_t *head)
212{ 212{
213 return dm_table_size_impl(head, DM_TABLE_ACTIVE); 213 return dm_table_size_impl(head, DM_TABLE_ACTIVE);
214} 214}
215 215
216/* 216/*
217 * Return length of active table in device. 217 * Return length of active table in device.
218 */ 218 */
219uint64_t 219uint64_t
220dm_inactive_table_size(dm_table_head_t * head) 220dm_inactive_table_size(dm_table_head_t *head)
221{ 221{
222 return dm_table_size_impl(head, DM_TABLE_INACTIVE); 222 return dm_table_size_impl(head, DM_TABLE_INACTIVE);
223} 223}
224 224
225/* 225/*
226 * Return combined disk geometry 226 * Return combined disk geometry
227 */ 227 */
228void 228void
229dm_table_disksize(dm_table_head_t * head, uint64_t *numsecp, unsigned *secsizep) 229dm_table_disksize(dm_table_head_t *head, uint64_t *numsecp, unsigned *secsizep)
230{ 230{
231 dm_table_t *tbl; 231 dm_table_t *tbl;
232 dm_table_entry_t *table_en; 232 dm_table_entry_t *table_en;
233 uint64_t length; 233 uint64_t length;
234 unsigned secsize, tsecsize; 234 unsigned secsize, tsecsize;
235 uint8_t id; 235 uint8_t id;
236 236
237 length = 0; 237 length = 0;
238 238
239 id = dm_table_busy(head, DM_TABLE_ACTIVE); 239 id = dm_table_busy(head, DM_TABLE_ACTIVE);
240 240
241 /* Select active table */ 241 /* Select active table */
242 tbl = &head->tables[id]; 242 tbl = &head->tables[id];
@@ -255,68 +255,68 @@ dm_table_disksize(dm_table_head_t * head @@ -255,68 +255,68 @@ dm_table_disksize(dm_table_head_t * head
255 *numsecp = secsize > 0 ? dbtob(length) / secsize : 0; 255 *numsecp = secsize > 0 ? dbtob(length) / secsize : 0;
256 *secsizep = secsize; 256 *secsizep = secsize;
257 257
258 dm_table_unbusy(head); 258 dm_table_unbusy(head);
259} 259}
260 260
261/* 261/*
262 * Return > 0 if table is at least one table entry (returns number of entries) 262 * Return > 0 if table is at least one table entry (returns number of entries)
263 * and return 0 if there is not. Target count returned from this function 263 * and return 0 if there is not. Target count returned from this function
264 * doesn't need to be true when userspace user receive it (after return 264 * doesn't need to be true when userspace user receive it (after return
265 * there can be dm_dev_resume_ioctl), therfore this isonly informative. 265 * there can be dm_dev_resume_ioctl), therfore this isonly informative.
266 */ 266 */
267int 267int
268dm_table_get_target_count(dm_table_head_t * head, uint8_t table_id) 268dm_table_get_target_count(dm_table_head_t *head, uint8_t table_id)
269{ 269{
270 dm_table_entry_t *table_en; 270 dm_table_entry_t *table_en;
271 dm_table_t *tbl; 271 dm_table_t *tbl;
272 uint32_t target_count; 272 uint32_t target_count;
273 uint8_t id; 273 uint8_t id;
274 274
275 target_count = 0; 275 target_count = 0;
276 276
277 id = dm_table_busy(head, table_id); 277 id = dm_table_busy(head, table_id);
278 278
279 tbl = &head->tables[id]; 279 tbl = &head->tables[id];
280 280
281 SLIST_FOREACH(table_en, tbl, next) 281 SLIST_FOREACH(table_en, tbl, next)
282 target_count++; 282 target_count++;
283 283
284 dm_table_unbusy(head); 284 dm_table_unbusy(head);
285 285
286 return target_count; 286 return target_count;
287} 287}
288 288
289 289
290/* 290/*
291 * Initialize table_head structures, I'm trying to keep this structure as 291 * Initialize table_head structures, I'm trying to keep this structure as
292 * opaque as possible. 292 * opaque as possible.
293 */ 293 */
294void 294void
295dm_table_head_init(dm_table_head_t * head) 295dm_table_head_init(dm_table_head_t *head)
296{ 296{
297 head->cur_active_table = 0; 297 head->cur_active_table = 0;
298 head->io_cnt = 0; 298 head->io_cnt = 0;
299 299
300 /* Initialize tables. */ 300 /* Initialize tables. */
301 SLIST_INIT(&head->tables[0]); 301 SLIST_INIT(&head->tables[0]);
302 SLIST_INIT(&head->tables[1]); 302 SLIST_INIT(&head->tables[1]);
303 303
304 mutex_init(&head->table_mtx, MUTEX_DEFAULT, IPL_NONE); 304 mutex_init(&head->table_mtx, MUTEX_DEFAULT, IPL_NONE);
305 cv_init(&head->table_cv, "dm_io"); 305 cv_init(&head->table_cv, "dm_io");
306} 306}
307 307
308/* 308/*
309 * Destroy all variables in table_head 309 * Destroy all variables in table_head
310 */ 310 */
311void 311void
312dm_table_head_destroy(dm_table_head_t * head) 312dm_table_head_destroy(dm_table_head_t *head)
313{ 313{
314 KASSERT(!mutex_owned(&head->table_mtx)); 314 KASSERT(!mutex_owned(&head->table_mtx));
315 KASSERT(!cv_has_waiters(&head->table_cv)); 315 KASSERT(!cv_has_waiters(&head->table_cv));
316 /* tables doens't exists when I call this routine, therefore it 316 /* tables doens't exists when I call this routine, therefore it
317 * doesn't make sense to have io_cnt != 0 */ 317 * doesn't make sense to have io_cnt != 0 */
318 KASSERT(head->io_cnt == 0); 318 KASSERT(head->io_cnt == 0);
319 319
320 cv_destroy(&head->table_cv); 320 cv_destroy(&head->table_cv);
321 mutex_destroy(&head->table_mtx); 321 mutex_destroy(&head->table_mtx);
322} 322}

cvs diff -r1.24 -r1.25 src/sys/dev/dm/dm_target.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target.c 2019/12/07 06:26:31 1.24
+++ src/sys/dev/dm/dm_target.c 2019/12/07 15:28:39 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_target.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $ */ 1/* $NetBSD: dm_target.c,v 1.25 2019/12/07 15:28:39 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.
@@ -19,61 +19,61 @@ @@ -19,61 +19,61 @@
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.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.25 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/param.h> 35#include <sys/param.h>
36 36
37#include <sys/kmem.h> 37#include <sys/kmem.h>
38#include <sys/module.h> 38#include <sys/module.h>
39 39
40 40
41#include "netbsd-dm.h" 41#include "netbsd-dm.h"
42#include "dm.h" 42#include "dm.h"
43 43
44static dm_target_t *dm_target_lookup_name(const char *); 44static dm_target_t *dm_target_lookup_name(const char *);
45 45
46TAILQ_HEAD(dm_target_head, dm_target); 46TAILQ_HEAD(dm_target_head, dm_target);
47 47
48static struct dm_target_head dm_target_list = 48static struct dm_target_head dm_target_list =
49TAILQ_HEAD_INITIALIZER(dm_target_list); 49TAILQ_HEAD_INITIALIZER(dm_target_list);
50 50
51static kmutex_t dm_target_mutex; 51static kmutex_t dm_target_mutex;
52 52
53/* 53/*
54 * Called indirectly from dm_table_load_ioctl to mark target as used. 54 * Called indirectly from dm_table_load_ioctl to mark target as used.
55 */ 55 */
56void 56void
57dm_target_busy(dm_target_t * target) 57dm_target_busy(dm_target_t *target)
58{ 58{
59 atomic_inc_32(&target->ref_cnt); 59 atomic_inc_32(&target->ref_cnt);
60} 60}
61 61
62/* 62/*
63 * Release reference counter on target. 63 * Release reference counter on target.
64 */ 64 */
65void 65void
66dm_target_unbusy(dm_target_t * target) 66dm_target_unbusy(dm_target_t *target)
67{ 67{
68 KASSERT(target->ref_cnt > 0); 68 KASSERT(target->ref_cnt > 0);
69 atomic_dec_32(&target->ref_cnt); 69 atomic_dec_32(&target->ref_cnt);
70} 70}
71 71
72/* 72/*
73 * Try to autoload target module if it was not found in current 73 * Try to autoload target module if it was not found in current
74 * target list. 74 * target list.
75 */ 75 */
76dm_target_t * 76dm_target_t *
77dm_target_autoload(const char *dm_target_name) 77dm_target_autoload(const char *dm_target_name)
78{ 78{
79 char name[30]; 79 char name[30];
@@ -141,27 +141,27 @@ dm_target_lookup_name(const char *dm_tar @@ -141,27 +141,27 @@ dm_target_lookup_name(const char *dm_tar
141 if (strncmp(dm_target_name, dm_target->name, slen) == 0) 141 if (strncmp(dm_target_name, dm_target->name, slen) == 0)
142 return dm_target; 142 return dm_target;
143 } 143 }
144 144
145 return NULL; 145 return NULL;
146} 146}
147 147
148/* 148/*
149 * Insert new target struct into the TAIL. 149 * Insert new target struct into the TAIL.
150 * dm_target 150 * dm_target
151 * contains name, version, function pointer to specifif target functions. 151 * contains name, version, function pointer to specifif target functions.
152 */ 152 */
153int 153int
154dm_target_insert(dm_target_t * dm_target) 154dm_target_insert(dm_target_t *dm_target)
155{ 155{
156 dm_target_t *dmt; 156 dm_target_t *dmt;
157 157
158 /* Sanity check for any missing function */ 158 /* Sanity check for any missing function */
159 KASSERT(dm_target->init != NULL); 159 KASSERT(dm_target->init != NULL);
160 KASSERT(dm_target->status != NULL); 160 KASSERT(dm_target->status != NULL);
161 KASSERT(dm_target->strategy != NULL); 161 KASSERT(dm_target->strategy != NULL);
162 KASSERT(dm_target->deps != NULL); 162 KASSERT(dm_target->deps != NULL);
163 KASSERT(dm_target->destroy != NULL); 163 KASSERT(dm_target->destroy != NULL);
164 KASSERT(dm_target->upcall != NULL); 164 KASSERT(dm_target->upcall != NULL);
165 KASSERT(dm_target->sync != NULL); 165 KASSERT(dm_target->sync != NULL);
166 KASSERT(dm_target->secsize != NULL); 166 KASSERT(dm_target->secsize != NULL);
167 167

cvs diff -r1.24 -r1.25 src/sys/dev/dm/dm_target_snapshot.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target_snapshot.c 2019/12/06 16:11:59 1.24
+++ src/sys/dev/dm/dm_target_snapshot.c 2019/12/07 15:28:39 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_target_snapshot.c,v 1.24 2019/12/06 16:11:59 tkusumi Exp $ */ 1/* $NetBSD: dm_target_snapshot.c,v 1.25 2019/12/07 15:28:39 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.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
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.24 2019/12/06 16:11:59 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.25 2019/12/07 15:28:39 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.
@@ -78,35 +78,35 @@ __KERNEL_RCSID(0, "$NetBSD: dm_target_sn @@ -78,35 +78,35 @@ __KERNEL_RCSID(0, "$NetBSD: dm_target_sn
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_dev_t *, void**, char *); 90int dm_target_snapshot_init(dm_dev_t *, void**, 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_deps(dm_table_entry_t *, prop_array_t); 93int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t);
94int dm_target_snapshot_destroy(dm_table_entry_t *); 94int dm_target_snapshot_destroy(dm_table_entry_t *);
95int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *); 95int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
96 96
97/* dm snapshot origin driver */ 97/* dm snapshot origin driver */
98int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *); 98int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *);
99char * dm_target_snapshot_orig_status(void *); 99char *dm_target_snapshot_orig_status(void *);
100int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *); 100int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
101int dm_target_snapshot_orig_sync(dm_table_entry_t *); 101int dm_target_snapshot_orig_sync(dm_table_entry_t *);
102int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t); 102int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t);
103int dm_target_snapshot_orig_destroy(dm_table_entry_t *); 103int dm_target_snapshot_orig_destroy(dm_table_entry_t *);
104int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *); 104int dm_target_snapshot_orig_upcall(dm_table_entry_t *, struct buf *);
105 105
106#ifdef DM_TARGET_MODULE 106#ifdef DM_TARGET_MODULE
107/* 107/*
108 * Every target can be compiled directly to dm driver or as a 108 * Every target can be compiled directly to dm driver or as a
109 * separate module this part of target is used for loading targets 109 * separate module this part of target is used for loading targets
110 * to dm driver. 110 * to dm driver.
111 * Target can be unloaded from kernel only if there are no users of 111 * Target can be unloaded from kernel only if there are no users of
112 * it e.g. there are no devices which uses that target. 112 * it e.g. there are no devices which uses that target.
@@ -182,27 +182,27 @@ dm_target_snapshot_modcmd(modcmd_t cmd,  @@ -182,27 +182,27 @@ dm_target_snapshot_modcmd(modcmd_t cmd,
182 return ENOTTY; 182 return ENOTTY;
183 } 183 }
184 184
185 return r; 185 return r;
186} 186}
187#endif 187#endif
188 188
189/* 189/*
190 * Init function called from dm_table_load_ioctl. 190 * Init function called from dm_table_load_ioctl.
191 * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64 191 * argv: /dev/mapper/my_data_org /dev/mapper/tsc_cow_dev p 64
192 * snapshot_origin device, cow device, persistent flag, chunk size 192 * snapshot_origin device, cow device, persistent flag, chunk size
193 */ 193 */
194int 194int
195dm_target_snapshot_init(dm_dev_t * dmv, void **target_config, char *params) 195dm_target_snapshot_init(dm_dev_t *dmv, void **target_config, char *params)
196{ 196{
197 dm_target_snapshot_config_t *tsc; 197 dm_target_snapshot_config_t *tsc;
198 dm_pdev_t *dmp_snap, *dmp_cow; 198 dm_pdev_t *dmp_snap, *dmp_cow;
199 char **ap, *argv[5]; 199 char **ap, *argv[5];
200 200
201 dmp_cow = NULL; 201 dmp_cow = NULL;
202 202
203 if (params == NULL) 203 if (params == NULL)
204 return EINVAL; 204 return EINVAL;
205 /* 205 /*
206 * Parse a string, containing tokens delimited by white space, 206 * Parse a string, containing tokens delimited by white space,
207 * into an argument vector 207 * into an argument vector
208 */ 208 */
@@ -285,42 +285,42 @@ dm_target_snapshot_status(void *target_c @@ -285,42 +285,42 @@ dm_target_snapshot_status(void *target_c
285 tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n", 285 tsc->tsc_cow_dev->name, tsc->tsc_persistent_dev ? "p" : "n",
286 tsc->tsc_chunk_size); 286 tsc->tsc_chunk_size);
287 287
288 snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name, 288 snprintf(params, prm_len, "%s %s %s %" PRIu64, tsc->tsc_snap_dev->name,
289 tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "", 289 tsc->tsc_persistent_dev ? tsc->tsc_cow_dev->name : "",
290 tsc->tsc_persistent_dev ? "p" : "n", 290 tsc->tsc_persistent_dev ? "p" : "n",
291 tsc->tsc_chunk_size); 291 tsc->tsc_chunk_size);
292 292
293 return params; 293 return params;
294} 294}
295 295
296/* Strategy routine called from dm_strategy. */ 296/* Strategy routine called from dm_strategy. */
297int 297int
298dm_target_snapshot_strategy(dm_table_entry_t * table_en, struct buf * bp) 298dm_target_snapshot_strategy(dm_table_entry_t *table_en, struct buf *bp)
299{ 299{
300 300
301 printf("Snapshot target read function called!!\n"); 301 printf("Snapshot target read function called!!\n");
302 302
303 bp->b_error = EIO; 303 bp->b_error = EIO;
304 bp->b_resid = 0; 304 bp->b_resid = 0;
305 305
306 biodone(bp); 306 biodone(bp);
307 307
308 return 0; 308 return 0;
309} 309}
310 310
311/* Doesn't do anything here. */ 311/* Doesn't do anything here. */
312int 312int
313dm_target_snapshot_destroy(dm_table_entry_t * table_en) 313dm_target_snapshot_destroy(dm_table_entry_t *table_en)
314{ 314{
315 315
316 /* 316 /*
317 * Destroy function is called for every target even if it 317 * Destroy function is called for every target even if it
318 * doesn't have target_config. 318 * doesn't have target_config.
319 */ 319 */
320 if (table_en->target_config == NULL) 320 if (table_en->target_config == NULL)
321 goto out; 321 goto out;
322 322
323 printf("Snapshot target destroy function called\n"); 323 printf("Snapshot target destroy function called\n");
324 324
325 dm_target_snapshot_config_t *tsc = table_en->target_config; 325 dm_target_snapshot_config_t *tsc = table_en->target_config;
326 326
@@ -329,76 +329,75 @@ dm_target_snapshot_destroy(dm_table_entr @@ -329,76 +329,75 @@ dm_target_snapshot_destroy(dm_table_entr
329 if (tsc->tsc_persistent_dev) 329 if (tsc->tsc_persistent_dev)
330 dm_pdev_decr(tsc->tsc_cow_dev); 330 dm_pdev_decr(tsc->tsc_cow_dev);
331 331
332 kmem_free(tsc, sizeof(*tsc)); 332 kmem_free(tsc, sizeof(*tsc));
333out: 333out:
334 /* Unbusy target so we can unload it */ 334 /* Unbusy target so we can unload it */
335 dm_target_unbusy(table_en->target); 335 dm_target_unbusy(table_en->target);
336 336
337 return 0; 337 return 0;
338} 338}
339 339
340/* Add this target dependencies to prop_array_t */ 340/* Add this target dependencies to prop_array_t */
341int 341int
342dm_target_snapshot_deps(dm_table_entry_t * table_en, 342dm_target_snapshot_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
343 prop_array_t prop_array) 
344{ 343{
345 dm_target_snapshot_config_t *tsc; 344 dm_target_snapshot_config_t *tsc;
346 345
347 if (table_en->target_config == NULL) 346 if (table_en->target_config == NULL)
348 return 0; 347 return 0;
349 348
350 tsc = table_en->target_config; 349 tsc = table_en->target_config;
351 350
352 prop_array_add_uint64(prop_array, 351 prop_array_add_uint64(prop_array,
353 (uint64_t) tsc->tsc_snap_dev->pdev_vnode->v_rdev); 352 (uint64_t) tsc->tsc_snap_dev->pdev_vnode->v_rdev);
354 353
355 if (tsc->tsc_persistent_dev) { 354 if (tsc->tsc_persistent_dev) {
356 prop_array_add_uint64(prop_array, 355 prop_array_add_uint64(prop_array,
357 (uint64_t) tsc->tsc_cow_dev->pdev_vnode->v_rdev); 356 (uint64_t) tsc->tsc_cow_dev->pdev_vnode->v_rdev);
358 357
359 } 358 }
360 return 0; 359 return 0;
361} 360}
362 361
363/* Upcall is used to inform other depended devices about IO. */ 362/* Upcall is used to inform other depended devices about IO. */
364int 363int
365dm_target_snapshot_upcall(dm_table_entry_t * table_en, struct buf * bp) 364dm_target_snapshot_upcall(dm_table_entry_t *table_en, struct buf *bp)
366{ 365{
367 printf("dm_target_snapshot_upcall called\n"); 366 printf("dm_target_snapshot_upcall called\n");
368 367
369 printf("upcall buf flags %s %s\n", 368 printf("upcall buf flags %s %s\n",
370 (bp->b_flags & B_WRITE) ? "B_WRITE" : "", 369 (bp->b_flags & B_WRITE) ? "B_WRITE" : "",
371 (bp->b_flags & B_READ) ? "B_READ" : ""); 370 (bp->b_flags & B_READ) ? "B_READ" : "");
372 371
373 return 0; 372 return 0;
374} 373}
375 374
376/* 375/*
377 * dm target snapshot origin routines. 376 * dm target snapshot origin routines.
378 * 377 *
379 * Keep for compatibility with linux lvm2tools. They use two targets 378 * Keep for compatibility with linux lvm2tools. They use two targets
380 * to implement snapshots. Snapshot target will implement exception 379 * to implement snapshots. Snapshot target will implement exception
381 * store and snapshot origin will implement device which calls every 380 * store and snapshot origin will implement device which calls every
382 * snapshot device when write is done on master device. 381 * snapshot device when write is done on master device.
383 */ 382 */
384 383
385/* 384/*
386 * Init function called from dm_table_load_ioctl. 385 * Init function called from dm_table_load_ioctl.
387 * 386 *
388 * argv: /dev/mapper/my_data_real 387 * argv: /dev/mapper/my_data_real
389 */ 388 */
390int 389int
391dm_target_snapshot_orig_init(dm_dev_t * dmv, void **target_config, char *params) 390dm_target_snapshot_orig_init(dm_dev_t *dmv, void **target_config, char *params)
392{ 391{
393 dm_target_snapshot_origin_config_t *tsoc; 392 dm_target_snapshot_origin_config_t *tsoc;
394 dm_pdev_t *dmp_real; 393 dm_pdev_t *dmp_real;
395 394
396 if (params == NULL) 395 if (params == NULL)
397 return EINVAL; 396 return EINVAL;
398 397
399 printf("Snapshot origin target init function called!!\n"); 398 printf("Snapshot origin target init function called!!\n");
400 printf("Parent device: %s\n", params); 399 printf("Parent device: %s\n", params);
401 400
402 /* Insert snap device to global pdev list */ 401 /* Insert snap device to global pdev list */
403 if ((dmp_real = dm_pdev_insert(params)) == NULL) 402 if ((dmp_real = dm_pdev_insert(params)) == NULL)
404 return ENOENT; 403 return ENOENT;
@@ -436,59 +435,59 @@ dm_target_snapshot_orig_status(void *tar @@ -436,59 +435,59 @@ dm_target_snapshot_orig_status(void *tar
436 printf("real_dev name %s\n", tsoc->tsoc_real_dev->name); 435 printf("real_dev name %s\n", tsoc->tsoc_real_dev->name);
437 436
438 params = kmem_alloc(prm_len, KM_SLEEP); 437 params = kmem_alloc(prm_len, KM_SLEEP);
439 438
440 printf("%s\n", tsoc->tsoc_real_dev->name); 439 printf("%s\n", tsoc->tsoc_real_dev->name);
441 440
442 snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name); 441 snprintf(params, prm_len, "%s", tsoc->tsoc_real_dev->name);
443 442
444 return params; 443 return params;
445} 444}
446 445
447/* Strategy routine called from dm_strategy. */ 446/* Strategy routine called from dm_strategy. */
448int 447int
449dm_target_snapshot_orig_strategy(dm_table_entry_t * table_en, struct buf * bp) 448dm_target_snapshot_orig_strategy(dm_table_entry_t *table_en, struct buf *bp)
450{ 449{
451 450
452 printf("Snapshot_Orig target read function called!!\n"); 451 printf("Snapshot_Orig target read function called!!\n");
453 452
454 bp->b_error = EIO; 453 bp->b_error = EIO;
455 bp->b_resid = 0; 454 bp->b_resid = 0;
456 455
457 biodone(bp); 456 biodone(bp);
458 457
459 return 0; 458 return 0;
460} 459}
461 460
462/* 461/*
463 * Sync underlying disk caches. 462 * Sync underlying disk caches.
464 */ 463 */
465int 464int
466dm_target_snapshot_orig_sync(dm_table_entry_t * table_en) 465dm_target_snapshot_orig_sync(dm_table_entry_t *table_en)
467{ 466{
468 int cmd; 467 int cmd;
469 dm_target_snapshot_origin_config_t *tsoc; 468 dm_target_snapshot_origin_config_t *tsoc;
470 469
471 tsoc = table_en->target_config; 470 tsoc = table_en->target_config;
472 471
473 cmd = 1; 472 cmd = 1;
474 473
475 return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC, 474 return VOP_IOCTL(tsoc->tsoc_real_dev->pdev_vnode, DIOCCACHESYNC,
476 &cmd, FREAD|FWRITE, kauth_cred_get()); 475 &cmd, FREAD|FWRITE, kauth_cred_get());
477} 476}
478 477
479/* Decrement pdev and free allocated space. */ 478/* Decrement pdev and free allocated space. */
480int 479int
481dm_target_snapshot_orig_destroy(dm_table_entry_t * table_en) 480dm_target_snapshot_orig_destroy(dm_table_entry_t *table_en)
482{ 481{
483 482
484 /* 483 /*
485 * Destroy function is called for every target even if it 484 * Destroy function is called for every target even if it
486 * doesn't have target_config. 485 * doesn't have target_config.
487 */ 486 */
488 487
489 if (table_en->target_config == NULL) 488 if (table_en->target_config == NULL)
490 goto out; 489 goto out;
491 490
492 dm_target_snapshot_origin_config_t *tsoc = table_en->target_config; 491 dm_target_snapshot_origin_config_t *tsoc = table_en->target_config;
493 492
494 /* Decrement pdev ref counter if 0 remove it */ 493 /* Decrement pdev ref counter if 0 remove it */
@@ -496,44 +495,44 @@ dm_target_snapshot_orig_destroy(dm_table @@ -496,44 +495,44 @@ dm_target_snapshot_orig_destroy(dm_table
496 495
497 kmem_free(tsoc, sizeof(*tsoc)); 496 kmem_free(tsoc, sizeof(*tsoc));
498out: 497out:
499 /* Unbusy target so we can unload it */ 498 /* Unbusy target so we can unload it */
500 dm_target_unbusy(table_en->target); 499 dm_target_unbusy(table_en->target);
501 500
502 return 0; 501 return 0;
503} 502}
504 503
505/* 504/*
506 * Get target deps and add them to prop_array_t. 505 * Get target deps and add them to prop_array_t.
507 */ 506 */
508int 507int
509dm_target_snapshot_orig_deps(dm_table_entry_t * table_en, 508dm_target_snapshot_orig_deps(dm_table_entry_t *table_en,
510 prop_array_t prop_array) 509 prop_array_t prop_array)
511{ 510{
512 dm_target_snapshot_origin_config_t *tsoc; 511 dm_target_snapshot_origin_config_t *tsoc;
513 struct vattr va; 512 struct vattr va;
514 513
515 int error; 514 int error;
516 515
517 if (table_en->target_config == NULL) 516 if (table_en->target_config == NULL)
518 return 0; 517 return 0;
519 518
520 tsoc = table_en->target_config; 519 tsoc = table_en->target_config;
521 520
522 vn_lock(tsoc->tsoc_real_dev->pdev_vnode, LK_SHARED | LK_RETRY); 521 vn_lock(tsoc->tsoc_real_dev->pdev_vnode, LK_SHARED | LK_RETRY);
523 error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va, 522 error = VOP_GETATTR(tsoc->tsoc_real_dev->pdev_vnode, &va,
524 curlwp->l_cred); 523 curlwp->l_cred);
525 VOP_UNLOCK(tsoc->tsoc_real_dev->pdev_vnode); 524 VOP_UNLOCK(tsoc->tsoc_real_dev->pdev_vnode);
526 if (error != 0) 525 if (error != 0)
527 return error; 526 return error;
528 527
529 prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev); 528 prop_array_add_uint64(prop_array, (uint64_t) va.va_rdev);
530 529
531 return 0; 530 return 0;
532} 531}
533 532
534/* Unsupported for this target. */ 533/* Unsupported for this target. */
535int 534int
536dm_target_snapshot_orig_upcall(dm_table_entry_t * table_en, struct buf * bp) 535dm_target_snapshot_orig_upcall(dm_table_entry_t *table_en, struct buf *bp)
537{ 536{
538 return 0; 537 return 0;
539} 538}

cvs diff -r1.15 -r1.16 src/sys/dev/dm/dm_target_error.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target_error.c 2019/12/06 16:11:59 1.15
+++ src/sys/dev/dm/dm_target_error.c 2019/12/07 15:28:39 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_target_error.c,v 1.15 2019/12/06 16:11:59 tkusumi Exp $ */ 1/* $NetBSD: dm_target_error.c,v 1.16 2019/12/07 15:28:39 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.
@@ -19,41 +19,41 @@ @@ -19,41 +19,41 @@
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.15 2019/12/06 16:11:59 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_error.c,v 1.16 2019/12/07 15:28:39 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_dev_t *, void**, char *); 45int dm_target_error_init(dm_dev_t *, void**, 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.
@@ -100,76 +100,76 @@ dm_target_error_modcmd(modcmd_t cmd, voi @@ -100,76 +100,76 @@ dm_target_error_modcmd(modcmd_t cmd, voi
100 case MODULE_CMD_STAT: 100 case MODULE_CMD_STAT:
101 return ENOTTY; 101 return ENOTTY;
102 102
103 default: 103 default:
104 return ENOTTY; 104 return ENOTTY;
105 } 105 }
106 106
107 return r; 107 return r;
108} 108}
109#endif 109#endif
110 110
111/* Init function called from dm_table_load_ioctl. */ 111/* Init function called from dm_table_load_ioctl. */
112int 112int
113dm_target_error_init(dm_dev_t * dmv, void **target_config, char *argv) 113dm_target_error_init(dm_dev_t *dmv, void **target_config, char *argv)
114{ 114{
115 115
116 printf("Error target init function called!!\n"); 116 printf("Error target init function called!!\n");
117 117
118 *target_config = NULL; 118 *target_config = NULL;
119 119
120 return 0; 120 return 0;
121} 121}
122 122
123/* Status routine called to get params string. */ 123/* Status routine called to get params string. */
124char * 124char *
125dm_target_error_status(void *target_config) 125dm_target_error_status(void *target_config)
126{ 126{
127 return NULL; 127 return NULL;
128} 128}
129 129
130/* Strategy routine called from dm_strategy. */ 130/* Strategy routine called from dm_strategy. */
131int 131int
132dm_target_error_strategy(dm_table_entry_t * table_en, struct buf * bp) 132dm_target_error_strategy(dm_table_entry_t *table_en, struct buf *bp)
133{ 133{
134 134
135 printf("Error target read function called!!\n"); 135 printf("Error target read function called!!\n");
136 136
137 bp->b_error = EIO; 137 bp->b_error = EIO;
138 bp->b_resid = 0; 138 bp->b_resid = 0;
139 139
140 biodone(bp); 140 biodone(bp);
141 141
142 return 0; 142 return 0;
143} 143}
144 144
145/* Sync underlying disk caches. */ 145/* Sync underlying disk caches. */
146int 146int
147dm_target_error_sync(dm_table_entry_t * table_en) 147dm_target_error_sync(dm_table_entry_t *table_en)
148{ 148{
149 149
150 return 0; 150 return 0;
151} 151}
152 152
153/* Doesn't do anything here. */ 153/* Doesn't do anything here. */
154int 154int
155dm_target_error_destroy(dm_table_entry_t * table_en) 155dm_target_error_destroy(dm_table_entry_t *table_en)
156{ 156{
157 /* Unbusy target so we can unload it */ 157 /* Unbusy target so we can unload it */
158 dm_target_unbusy(table_en->target); 158 dm_target_unbusy(table_en->target);
159 159
160 return 0; 160 return 0;
161} 161}
162 162
163/* Doesn't not need to do anything here. */ 163/* Doesn't not need to do anything here. */
164int 164int
165dm_target_error_deps(dm_table_entry_t * table_en, prop_array_t prop_array) 165dm_target_error_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
166{ 166{
167 return 0; 167 return 0;
168} 168}
169 169
170/* Unsupported for this target. */ 170/* Unsupported for this target. */
171int 171int
172dm_target_error_upcall(dm_table_entry_t * table_en, struct buf * bp) 172dm_target_error_upcall(dm_table_entry_t *table_en, struct buf *bp)
173{ 173{
174 return 0; 174 return 0;
175} 175}

cvs diff -r1.23 -r1.24 src/sys/dev/dm/dm_target_linear.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target_linear.c 2019/12/06 16:46:14 1.23
+++ src/sys/dev/dm/dm_target_linear.c 2019/12/07 15:28:39 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dm_target_linear.c,v 1.23 2019/12/06 16:46:14 tkusumi Exp $ */ 1/* $NetBSD: dm_target_linear.c,v 1.24 2019/12/07 15:28:39 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.
@@ -19,53 +19,53 @@ @@ -19,53 +19,53 @@
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_linear.c,v 1.23 2019/12/06 16:46:14 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_linear.c,v 1.24 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34/* 34/*
35 * This file implements initial version of device-mapper dklinear target. 35 * This file implements initial version of device-mapper dklinear target.
36 */ 36 */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
39#include <sys/param.h> 39#include <sys/param.h>
40 40
41#include <sys/buf.h> 41#include <sys/buf.h>
42#include <sys/kmem.h> 42#include <sys/kmem.h>
43#include <sys/lwp.h> 43#include <sys/lwp.h>
44 44
45#include <machine/int_fmtio.h> 45#include <machine/int_fmtio.h>
46 46
47#include "dm.h" 47#include "dm.h"
48 48
49/* 49/*
50 * Allocate target specific config data, and link them to table. 50 * Allocate target specific config data, and link them to table.
51 * This function is called only when, flags is not READONLY and 51 * This function is called only when, flags is not READONLY and
52 * therefore we can add things to pdev list. This should not a 52 * therefore we can add things to pdev list. This should not a
53 * problem because this routine is called only from dm_table_load_ioctl. 53 * problem because this routine is called only from dm_table_load_ioctl.
54 * @argv[0] is name, 54 * @argv[0] is name,
55 * @argv[1] is physical data offset. 55 * @argv[1] is physical data offset.
56 */ 56 */
57int 57int
58dm_target_linear_init(dm_dev_t * dmv, void **target_config, char *params) 58dm_target_linear_init(dm_dev_t *dmv, void **target_config, char *params)
59{ 59{
60 dm_target_linear_config_t *tlc; 60 dm_target_linear_config_t *tlc;
61 dm_pdev_t *dmp; 61 dm_pdev_t *dmp;
62 62
63 char **ap, *argv[3]; 63 char **ap, *argv[3];
64 64
65 if (params == NULL) 65 if (params == NULL)
66 return EINVAL; 66 return EINVAL;
67 67
68 /* 68 /*
69 * Parse a string, containing tokens delimited by white space, 69 * Parse a string, containing tokens delimited by white space,
70 * into an argument vector 70 * into an argument vector
71 */ 71 */
@@ -107,121 +107,121 @@ dm_target_linear_status(void *target_con @@ -107,121 +107,121 @@ dm_target_linear_status(void *target_con
107 107
108 params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP); 108 params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_SLEEP);
109 aprint_normal("%s %" PRIu64, tlc->pdev->name, tlc->offset); 109 aprint_normal("%s %" PRIu64, tlc->pdev->name, tlc->offset);
110 snprintf(params, DM_MAX_PARAMS_SIZE, "%s %" PRIu64, 110 snprintf(params, DM_MAX_PARAMS_SIZE, "%s %" PRIu64,
111 tlc->pdev->name, tlc->offset); 111 tlc->pdev->name, tlc->offset);
112 112
113 return params; 113 return params;
114} 114}
115 115
116/* 116/*
117 * Do IO operation, called from dmstrategy routine. 117 * Do IO operation, called from dmstrategy routine.
118 */ 118 */
119int 119int
120dm_target_linear_strategy(dm_table_entry_t * table_en, struct buf * bp) 120dm_target_linear_strategy(dm_table_entry_t *table_en, struct buf *bp)
121{ 121{
122 dm_target_linear_config_t *tlc; 122 dm_target_linear_config_t *tlc;
123 123
124 tlc = table_en->target_config; 124 tlc = table_en->target_config;
125 125
126/* printf("Linear target read function called %" PRIu64 "!!\n", 126/* printf("Linear target read function called %" PRIu64 "!!\n",
127 tlc->offset);*/ 127 tlc->offset);*/
128 128
129 bp->b_blkno += tlc->offset; 129 bp->b_blkno += tlc->offset;
130 130
131 VOP_STRATEGY(tlc->pdev->pdev_vnode, bp); 131 VOP_STRATEGY(tlc->pdev->pdev_vnode, bp);
132 132
133 return 0; 133 return 0;
134 134
135} 135}
136 136
137/* 137/*
138 * Sync underlying disk caches. 138 * Sync underlying disk caches.
139 */ 139 */
140int 140int
141dm_target_linear_sync(dm_table_entry_t * table_en) 141dm_target_linear_sync(dm_table_entry_t *table_en)
142{ 142{
143 int cmd; 143 int cmd;
144 dm_target_linear_config_t *tlc; 144 dm_target_linear_config_t *tlc;
145 145
146 tlc = table_en->target_config; 146 tlc = table_en->target_config;
147 147
148 cmd = 1; 148 cmd = 1;
149 149
150 return VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, &cmd, 150 return VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, &cmd,
151 FREAD|FWRITE, kauth_cred_get()); 151 FREAD|FWRITE, kauth_cred_get());
152} 152}
153 153
154/* 154/*
155 * Destroy target specific data. Decrement table pdevs. 155 * Destroy target specific data. Decrement table pdevs.
156 */ 156 */
157int 157int
158dm_target_linear_destroy(dm_table_entry_t * table_en) 158dm_target_linear_destroy(dm_table_entry_t *table_en)
159{ 159{
160 160
161 /* 161 /*
162 * Destroy function is called for every target even if it 162 * Destroy function is called for every target even if it
163 * doesn't have target_config. 163 * doesn't have target_config.
164 */ 164 */
165 if (table_en->target_config == NULL) 165 if (table_en->target_config == NULL)
166 goto out; 166 goto out;
167 167
168 dm_target_linear_config_t *tlc = table_en->target_config; 168 dm_target_linear_config_t *tlc = table_en->target_config;
169 169
170 /* Decrement pdev ref counter if 0 remove it */ 170 /* Decrement pdev ref counter if 0 remove it */
171 dm_pdev_decr(tlc->pdev); 171 dm_pdev_decr(tlc->pdev);
172 172
173 kmem_free(tlc, sizeof(*tlc)); 173 kmem_free(tlc, sizeof(*tlc));
174 174
175out: 175out:
176 /* Unbusy target so we can unload it */ 176 /* Unbusy target so we can unload it */
177 dm_target_unbusy(table_en->target); 177 dm_target_unbusy(table_en->target);
178 return 0; 178 return 0;
179} 179}
180 180
181/* Add this target pdev dependencies to prop_array_t */ 181/* Add this target pdev dependencies to prop_array_t */
182int 182int
183dm_target_linear_deps(dm_table_entry_t * table_en, prop_array_t prop_array) 183dm_target_linear_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
184{ 184{
185 dm_target_linear_config_t *tlc; 185 dm_target_linear_config_t *tlc;
186 186
187 if (table_en->target_config == NULL) 187 if (table_en->target_config == NULL)
188 return ENOENT; 188 return ENOENT;
189 189
190 tlc = table_en->target_config; 190 tlc = table_en->target_config;
191 191
192 prop_array_add_uint64(prop_array, 192 prop_array_add_uint64(prop_array,
193 (uint64_t) tlc->pdev->pdev_vnode->v_rdev); 193 (uint64_t) tlc->pdev->pdev_vnode->v_rdev);
194 194
195 return 0; 195 return 0;
196} 196}
197 197
198/* 198/*
199 * Register upcall device. 199 * Register upcall device.
200 * Linear target doesn't need any upcall devices but other targets like 200 * Linear target doesn't need any upcall devices but other targets like
201 * mirror, snapshot, multipath, stripe will use this functionality. 201 * mirror, snapshot, multipath, stripe will use this functionality.
202 */ 202 */
203int 203int
204dm_target_linear_upcall(dm_table_entry_t * table_en, struct buf * bp) 204dm_target_linear_upcall(dm_table_entry_t *table_en, struct buf *bp)
205{ 205{
206 return 0; 206 return 0;
207} 207}
208 208
209/* 209/*
210 * Query physical block size of this target 210 * Query physical block size of this target
211 * For a linear target this is just the sector size of the underlying device 211 * For a linear target this is just the sector size of the underlying device
212 */ 212 */
213int 213int
214dm_target_linear_secsize(dm_table_entry_t * table_en, unsigned *secsizep) 214dm_target_linear_secsize(dm_table_entry_t *table_en, unsigned *secsizep)
215{ 215{
216 dm_target_linear_config_t *tlc; 216 dm_target_linear_config_t *tlc;
217 unsigned secsize; 217 unsigned secsize;
218 218
219 secsize = 0; 219 secsize = 0;
220 220
221 tlc = table_en->target_config; 221 tlc = table_en->target_config;
222 if (tlc != NULL) 222 if (tlc != NULL)
223 secsize = tlc->pdev->pdev_secsize; 223 secsize = tlc->pdev->pdev_secsize;
224 224
225 *secsizep = secsize; 225 *secsizep = secsize;
226 226
227 return 0; 227 return 0;

cvs diff -r1.29 -r1.30 src/sys/dev/dm/dm_target_stripe.c (expand / switch to unified diff)

--- src/sys/dev/dm/dm_target_stripe.c 2019/12/06 16:33:47 1.29
+++ src/sys/dev/dm/dm_target_stripe.c 2019/12/07 15:28:39 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/*$NetBSD: dm_target_stripe.c,v 1.29 2019/12/06 16:33:47 tkusumi Exp $*/ 1/*$NetBSD: dm_target_stripe.c,v 1.30 2019/12/07 15:28:39 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.
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
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_stripe.c,v 1.29 2019/12/06 16:33:47 tkusumi Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: dm_target_stripe.c,v 1.30 2019/12/07 15:28:39 tkusumi Exp $");
33 33
34/* 34/*
35 * This file implements initial version of device-mapper stripe target. 35 * This file implements initial version of device-mapper stripe 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#include <sys/kmem.h> 41#include <sys/kmem.h>
42#include <sys/lwp.h> 42#include <sys/lwp.h>
43 43
44#include "dm.h" 44#include "dm.h"
45 45
@@ -118,27 +118,27 @@ dm_target_stripe_fini(dm_target_stripe_c @@ -118,27 +118,27 @@ dm_target_stripe_fini(dm_target_stripe_c
118 118
119 kmem_free(tsc, sizeof(*tsc)); 119 kmem_free(tsc, sizeof(*tsc));
120} 120}
121 121
122/* 122/*
123 * Init function called from dm_table_load_ioctl. 123 * Init function called from dm_table_load_ioctl.
124 * DM_STRIPE_DEV_OFFSET should always hold the index of the first device-offset 124 * DM_STRIPE_DEV_OFFSET should always hold the index of the first device-offset
125 * pair in the parameters. 125 * pair in the parameters.
126 * Example line sent to dm from lvm tools when using striped target. 126 * Example line sent to dm from lvm tools when using striped target.
127 * start length striped #stripes chunk_size device1 offset1 ... deviceN offsetN 127 * start length striped #stripes chunk_size device1 offset1 ... deviceN offsetN
128 * 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0 128 * 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0
129 */ 129 */
130int 130int
131dm_target_stripe_init(dm_dev_t * dmv, void **target_config, char *params) 131dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params)
132{ 132{
133 dm_target_linear_config_t *tlc; 133 dm_target_linear_config_t *tlc;
134 dm_target_stripe_config_t *tsc; 134 dm_target_stripe_config_t *tsc;
135 size_t len; 135 size_t len;
136 char **ap, *argv[10]; 136 char **ap, *argv[10];
137 int strpc, strpi; 137 int strpc, strpi;
138 138
139 if (params == NULL) 139 if (params == NULL)
140 return EINVAL; 140 return EINVAL;
141 141
142 len = strlen(params) + 1; 142 len = strlen(params) + 1;
143 143
144 /* 144 /*
@@ -207,27 +207,27 @@ dm_target_stripe_status(void *target_con @@ -207,27 +207,27 @@ dm_target_stripe_status(void *target_con
207 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) { 207 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
208 snprintf(tmp, DM_MAX_PARAMS_SIZE, " %s %" PRIu64, 208 snprintf(tmp, DM_MAX_PARAMS_SIZE, " %s %" PRIu64,
209 tlc->pdev->name, tlc->offset); 209 tlc->pdev->name, tlc->offset);
210 strcat(params, tmp); 210 strcat(params, tmp);
211 } 211 }
212 212
213 kmem_free(tmp, DM_MAX_PARAMS_SIZE); 213 kmem_free(tmp, DM_MAX_PARAMS_SIZE);
214 214
215 return params; 215 return params;
216} 216}
217 217
218/* Strategy routine called from dm_strategy. */ 218/* Strategy routine called from dm_strategy. */
219int 219int
220dm_target_stripe_strategy(dm_table_entry_t * table_en, struct buf * bp) 220dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp)
221{ 221{
222 dm_target_linear_config_t *tlc; 222 dm_target_linear_config_t *tlc;
223 dm_target_stripe_config_t *tsc; 223 dm_target_stripe_config_t *tsc;
224 struct buf *nestbuf; 224 struct buf *nestbuf;
225 uint64_t blkno, blkoff; 225 uint64_t blkno, blkoff;
226 uint64_t stripe, stripe_blknr; 226 uint64_t stripe, stripe_blknr;
227 uint32_t stripe_off, stripe_rest, num_blks, issue_blks; 227 uint32_t stripe_off, stripe_rest, num_blks, issue_blks;
228 int i, stripe_devnr; 228 int i, stripe_devnr;
229 229
230 tsc = table_en->target_config; 230 tsc = table_en->target_config;
231 if (tsc == NULL) 231 if (tsc == NULL)
232 return 0; 232 return 0;
233 233
@@ -273,94 +273,94 @@ dm_target_stripe_strategy(dm_table_entry @@ -273,94 +273,94 @@ dm_target_stripe_strategy(dm_table_entry
273 blkno += issue_blks; 273 blkno += issue_blks;
274 blkoff += issue_blks * DEV_BSIZE; 274 blkoff += issue_blks * DEV_BSIZE;
275 num_blks -= issue_blks; 275 num_blks -= issue_blks;
276 276
277 if (num_blks <= 0) 277 if (num_blks <= 0)
278 break; 278 break;
279 } 279 }
280 280
281 return 0; 281 return 0;
282} 282}
283 283
284/* Sync underlying disk caches. */ 284/* Sync underlying disk caches. */
285int 285int
286dm_target_stripe_sync(dm_table_entry_t * table_en) 286dm_target_stripe_sync(dm_table_entry_t *table_en)
287{ 287{
288 int cmd, err; 288 int cmd, err;
289 dm_target_stripe_config_t *tsc; 289 dm_target_stripe_config_t *tsc;
290 dm_target_linear_config_t *tlc; 290 dm_target_linear_config_t *tlc;
291 291
292 tsc = table_en->target_config; 292 tsc = table_en->target_config;
293 293
294 err = 0; 294 err = 0;
295 cmd = 1; 295 cmd = 1;
296 296
297 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) { 297 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
298 if ((err = VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC, 298 if ((err = VOP_IOCTL(tlc->pdev->pdev_vnode, DIOCCACHESYNC,
299 &cmd, FREAD|FWRITE, kauth_cred_get())) != 0) 299 &cmd, FREAD|FWRITE, kauth_cred_get())) != 0)
300 return err; 300 return err;
301 } 301 }
302 302
303 return err; 303 return err;
304 304
305} 305}
306 306
307/* Destroy target specific data. */ 307/* Destroy target specific data. */
308int 308int
309dm_target_stripe_destroy(dm_table_entry_t * table_en) 309dm_target_stripe_destroy(dm_table_entry_t *table_en)
310{ 310{
311 dm_target_stripe_fini(table_en->target_config); 311 dm_target_stripe_fini(table_en->target_config);
312 312
313 /* Unbusy target so we can unload it */ 313 /* Unbusy target so we can unload it */
314 dm_target_unbusy(table_en->target); 314 dm_target_unbusy(table_en->target);
315 315
316 return 0; 316 return 0;
317} 317}
318 318
319/* Doesn't not need to do anything here. */ 319/* Doesn't not need to do anything here. */
320int 320int
321dm_target_stripe_deps(dm_table_entry_t * table_en, prop_array_t prop_array) 321dm_target_stripe_deps(dm_table_entry_t *table_en, prop_array_t prop_array)
322{ 322{
323 dm_target_stripe_config_t *tsc; 323 dm_target_stripe_config_t *tsc;
324 dm_target_linear_config_t *tlc; 324 dm_target_linear_config_t *tlc;
325 325
326 if (table_en->target_config == NULL) 326 if (table_en->target_config == NULL)
327 return ENOENT; 327 return ENOENT;
328 328
329 tsc = table_en->target_config; 329 tsc = table_en->target_config;
330 330
331 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) { 331 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
332 prop_array_add_uint64(prop_array, 332 prop_array_add_uint64(prop_array,
333 (uint64_t) tlc->pdev->pdev_vnode->v_rdev); 333 (uint64_t) tlc->pdev->pdev_vnode->v_rdev);
334 } 334 }
335 335
336 return 0; 336 return 0;
337} 337}
338 338
339/* Unsupported for this target. */ 339/* Unsupported for this target. */
340int 340int
341dm_target_stripe_upcall(dm_table_entry_t * table_en, struct buf * bp) 341dm_target_stripe_upcall(dm_table_entry_t *table_en, struct buf *bp)
342{ 342{
343 return 0; 343 return 0;
344} 344}
345 345
346/* 346/*
347 * Compute physical block size 347 * Compute physical block size
348 * For a stripe target we chose the maximum sector size of all 348 * For a stripe target we chose the maximum sector size of all
349 * stripe devices. For the supported power-of-2 sizes this is equivalent 349 * stripe devices. For the supported power-of-2 sizes this is equivalent
350 * to the least common multiple. 350 * to the least common multiple.
351 */ 351 */
352int 352int
353dm_target_stripe_secsize(dm_table_entry_t * table_en, unsigned *secsizep) 353dm_target_stripe_secsize(dm_table_entry_t *table_en, unsigned *secsizep)
354{ 354{
355 dm_target_linear_config_t *tlc; 355 dm_target_linear_config_t *tlc;
356 dm_target_stripe_config_t *tsc; 356 dm_target_stripe_config_t *tsc;
357 unsigned secsize; 357 unsigned secsize;
358 358
359 secsize = 0; 359 secsize = 0;
360 360
361 tsc = table_en->target_config; 361 tsc = table_en->target_config;
362 if (tsc != NULL) { 362 if (tsc != NULL) {
363 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) { 363 TAILQ_FOREACH(tlc, &tsc->stripe_devs, entries) {
364 if (secsize < tlc->pdev->pdev_secsize) 364 if (secsize < tlc->pdev->pdev_secsize)
365 secsize = tlc->pdev->pdev_secsize; 365 secsize = tlc->pdev->pdev_secsize;
366 } 366 }

cvs diff -r1.2 -r1.3 src/sys/dev/dm/doc/locking.txt (expand / switch to unified diff)

--- src/sys/dev/dm/doc/locking.txt 2019/12/01 06:53:32 1.2
+++ src/sys/dev/dm/doc/locking.txt 2019/12/07 15:28:39 1.3
@@ -110,27 +110,27 @@ these routines to manage access to table @@ -110,27 +110,27 @@ these routines to manage access to table
110 * Destroy all table data. This function can run when there are no  110 * Destroy all table data. This function can run when there are no
111 * readers on table lists.  111 * readers on table lists.
112 */ 112 */
113int dm_table_destroy(dm_table_head_t *, uint8_t); 113int dm_table_destroy(dm_table_head_t *, uint8_t);
114 114
115/*  115/*
116 * Return length of active table in device.  116 * Return length of active table in device.
117 */ 117 */
118uint64_t dm_table_size(dm_table_head_t *); 118uint64_t dm_table_size(dm_table_head_t *);
119 119
120/*  120/*
121 * Return current active table to caller, increment io_cnt reference counter.  121 * Return current active table to caller, increment io_cnt reference counter.
122 */ 122 */
123struct dm_table * dm_table_get_entry(dm_table_head_t *, uint8_t); 123struct dm_table *dm_table_get_entry(dm_table_head_t *, uint8_t);
124 124
125/*  125/*
126 * Return > 0 if table is at least one table entry (returns number of entries)  126 * Return > 0 if table is at least one table entry (returns number of entries)
127 * and return 0 if there is not. Target count returned from this function  127 * and return 0 if there is not. Target count returned from this function
128 * doesn't need to be true when userspace user receive it (after return  128 * doesn't need to be true when userspace user receive it (after return
129 * there can be dm_dev_resume_ioctl), therfore this isonly informative.  129 * there can be dm_dev_resume_ioctl), therfore this isonly informative.
130 */ 130 */
131int dm_table_get_target_count(dm_table_head_t *, uint8_t); 131int dm_table_get_target_count(dm_table_head_t *, uint8_t);
132 132
133/*  133/*
134 * Decrement io reference counter and wake up all callers, with table_head cv.  134 * Decrement io reference counter and wake up all callers, with table_head cv.
135 */ 135 */
136void dm_table_release(dm_table_head_t *, uint8_t s); 136void dm_table_release(dm_table_head_t *, uint8_t s);