Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/dm dm: Remove target's ->deps() by implementing deps...
details: https://anonhg.NetBSD.org/src/rev/3bf3854fc299
branches: trunk
changeset: 967761:3bf3854fc299
user: tkusumi <tkusumi%NetBSD.org@localhost>
date: Sat Dec 21 11:59:03 2019 +0000
description:
dm: Remove target's ->deps() by implementing deps in dm core
Retrieving device dependencies doesn't need to be target specific.
The reason it currently needs ->deps() is because dm core doesn't
have data structure that allows table to walk through target's
underlying devices. Add struct dm_mapping to be able to do this,
and remove ->deps()'s from targets which basically do the same thing.
=====(A) before this commit
table
| [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)
=====(B) this commit
table---->mapping-->mapping-->mapping-->...
| | | |
| v v v [dm core]
-------------------------------------------------------
| pdev pdev pdev [dm targets]
v ^ ^ ^
target----/---------/---------/
(void*)
taken-from: DragonFlyBSD
diffstat:
sys/dev/dm/dm.h | 17 +++++++---
sys/dev/dm/dm_ioctl.c | 38 +++++++++++++++++++++++-
sys/dev/dm/dm_table.c | 51 ++++++++++++++++++++++++++++++++-
sys/dev/dm/dm_target.c | 12 +------
sys/dev/dm/dm_target_error.c | 13 +-------
sys/dev/dm/dm_target_linear.c | 22 +------------
sys/dev/dm/dm_target_mirror.c | 14 +-------
sys/dev/dm/dm_target_snapshot.c | 62 +++-------------------------------------
sys/dev/dm/dm_target_stripe.c | 26 +---------------
sys/dev/dm/dm_target_zero.c | 13 +-------
10 files changed, 114 insertions(+), 154 deletions(-)
diffs (truncated from 678 to 300 lines):
diff -r b5a39fe612a7 -r 3bf3854fc299 sys/dev/dm/dm.h
--- a/sys/dev/dm/dm.h Sat Dec 21 11:54:04 2019 +0000
+++ b/sys/dev/dm/dm.h Sat Dec 21 11:59:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm.h,v 1.49 2019/12/20 16:16:36 tkusumi Exp $ */
+/* $NetBSD: dm.h,v 1.50 2019/12/21 11:59:03 tkusumi Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -65,6 +65,13 @@
extern const struct dkdriver dmdkdriver;
extern uint32_t dm_dev_counter;
+typedef struct dm_mapping {
+ union {
+ struct dm_pdev *pdev;
+ } data;
+ TAILQ_ENTRY(dm_mapping) next;
+} dm_mapping_t;
+
/*
* A device mapper table is a list of physical ranges plus the mapping target
* applied to them.
@@ -77,6 +84,8 @@
struct dm_target *target; /* Link to table target. */
void *target_config; /* Target specific data. */
SLIST_ENTRY(dm_table_entry) next;
+
+ TAILQ_HEAD(, dm_mapping) pdev_maps;
} dm_table_entry_t;
SLIST_HEAD(dm_table, dm_table_entry);
@@ -172,7 +181,6 @@
/* Destroy target_config area */
int (*destroy)(dm_table_entry_t *);
- int (*deps)(dm_table_entry_t *, prop_array_t);
/*
* Info/table routine are called to get params string, which is target
* specific. When dm_table_status_ioctl is called with flag
@@ -237,7 +245,6 @@
char *dm_target_linear_table(void *);
int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
int dm_target_linear_sync(dm_table_entry_t *);
-int dm_target_linear_deps(dm_table_entry_t *, prop_array_t);
int dm_target_linear_destroy(dm_table_entry_t *);
int dm_target_linear_upcall(dm_table_entry_t *, struct buf *);
int dm_target_linear_secsize(dm_table_entry_t *, unsigned int *);
@@ -247,7 +254,6 @@
char *dm_target_stripe_table(void *);
int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
int dm_target_stripe_sync(dm_table_entry_t *);
-int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t);
int dm_target_stripe_destroy(dm_table_entry_t *);
int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *);
int dm_target_stripe_secsize(dm_table_entry_t *, unsigned int *);
@@ -256,7 +262,6 @@
int dm_target_error_init(dm_table_entry_t*, int, char **);
char *dm_target_error_table(void *);
int dm_target_error_strategy(dm_table_entry_t *, struct buf *);
-int dm_target_error_deps(dm_table_entry_t *, prop_array_t);
int dm_target_error_destroy(dm_table_entry_t *);
int dm_target_error_upcall(dm_table_entry_t *, struct buf *);
@@ -265,7 +270,6 @@
char *dm_target_zero_table(void *);
int dm_target_zero_strategy(dm_table_entry_t *, struct buf *);
int dm_target_zero_destroy(dm_table_entry_t *);
-int dm_target_zero_deps(dm_table_entry_t *, prop_array_t);
int dm_target_zero_upcall(dm_table_entry_t *, struct buf *);
/* dm_table.c */
@@ -282,6 +286,7 @@
void dm_table_switch_tables(dm_table_head_t *);
void dm_table_head_init(dm_table_head_t *);
void dm_table_head_destroy(dm_table_head_t *);
+int dm_table_add_deps(dm_table_entry_t *, dm_pdev_t *);
/* dm_dev.c */
dm_dev_t* dm_dev_alloc(void);
diff -r b5a39fe612a7 -r 3bf3854fc299 sys/dev/dm/dm_ioctl.c
--- a/sys/dev/dm/dm_ioctl.c Sat Dec 21 11:54:04 2019 +0000
+++ b/sys/dev/dm/dm_ioctl.c Sat Dec 21 11:59:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_ioctl.c,v 1.47 2019/12/19 16:27:39 tkusumi Exp $ */
+/* $NetBSD: dm_ioctl.c,v 1.48 2019/12/21 11:59:03 tkusumi Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.47 2019/12/19 16:27:39 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.48 2019/12/21 11:59:03 tkusumi Exp $");
/*
* Locking is used to synchronise between ioctl calls and between dm_table's
@@ -116,6 +116,7 @@
prop_dictionary_set_uint32(dm_dict,DM_IOCTL_FLAGS,flag); \
} while (/*CONSTCOND*/0)
+static int dm_table_deps(dm_table_entry_t *, prop_array_t);
static int dm_table_init(dm_target_t *, dm_table_entry_t *, char *);
/*
@@ -644,7 +645,7 @@
tbl = dm_table_get_entry(&dmv->table_head, table_type);
SLIST_FOREACH(table_en, tbl, next)
- table_en->target->deps(table_en, cmd_array);
+ dm_table_deps(table_en, cmd_array);
dm_table_release(&dmv->table_head, table_type);
dm_dev_unbusy(dmv);
@@ -655,6 +656,36 @@
return 0;
}
+static int
+dm_table_deps(dm_table_entry_t *table_en, prop_array_t array)
+{
+ dm_mapping_t *map;
+ int i, size;
+ uint64_t rdev, tmp;
+
+ size = prop_array_count(array);
+
+ TAILQ_FOREACH(map, &table_en->pdev_maps, next) {
+ rdev = map->data.pdev->pdev_vnode->v_rdev;
+ for (i = 0; i < size; i++) {
+ if (prop_array_get_uint64(array, i, &tmp) == true)
+ if (rdev == tmp)
+ break; /* exists */
+ }
+ /*
+ * Ignore if the device has already been added by
+ * other tables.
+ */
+ if (i == size) {
+ prop_array_add_uint64(array, rdev);
+ aprint_debug("%s: %d:%d\n", __func__, major(rdev),
+ minor(rdev));
+ }
+ }
+
+ return 0;
+}
+
/*
* Load new table/tables to device.
* Call apropriate target init routine open all physical pdev's and
@@ -746,6 +777,7 @@
table_en->target = target;
table_en->dm_dev = dmv;
table_en->target_config = NULL;
+ TAILQ_INIT(&table_en->pdev_maps);
/*
* There is a parameter string after dm_target_spec
diff -r b5a39fe612a7 -r 3bf3854fc299 sys/dev/dm/dm_table.c
--- a/sys/dev/dm/dm_table.c Sat Dec 21 11:54:04 2019 +0000
+++ b/sys/dev/dm/dm_table.c Sat Dec 21 11:59:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_table.c,v 1.16 2019/12/15 14:39:42 tkusumi Exp $ */
+/* $NetBSD: dm_table.c,v 1.17 2019/12/21 11:59:03 tkusumi Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.16 2019/12/15 14:39:42 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.17 2019/12/21 11:59:03 tkusumi Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -54,6 +54,8 @@
static int dm_table_busy(dm_table_head_t *, uint8_t);
static void dm_table_unbusy(dm_table_head_t *);
+static void dm_table_free_deps(dm_table_entry_t *);
+
/*
* Function to increment table user reference counter. Return id
@@ -166,6 +168,7 @@
SLIST_REMOVE(tbl, table_en, dm_table_entry, next);
if (table_en->target->destroy(table_en) == 0)
table_en->target_config = NULL;
+ dm_table_free_deps(table_en);
kmem_free(table_en, sizeof(*table_en));
}
KASSERT(SLIST_EMPTY(tbl));
@@ -327,3 +330,47 @@
cv_destroy(&head->table_cv);
mutex_destroy(&head->table_mtx);
}
+
+int
+dm_table_add_deps(dm_table_entry_t *table_en, dm_pdev_t *pdev)
+{
+ dm_table_head_t *head;
+ dm_mapping_t *map;
+
+ if (!pdev)
+ return -1;
+
+ head = &table_en->dm_dev->table_head;
+ mutex_enter(&head->table_mtx);
+
+ TAILQ_FOREACH(map, &table_en->pdev_maps, next) {
+ if (map->data.pdev->pdev_vnode->v_rdev ==
+ pdev->pdev_vnode->v_rdev) {
+ mutex_exit(&head->table_mtx);
+ return -1;
+ }
+ }
+
+ map = kmem_alloc(sizeof(*map), KM_SLEEP);
+ map->data.pdev = pdev;
+ aprint_debug("%s: %s\n", __func__, pdev->name);
+ TAILQ_INSERT_TAIL(&table_en->pdev_maps, map, next);
+
+ mutex_exit(&head->table_mtx);
+
+ return 0;
+}
+
+/* caller must hold ->table_mtx */
+static void
+dm_table_free_deps(dm_table_entry_t *table_en)
+{
+ dm_mapping_t *map;
+
+ while ((map = TAILQ_FIRST(&table_en->pdev_maps)) != NULL) {
+ TAILQ_REMOVE(&table_en->pdev_maps, map, next);
+ aprint_debug("%s: %s\n", __func__, map->data.pdev->name);
+ kmem_free(map, sizeof(*map));
+ }
+ KASSERT(TAILQ_EMPTY(&table_en->pdev_maps));
+}
diff -r b5a39fe612a7 -r 3bf3854fc299 sys/dev/dm/dm_target.c
--- a/sys/dev/dm/dm_target.c Sat Dec 21 11:54:04 2019 +0000
+++ b/sys/dev/dm/dm_target.c Sat Dec 21 11:59:03 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dm_target.c,v 1.34 2019/12/19 15:34:54 tkusumi Exp $ */
+/* $NetBSD: dm_target.c,v 1.35 2019/12/21 11:59:03 tkusumi Exp $ */
/*
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.34 2019/12/19 15:34:54 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.35 2019/12/21 11:59:03 tkusumi Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -168,10 +168,6 @@
printf("%s missing strategy\n", dm_target->name);
return EINVAL;
}
- if (dm_target->deps == NULL) {
- printf("%s missing deps\n", dm_target->name);
- return EINVAL;
- }
if (dm_target->destroy == NULL) {
printf("%s missing destroy\n", dm_target->name);
return EINVAL;
@@ -324,7 +320,6 @@
dmt->table = &dm_target_linear_table;
dmt->strategy = &dm_target_linear_strategy;
dmt->sync = &dm_target_linear_sync;
- dmt->deps = &dm_target_linear_deps;
dmt->destroy = &dm_target_linear_destroy;
dmt->upcall = &dm_target_linear_upcall;
dmt->secsize = &dm_target_linear_secsize;
@@ -339,7 +334,6 @@
dmt->table = &dm_target_stripe_table;
dmt->strategy = &dm_target_stripe_strategy;
dmt->sync = &dm_target_stripe_sync;
- dmt->deps = &dm_target_stripe_deps;
dmt->destroy = &dm_target_stripe_destroy;
dmt->upcall = &dm_target_stripe_upcall;
dmt->secsize = &dm_target_stripe_secsize;
@@ -353,7 +347,6 @@
dmt->init = &dm_target_error_init;
dmt->table = &dm_target_error_table;
dmt->strategy = &dm_target_error_strategy;
- dmt->deps = &dm_target_error_deps;
dmt->destroy = &dm_target_error_destroy;
dmt->upcall = &dm_target_error_upcall;
if (dm_target_insert(dmt))
@@ -366,7 +359,6 @@
dmt->init = &dm_target_zero_init;
dmt->table = &dm_target_zero_table;
dmt->strategy = &dm_target_zero_strategy;
Home |
Main Index |
Thread Index |
Old Index