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: Make target's ->init() take parsed argc and argv



details:   https://anonhg.NetBSD.org/src/rev/01d97cd680c5
branches:  trunk
changeset: 967514:01d97cd680c5
user:      tkusumi <tkusumi%NetBSD.org@localhost>
date:      Thu Dec 12 16:28:24 2019 +0000

description:
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:

 sys/dev/dm/dm.h                 |   9 ++++---
 sys/dev/dm/dm_ioctl.c           |  48 +++++++++++++++++++++++++++++++++-------
 sys/dev/dm/dm_target_error.c    |   8 +++---
 sys/dev/dm/dm_target_linear.c   |  22 +++++------------
 sys/dev/dm/dm_target_mirror.c   |   8 +++---
 sys/dev/dm/dm_target_snapshot.c |  32 ++++++--------------------
 sys/dev/dm/dm_target_stripe.c   |  27 +++++-----------------
 sys/dev/dm/dm_target_zero.c     |   8 +++---
 8 files changed, 78 insertions(+), 84 deletions(-)

diffs (truncated from 442 to 300 lines):

diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm.h
--- a/sys/dev/dm/dm.h   Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm.h   Thu Dec 12 16:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm.h,v 1.38 2019/12/08 14:59:42 tkusumi Exp $      */
+/*        $NetBSD: dm.h,v 1.39 2019/12/12 16:28:24 tkusumi Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -174,7 +174,7 @@
 typedef struct dm_target {
        char name[DM_MAX_TYPE_NAME];
        /* Initialize target_config area */
-       int (*init)(dm_table_entry_t *, char *);
+       int (*init)(dm_table_entry_t *, int, char **);
 
        /* Destroy target_config area */
        int (*destroy)(dm_table_entry_t *);
@@ -193,6 +193,7 @@
 
        uint32_t version[3];
        uint32_t ref_cnt;
+       int max_argc;
 
        TAILQ_ENTRY(dm_target) dm_target_next;
 } dm_target_t;
@@ -236,7 +237,7 @@
 #define DM_MAX_PARAMS_SIZE 1024
 
 /* dm_target_linear.c */
-int dm_target_linear_init(dm_table_entry_t *, char *);
+int dm_target_linear_init(dm_table_entry_t *, int, char **);
 char *dm_target_linear_status(void *);
 int dm_target_linear_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_linear_sync(dm_table_entry_t *);
@@ -249,7 +250,7 @@
 uint64_t atoi(const char *);
 
 /* dm_target_stripe.c */
-int dm_target_stripe_init(dm_table_entry_t *, char *);
+int dm_target_stripe_init(dm_table_entry_t *, int, char **);
 char *dm_target_stripe_status(void *);
 int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_stripe_sync(dm_table_entry_t *);
diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm_ioctl.c
--- a/sys/dev/dm/dm_ioctl.c     Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm_ioctl.c     Thu Dec 12 16:28:24 2019 +0000
@@ -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 @@
 } 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 @@
                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 @@
        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(&params, " \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.
diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm_target_error.c
--- a/sys/dev/dm/dm_target_error.c      Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm_target_error.c      Thu Dec 12 16:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_error.c,v 1.18 2019/12/08 14:59:42 tkusumi Exp $      */
+/*        $NetBSD: dm_target_error.c,v 1.19 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_target_error.c,v 1.18 2019/12/08 14:59:42 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target_error.c,v 1.19 2019/12/12 16:28:24 tkusumi Exp $");
 
 /*
  * This file implements initial version of device-mapper error target.
@@ -42,7 +42,7 @@
 #include "dm.h"
 
 /* dm_target_error.c */
-int dm_target_error_init(dm_table_entry_t*, char *);
+int dm_target_error_init(dm_table_entry_t*, int, char **);
 char *dm_target_error_status(void *);
 int dm_target_error_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_error_sync(dm_table_entry_t *);
@@ -111,7 +111,7 @@
 
 /* Init function called from dm_table_load_ioctl. */
 int
-dm_target_error_init(dm_table_entry_t *table_en, char *params)
+dm_target_error_init(dm_table_entry_t *table_en, int argc, char **argv)
 {
 
        printf("Error target init function called!!\n");
diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm_target_linear.c
--- a/sys/dev/dm/dm_target_linear.c     Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm_target_linear.c     Thu Dec 12 16:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_linear.c,v 1.26 2019/12/09 16:06:19 tkusumi Exp $      */
+/*        $NetBSD: dm_target_linear.c,v 1.27 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_target_linear.c,v 1.26 2019/12/09 16:06:19 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target_linear.c,v 1.27 2019/12/12 16:28:24 tkusumi Exp $");
 
 /*
  * This file implements initial version of device-mapper dklinear target.
@@ -55,25 +55,17 @@
  * @argv[1] is physical data offset.
  */
 int
-dm_target_linear_init(dm_table_entry_t *table_en, char *params)
+dm_target_linear_init(dm_table_entry_t *table_en, int argc, char **argv)
 {
        dm_target_linear_config_t *tlc;
        dm_pdev_t *dmp;
 
-       char **ap, *argv[3];
-
-       if (params == NULL)
+       /*
+       if (argc != 2) {
+               printf("Linear target takes 2 args\n");
                return EINVAL;
-
-       /*
-        * Parse a string, containing tokens delimited by white space,
-        * into an argument vector
-        */
-       for (ap = argv; ap < &argv[2] &&
-           (*ap = strsep(&params, " \t")) != NULL;) {
-               if (**ap != '\0')
-                       ap++;
        }
+       */
 
        aprint_debug("Linear target init function called %s--%s!!\n",
            argv[0], argv[1]);
diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm_target_mirror.c
--- a/sys/dev/dm/dm_target_mirror.c     Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm_target_mirror.c     Thu Dec 12 16:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/*$NetBSD: dm_target_mirror.c,v 1.17 2019/12/08 14:59:42 tkusumi Exp $*/
+/*$NetBSD: dm_target_mirror.c,v 1.18 2019/12/12 16:28:24 tkusumi Exp $*/
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.17 2019/12/08 14:59:42 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target_mirror.c,v 1.18 2019/12/12 16:28:24 tkusumi Exp $");
 
 /*
  * This file implements initial version of device-mapper mirror target.
@@ -42,7 +42,7 @@
 #include "dm.h"
 
 /* dm_target_mirror.c */
-int dm_target_mirror_init(dm_table_entry_t *, char *);
+int dm_target_mirror_init(dm_table_entry_t *, int, char **);
 char *dm_target_mirror_status(void *);
 int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_mirror_sync(dm_table_entry_t *);
@@ -127,7 +127,7 @@
  * 0 52428800 mirror clustered_disk 4 253:2 1024 UUID block_on_error 3 253:3 0 253:4 0 253:5 0
  */
 int
-dm_target_mirror_init(dm_table_entry_t *table_en, char *params)
+dm_target_mirror_init(dm_table_entry_t *table_en, int argc, char **argv)
 {
 
        printf("Mirror target init function called!!\n");
diff -r f4b5db2e6e8f -r 01d97cd680c5 sys/dev/dm/dm_target_snapshot.c
--- a/sys/dev/dm/dm_target_snapshot.c   Thu Dec 12 12:35:43 2019 +0000
+++ b/sys/dev/dm/dm_target_snapshot.c   Thu Dec 12 16:28:24 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target_snapshot.c,v 1.29 2019/12/08 14:59:42 tkusumi Exp $      */
+/*        $NetBSD: dm_target_snapshot.c,v 1.30 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_target_snapshot.c,v 1.29 2019/12/08 14:59:42 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target_snapshot.c,v 1.30 2019/12/12 16:28:24 tkusumi Exp $");
 
 /*
  * 1. Suspend my_data to temporarily stop any I/O while the snapshot is being
@@ -87,7 +87,7 @@
 #include "dm.h"
 
 /* dm_target_snapshot.c */
-int dm_target_snapshot_init(dm_table_entry_t *, char *);
+int dm_target_snapshot_init(dm_table_entry_t *, int, char **);
 char *dm_target_snapshot_status(void *);
 int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_snapshot_sync(dm_table_entry_t *);
@@ -96,7 +96,7 @@
 int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *);
 
 /* dm snapshot origin driver */
-int dm_target_snapshot_orig_init(dm_table_entry_t *, char *);
+int dm_target_snapshot_orig_init(dm_table_entry_t *, int, char **);
 char *dm_target_snapshot_orig_status(void *);
 int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *);
 int dm_target_snapshot_orig_sync(dm_table_entry_t *);
@@ -210,26 +210,13 @@
  *        snapshot_origin device, cow device, persistent flag, chunk size
  */
 int
-dm_target_snapshot_init(dm_table_entry_t *table_en, char *params)
+dm_target_snapshot_init(dm_table_entry_t *table_en, int argc, char **argv)
 {
        dm_target_snapshot_config_t *tsc;
        dm_pdev_t *dmp_snap, *dmp_cow;
-       char **ap, *argv[5];
 
        dmp_cow = NULL;
 
-       if (params == NULL)
-               return EINVAL;
-       /*



Home | Main Index | Thread Index | Old Index