diff options
| author | tkusumi <tkusumi@NetBSD.org> | 2019-12-12 16:28:24 +0000 |
|---|---|---|
| committer | tkusumi <tkusumi@NetBSD.org> | 2019-12-12 16:28:24 +0000 |
| commit | f4d889641c2e4ce572c3d1bf01581cc30cb8e537 (patch) | |
| tree | 39c606b7b983b7019d1488f700e2382b023f2fad /sys/dev/dm/dm_ioctl.c | |
| parent | 1a169b36b03c3b7135058de274a8a107e2e98b83 (diff) | |
dm: Make target's ->init() take parsed argc and argv
This gets rid of the same parser code in each target using strsep(3).
taken-from: DragonFlyBSD
Diffstat (limited to 'sys/dev/dm/dm_ioctl.c')
| -rw-r--r-- | sys/dev/dm/dm_ioctl.c | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/sys/dev/dm/dm_ioctl.c b/sys/dev/dm/dm_ioctl.c index 90f9e4f6cbe..74a31c327cb 100644 --- a/sys/dev/dm/dm_ioctl.c +++ b/sys/dev/dm/dm_ioctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_ioctl.c,v 1.40 2019/12/08 04:41:02 tkusumi Exp $ */ +/* $NetBSD: dm_ioctl.c,v 1.41 2019/12/12 16:28:24 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.40 2019/12/08 04:41:02 tkusumi Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dm_ioctl.c,v 1.41 2019/12/12 16:28:24 tkusumi Exp $"); /* * Locking is used to synchronise between ioctl calls and between dm_table's @@ -118,6 +118,7 @@ static struct cfdata dm_cfdata = { } while (/*CONSTCOND*/0) static int dm_dbg_print_flags(int); +static int dm_table_init(dm_target_t *, dm_table_entry_t *, char *); /* * Print flags sent to the kernel from libevmapper. @@ -774,13 +775,7 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict) else SLIST_INSERT_AFTER(last_table, table_en, next); - /* - * Params string is different for every target, - * therfore I have to pass it to target init - * routine and parse parameters there. - */ - - if ((ret = target->init(table_en, str)) != 0) { + if ((ret = dm_table_init(target, table_en, str)) != 0) { dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE); dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE); free(str, M_TEMP); @@ -802,6 +797,41 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict) return 0; } +static int +dm_table_init(dm_target_t *target, dm_table_entry_t *table_en, char *params) +{ + int i, n, ret, argc; + char **ap, **argv; + + if (params == NULL) + return EINVAL; + + n = target->max_argc; + if (n) + aprint_debug("Max argc %d for %s target\n", n, target->name); + else + n = 32; /* large enough for most targets */ + + argv = kmem_alloc(sizeof(*argv) * n, KM_SLEEP); + + for (ap = argv; + ap < &argv[n] && (*ap = strsep(¶ms, " \t")) != NULL;) { + if (**ap != '\0') + ap++; + } + argc = ap - argv; + + for (i = 0; i < argc; i++) + aprint_debug("DM: argv[%d] = \"%s\"\n", i, argv[i]); + + KASSERT(target->init); + ret = target->init(table_en, argc, argv); + + kmem_free(argv, sizeof(*argv) * n); + + return ret; +} + /* * Get description of all tables loaded to device from kernel * and send it to libdevmapper. |
