diff --git a/sys/dev/dm/dm.h b/sys/dev/dm/dm.h index 10c6598d3c4b..737caa300e86 100644 --- a/sys/dev/dm/dm.h +++ b/sys/dev/dm/dm.h @@ -1,4 +1,4 @@ -/* $NetBSD: dm.h,v 1.12 2009/03/25 23:35:54 dyoung Exp $ */ +/* $NetBSD: dm.h,v 1.13 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -51,7 +51,7 @@ #define DM_NAME_LEN 128 #define DM_UUID_LEN 129 -#define DM_VERSION_MAJOR 4 +#define DM_VERSION_MAJOR 5 #define DM_VERSION_MINOR 13 #define DM_VERSION_PATCHLEVEL 0 @@ -209,7 +209,7 @@ typedef struct target_snapshot_origin_config { typedef struct dm_target { char name[DM_MAX_TYPE_NAME]; /* Initialize target_config area */ - int (*init)(dm_dev_t *, void **, char *); + int (*init)(dm_dev_t *, void **, prop_dictionary_t); /* Destroy target_config area */ int (*destroy)(dm_table_entry_t *); @@ -278,8 +278,10 @@ void dm_target_busy(dm_target_t *); /* XXX temporally add */ int dm_target_init(void); +#define DM_MAX_PARAMS_SIZE 1024 + /* dm_target_zero.c */ -int dm_target_zero_init(dm_dev_t *, void**, char *); +int dm_target_zero_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_zero_status(void *); int dm_target_zero_strategy(dm_table_entry_t *, struct buf *); int dm_target_zero_destroy(dm_table_entry_t *); @@ -287,7 +289,7 @@ int dm_target_zero_deps(dm_table_entry_t *, prop_array_t); int dm_target_zero_upcall(dm_table_entry_t *, struct buf *); /* dm_target_error.c */ -int dm_target_error_init(dm_dev_t *, void**, char *); +int dm_target_error_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_error_status(void *); int dm_target_error_strategy(dm_table_entry_t *, struct buf *); int dm_target_error_deps(dm_table_entry_t *, prop_array_t); @@ -295,7 +297,7 @@ int dm_target_error_destroy(dm_table_entry_t *); int dm_target_error_upcall(dm_table_entry_t *, struct buf *); /* dm_target_linear.c */ -int dm_target_linear_init(dm_dev_t *, void**, char *); +int dm_target_linear_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_linear_status(void *); int dm_target_linear_strategy(dm_table_entry_t *, struct buf *); int dm_target_linear_deps(dm_table_entry_t *, prop_array_t); @@ -306,7 +308,7 @@ int dm_target_linear_upcall(dm_table_entry_t *, struct buf *); uint64_t atoi(const char *); /* dm_target_mirror.c */ -int dm_target_mirror_init(dm_dev_t *, void**, char *); +int dm_target_mirror_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_mirror_status(void *); int dm_target_mirror_strategy(dm_table_entry_t *, struct buf *); int dm_target_mirror_deps(dm_table_entry_t *, prop_array_t); @@ -314,7 +316,7 @@ int dm_target_mirror_destroy(dm_table_entry_t *); int dm_target_mirror_upcall(dm_table_entry_t *, struct buf *); /* dm_target_stripe.c */ -int dm_target_stripe_init(dm_dev_t *, void**, char *); +int dm_target_stripe_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_stripe_status(void *); int dm_target_stripe_strategy(dm_table_entry_t *, struct buf *); int dm_target_stripe_deps(dm_table_entry_t *, prop_array_t); @@ -322,7 +324,7 @@ int dm_target_stripe_destroy(dm_table_entry_t *); int dm_target_stripe_upcall(dm_table_entry_t *, struct buf *); /* dm_target_snapshot.c */ -int dm_target_snapshot_init(dm_dev_t *, void**, char *); +int dm_target_snapshot_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_snapshot_status(void *); int dm_target_snapshot_strategy(dm_table_entry_t *, struct buf *); int dm_target_snapshot_deps(dm_table_entry_t *, prop_array_t); @@ -330,7 +332,7 @@ int dm_target_snapshot_destroy(dm_table_entry_t *); int dm_target_snapshot_upcall(dm_table_entry_t *, struct buf *); /* dm snapshot origin driver */ -int dm_target_snapshot_orig_init(dm_dev_t *, void**, char *); +int dm_target_snapshot_orig_init(dm_dev_t *, void**, prop_dictionary_t); char * dm_target_snapshot_orig_status(void *); int dm_target_snapshot_orig_strategy(dm_table_entry_t *, struct buf *); int dm_target_snapshot_orig_deps(dm_table_entry_t *, prop_array_t); diff --git a/sys/dev/dm/dm_ioctl.c b/sys/dev/dm/dm_ioctl.c index 9dc84fe6fc37..03f1a91f6bd2 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.11 2009/04/13 18:51:54 haad Exp $ */ +/* $NetBSD: dm_ioctl.c,v 1.12 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -680,21 +680,18 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict) prop_object_iterator_t iter; prop_array_t cmd_array; - prop_dictionary_t target_dict; + prop_dictionary_t target_dict, param_dict; const char *name, *uuid, *type; uint32_t flags, ret, minor; - char *str; - ret = 0; flags = 0; name = NULL; uuid = NULL; dmv = NULL; last_table = NULL; - str = NULL; /* char *xml; xml = prop_dictionary_externalize(dm_dict); @@ -769,8 +766,7 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict) * null and therefore it should be checked before we try to * use it. */ - prop_dictionary_get_cstring(target_dict, - DM_TABLE_PARAMS, (char**)&str); + param_dict = prop_dictionary_get(target_dict, DM_TABLE_PARAMS); if (SLIST_EMPTY(tbl)) /* insert this table to head */ @@ -783,19 +779,16 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict) * therfore I have to pass it to target init * routine and parse parameters there. */ - if ((ret = target->init(dmv, &table_en->target_config, - str)) != 0) { + param_dict)) != 0) { dm_table_release(&dmv->table_head, DM_TABLE_INACTIVE); dm_table_destroy(&dmv->table_head, DM_TABLE_INACTIVE); - free(str, M_TEMP); - + dm_dev_unbusy(dmv); return ret; } last_table = table_en; - free(str, M_TEMP); } prop_object_iterator_release(iter); diff --git a/sys/dev/dm/dm_target_error.c b/sys/dev/dm/dm_target_error.c index ce5b4def93bc..a6ab9bfc023b 100644 --- a/sys/dev/dm/dm_target_error.c +++ b/sys/dev/dm/dm_target_error.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_error.c,v 1.7 2009/02/19 23:07:33 haad Exp $ */ +/* $NetBSD: dm_target_error.c,v 1.8 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -100,7 +100,7 @@ dm_target_error_modcmd(modcmd_t cmd, void *arg) /* Init function called from dm_table_load_ioctl. */ int -dm_target_error_init(dm_dev_t *dmv, void **target_config, char *argv) +dm_target_error_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { printf("Error target init function called!!\n"); diff --git a/sys/dev/dm/dm_target_linear.c b/sys/dev/dm/dm_target_linear.c index fa4520e2e12d..72732ffab502 100644 --- a/sys/dev/dm/dm_target_linear.c +++ b/sys/dev/dm/dm_target_linear.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_linear.c,v 1.4 2009/03/01 23:17:39 haad Exp $ */ +/* $NetBSD: dm_target_linear.c,v 1.5 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -43,6 +43,7 @@ #include +#include "netbsd-dm.h" #include "dm.h" /* @@ -54,32 +55,28 @@ * @argv[1] is physical data offset. */ int -dm_target_linear_init(dm_dev_t *dmv, void **target_config, char *params) +dm_target_linear_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { dm_target_linear_config_t *tlc; dm_pdev_t *dmp; - char **ap, *argv[3]; - - if(params == NULL) - return EINVAL; + const char *device; + uint64_t offset; - /* - * Parse a string, containing tokens delimited by white space, - * into an argument vector - */ - for (ap = argv; ap < &argv[2] && - (*ap = strsep(¶ms, " \t")) != NULL;) { - if (**ap != '\0') - ap++; - } + if (prop_dictionary_get_cstring_nocopy(dict, DM_TARGET_LINEAR_DEVICE, + &device) == false) + return EINVAL; + + if (prop_dictionary_get_uint64(dict, DM_TARGET_LINEAR_OFFSET, + &offset) == false) + return EINVAL; /* Insert dmp to global pdev list */ - if ((dmp = dm_pdev_insert(argv[0])) == NULL) + if ((dmp = dm_pdev_insert(device)) == NULL) return ENOENT; - aprint_debug("Linear target init function called %s--%s!!\n", - argv[0], argv[1]); + aprint_debug("Linear target init function called %s--%"PRIu64"!!\n", + device, offset); if ((tlc = kmem_alloc(sizeof(dm_target_linear_config_t), KM_NOSLEEP)) == NULL) @@ -89,7 +86,7 @@ dm_target_linear_init(dm_dev_t *dmv, void **target_config, char *params) tlc->offset = 0; /* default settings */ /* Check user input if it is not leave offset as 0. */ - tlc->offset = atoi(argv[1]); + tlc->offset = offset; *target_config = tlc; @@ -108,28 +105,16 @@ dm_target_linear_status(void *target_config) { dm_target_linear_config_t *tlc; char *params; - uint32_t i; - uint32_t count; - size_t prm_len; - tlc = target_config; - prm_len = 0; - count = 0; - - /* count number of chars in offset */ - for(i = tlc->offset; i != 0; i /= 10) - count++; - + aprint_debug("Linear target status function called\n"); - /* length of name + count of chars + one space and null char */ - prm_len = strlen(tlc->pdev->name) + count + 2; - - if ((params = kmem_alloc(prm_len, KM_NOSLEEP)) == NULL) + if ((params = kmem_alloc(DM_MAX_PARAMS_SIZE, KM_NOSLEEP)) == NULL) return NULL; - aprint_debug("%s %"PRIu64, tlc->pdev->name, tlc->offset); - snprintf(params, prm_len,"%s %"PRIu64, tlc->pdev->name, tlc->offset); + aprint_normal("%s %"PRIu64, tlc->pdev->name, tlc->offset); + snprintf(params, DM_MAX_PARAMS_SIZE,"%s %"PRIu64, + tlc->pdev->name, tlc->offset); return params; } diff --git a/sys/dev/dm/dm_target_mirror.c b/sys/dev/dm/dm_target_mirror.c index 9ef02df06810..9f1a17e94046 100644 --- a/sys/dev/dm/dm_target_mirror.c +++ b/sys/dev/dm/dm_target_mirror.c @@ -1,4 +1,4 @@ -/*$NetBSD: dm_target_mirror.c,v 1.5 2009/03/01 23:16:51 haad Exp $*/ +/*$NetBSD: dm_target_mirror.c,v 1.6 2009/06/05 19:56:40 haad Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -104,7 +104,7 @@ dm_target_mirror_modcmd(modcmd_t cmd, void *arg) * 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_dev_t *dmv, void **target_config, char *argv) +dm_target_mirror_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { printf("Mirror target init function called!!\n"); diff --git a/sys/dev/dm/dm_target_snapshot.c b/sys/dev/dm/dm_target_snapshot.c index e682265f45c6..b2afcb4e4c16 100644 --- a/sys/dev/dm/dm_target_snapshot.c +++ b/sys/dev/dm/dm_target_snapshot.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_snapshot.c,v 1.8 2009/02/19 23:07:33 haad Exp $ */ +/* $NetBSD: dm_target_snapshot.c,v 1.9 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -178,7 +178,7 @@ dm_target_snapshot_modcmd(modcmd_t cmd, void *arg) * snapshot_origin device, cow device, persistent flag, chunk size */ int -dm_target_snapshot_init(dm_dev_t *dmv, void **target_config, char *params) +dm_target_snapshot_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { dm_target_snapshot_config_t *tsc; dm_pdev_t *dmp_snap, *dmp_cow; diff --git a/sys/dev/dm/dm_target_stripe.c b/sys/dev/dm/dm_target_stripe.c index 0570af327a2c..e44df8b2b7a7 100644 --- a/sys/dev/dm/dm_target_stripe.c +++ b/sys/dev/dm/dm_target_stripe.c @@ -1,4 +1,4 @@ -/*$NetBSD: dm_target_stripe.c,v 1.5 2009/04/06 22:48:26 haad Exp $*/ +/*$NetBSD: dm_target_stripe.c,v 1.6 2009/06/05 19:56:40 haad Exp $*/ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -40,6 +40,7 @@ #include #include "dm.h" +#include "netbsd-dm.h" #ifdef DM_TARGET_MODULE /* @@ -108,34 +109,44 @@ dm_target_stripe_modcmd(modcmd_t cmd, void *arg) * 0 65536 striped 2 512 /dev/hda 0 /dev/hdb 0 */ int -dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params) +dm_target_stripe_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { dm_target_stripe_config_t *tsc; - size_t len; - char **ap, *argv[10]; - - if(params == NULL) + prop_array_t dev_array; + prop_dictionary_t dev_dict1, dev_dict2; + + uint64_t stripes, chunk_size, offset1, offset2; + const char *device1, *device2; + + if (prop_dictionary_get_uint64(dict, DM_TARGET_STRIPE_STRIPES, + &stripes) == false) return EINVAL; - - len = strlen(params) + 1; - /* - * Parse a string, containing tokens delimited by white space, - * into an argument vector - */ - for (ap = argv; ap < &argv[9] && - (*ap = strsep(¶ms, " \t")) != NULL;) { - if (**ap != '\0') - ap++; - } + if (prop_dictionary_get_uint64(dict, DM_TARGET_STRIPE_CHUNKSIZE, + &chunk_size) == false) + return EINVAL; + + dev_array = prop_dictionary_get(dict, DM_TARGET_STRIPE_DEVARRAY); - printf("Stripe target init function called!!\n"); + /* XXX Support for more than 2 devices */ + dev_dict1 = prop_array_get(dev_array, 0); + dev_dict2 = prop_array_get(dev_array, 1); - printf("Stripe target chunk size %s number of stripes %s\n", argv[1], argv[0]); - printf("Stripe target device name %s -- offset %s\n", argv[2], argv[3]); - printf("Stripe target device name %s -- offset %s\n", argv[4], argv[5]); + if(dev_dict2 == NULL || dev_dict1 == NULL) + return EINVAL; + + prop_dictionary_get_cstring_nocopy(dev_dict1, DM_TARGET_STRIPE_DEVICE, &device1); + prop_dictionary_get_uint64(dev_dict1, DM_TARGET_STRIPE_OFFSET, &offset1); + prop_dictionary_get_cstring_nocopy(dev_dict2, DM_TARGET_STRIPE_DEVICE, &device2); + prop_dictionary_get_uint64(dev_dict2, DM_TARGET_STRIPE_OFFSET, &offset2); - if (atoi(argv[0]) > MAX_STRIPES) + aprint_debug("Stripe target init function called!!\n"); + + aprint_debug("Stripe target chunk size %"PRIu64" number of stripes %"PRIu64"\n", chunk_size, stripes); + aprint_debug("Stripe target device name %s -- offset %"PRIu64"\n", device1, offset1); + aprint_debug("Stripe target device name %s -- offset %"PRIu64"\n", device2, offset2); + + if (stripes > MAX_STRIPES) return ENOTSUP; if ((tsc = kmem_alloc(sizeof(dm_target_stripe_config_t), KM_NOSLEEP)) @@ -143,20 +154,20 @@ dm_target_stripe_init(dm_dev_t *dmv, void **target_config, char *params) return ENOMEM; /* Insert dmp to global pdev list */ - if ((tsc->stripe_devs[0].pdev = dm_pdev_insert(argv[2])) == NULL) + if ((tsc->stripe_devs[0].pdev = dm_pdev_insert(device1)) == NULL) return ENOENT; /* Insert dmp to global pdev list */ - if ((tsc->stripe_devs[1].pdev = dm_pdev_insert(argv[4])) == NULL) + if ((tsc->stripe_devs[1].pdev = dm_pdev_insert(device2)) == NULL) return ENOENT; - tsc->stripe_devs[0].offset = atoi(argv[3]); - tsc->stripe_devs[1].offset = atoi(argv[5]); + tsc->stripe_devs[0].offset = offset1; + tsc->stripe_devs[1].offset = offset2; /* Save length of param string */ - tsc->params_len = len; - tsc->stripe_chunksize = atoi(argv[1]); - tsc->stripe_num = (uint8_t)atoi(argv[0]); + tsc->params_len = DM_MAX_PARAMS_SIZE; + tsc->stripe_chunksize = chunk_size; + tsc->stripe_num = (uint8_t)stripes; *target_config = tsc; @@ -200,7 +211,7 @@ dm_target_stripe_strategy(dm_table_entry_t *table_en, struct buf *bp) if (tsc == NULL) return 0; -/* printf("Stripe target read function called %" PRIu64 "!!\n", +/* aprint_debug("Stripe target read function called %" PRIu64 "!!\n", tlc->offset);*/ /* calculate extent of request */ diff --git a/sys/dev/dm/dm_target_zero.c b/sys/dev/dm/dm_target_zero.c index 0011bfd0370e..cd383ba6a6af 100644 --- a/sys/dev/dm/dm_target_zero.c +++ b/sys/dev/dm/dm_target_zero.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm_target_zero.c,v 1.7 2009/02/19 23:07:33 haad Exp $ */ +/* $NetBSD: dm_target_zero.c,v 1.8 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -104,7 +104,7 @@ dm_target_zero_modcmd(modcmd_t cmd, void *arg) * target specific config area. */ int -dm_target_zero_init(dm_dev_t *dmv, void **target_config, char *argv) +dm_target_zero_init(dm_dev_t *dmv, void **target_config, prop_dictionary_t dict) { printf("Zero target init function called!!\n"); diff --git a/sys/dev/dm/netbsd-dm.h b/sys/dev/dm/netbsd-dm.h index 61c13e6f3f5f..4322d3d55e7c 100644 --- a/sys/dev/dm/netbsd-dm.h +++ b/sys/dev/dm/netbsd-dm.h @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd-dm.h,v 1.3 2008/12/22 02:20:04 haad Exp $ */ +/* $NetBSD: netbsd-dm.h,v 1.4 2009/06/05 19:56:40 haad Exp $ */ /* * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -208,6 +208,17 @@ #define DM_TABLE_STAT "status" #define DM_TABLE_LENGTH "length" #define DM_TABLE_PARAMS "params" + +#define DM_TARGET_LINEAR_DEVICE "device" +#define DM_TARGET_LINEAR_OFFSET "offset" + +#define DM_TARGET_STRIPE_DEVARRAY "device_array" +#define DM_TARGET_STRIPE_DEVICE "device" +#define DM_TARGET_STRIPE_OFFSET "offset" +#define DM_TARGET_STRIPE_STRIPES "stripes" +#define DM_TARGET_STRIPE_CHUNKSIZE "chunk_size" + + //#ifndef __LIB_DEVMAPPER__ //#define DM_TABLE_DEPS "deps" //#endif @@ -266,7 +277,7 @@ /* Types for nbsd_get_dm_major */ #define DM_CHAR_MAJOR 1 -#define DM_BLOCK_MAJOR 2 +#define DM_BLOCK_MAJOR 2 /* libdm_netbsd.c */ int nbsd_get_dm_major(uint32_t *, int); /* Get dm device major numbers */ @@ -276,6 +287,8 @@ int nbsd_dmi_add_version(const int [3], prop_dictionary_t); int nbsd_dm_add_uint(const char *, uint64_t, prop_dictionary_t); int nbsd_dm_add_str(const char *, char *, prop_dictionary_t ); +prop_dictionary_t nbsd_dm_parse_param(const char *, char *); + struct dm_ioctl* nbsd_dm_dict_to_dmi(prop_dictionary_t, const int); #endif /* __LIB_DEVMAPPER__ */