diff mbox

[v6,1/4] ndctl: convert namespace actions to use util_filter_params

Message ID 152607028166.4523.7696454511543042282.stgit@djiang5-desk3.ch.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dave Jiang May 11, 2018, 8:24 p.m. UTC
In preparation of moving to using util_filter_walk, moving parts of
namespace params to util_filter_params.

Signed-off-by: Dave Jiang <dave.jiang@intel.com>
---
 ndctl/namespace.c |   41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

Comments

Ross Zwisler May 12, 2018, 1:46 a.m. UTC | #1
On Fri, May 11, 2018 at 01:24:41PM -0700, Dave Jiang wrote:
> In preparation of moving to using util_filter_walk, moving parts of
> namespace params to util_filter_params.
> 
> Signed-off-by: Dave Jiang <dave.jiang@intel.com>
> ---
>  ndctl/namespace.c |   41 ++++++++++++++++++++---------------------
>  1 file changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/ndctl/namespace.c b/ndctl/namespace.c
> index fe86d826..e61f500c 100644
> --- a/ndctl/namespace.c
> +++ b/ndctl/namespace.c
> @@ -40,14 +40,11 @@ static struct parameters {
>  	bool mode_default;
>  	bool align_default;
>  	bool autolabel;
> -	const char *bus;
>  	const char *map;
> -	const char *type;
>  	const char *uuid;
>  	const char *name;
>  	const char *size;
>  	const char *mode;

Why not use the 'mode' in uf_param as well?
diff mbox

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index fe86d826..e61f500c 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -40,14 +40,11 @@  static struct parameters {
 	bool mode_default;
 	bool align_default;
 	bool autolabel;
-	const char *bus;
 	const char *map;
-	const char *type;
 	const char *uuid;
 	const char *name;
 	const char *size;
 	const char *mode;
-	const char *region;
 	const char *reconfig;
 	const char *sector_size;
 	const char *align;
@@ -55,6 +52,8 @@  static struct parameters {
 	.autolabel = true,
 };
 
+struct util_filter_params uf_param;
+
 void builtin_xaction_namespace_reset(void)
 {
 	/*
@@ -87,9 +86,9 @@  struct parsed_parameters {
 	}})
 
 #define BASE_OPTIONS() \
-OPT_STRING('b', "bus", &param.bus, "bus-id", \
+OPT_STRING('b', "bus", &uf_param.bus, "bus-id", \
 	"limit namespace to a bus with an id or provider of <bus-id>"), \
-OPT_STRING('r', "region", &param.region, "region-id", \
+OPT_STRING('r', "region", &uf_param.region, "region-id", \
 	"limit namespace to a region with an id or name of <region-id>"), \
 OPT_BOOLEAN('v', "verbose", &verbose, "emit extra debug messages to stderr")
 
@@ -108,7 +107,7 @@  OPT_STRING('M', "map", &param.map, "memmap-location", \
 	"specify 'mem' or 'dev' for the location of the memmap"), \
 OPT_STRING('l', "sector-size", &param.sector_size, "lba-size", \
 	"specify the logical sector size in bytes"), \
-OPT_STRING('t', "type", &param.type, "type", \
+OPT_STRING('t', "type", &uf_param.type, "type", \
 	"specify the type of namespace to create 'pmem' or 'blk'"), \
 OPT_STRING('a', "align", &param.align, "align", \
 	"specify the namespace alignment in bytes (default: 2M)"), \
@@ -148,18 +147,18 @@  static int set_defaults(enum device_action mode)
 {
 	int rc = 0;
 
-	if (param.type) {
-		if (strcmp(param.type, "pmem") == 0)
+	if (uf_param.type) {
+		if (strcmp(uf_param.type, "pmem") == 0)
 			/* pass */;
-		else if (strcmp(param.type, "blk") == 0)
+		else if (strcmp(uf_param.type, "blk") == 0)
 			/* pass */;
 		else {
 			error("invalid type '%s', must be either 'pmem' or 'blk'\n",
-				param.type);
+				uf_param.type);
 			rc = -EINVAL;
 		}
 	} else if (!param.reconfig && mode == ACTION_CREATE)
-		param.type = "pmem";
+		uf_param.type = "pmem";
 
 	if (param.mode) {
 		if (strcmp(param.mode, "safe") == 0)
@@ -180,8 +179,8 @@  static int set_defaults(enum device_action mode)
 			error("invalid mode '%s'\n", param.mode);
 			rc = -EINVAL;
 		}
-	} else if (!param.reconfig && param.type) {
-		if (strcmp(param.type, "pmem") == 0)
+	} else if (!param.reconfig && uf_param.type) {
+		if (strcmp(uf_param.type, "pmem") == 0)
 			param.mode = "memory";
 		else
 			param.mode = "safe";
@@ -208,7 +207,7 @@  static int set_defaults(enum device_action mode)
 		param.map = "dev";
 
 	/* check for incompatible mode and type combinations */
-	if (param.type && param.mode && strcmp(param.type, "blk") == 0
+	if (uf_param.type && param.mode && strcmp(uf_param.type, "blk") == 0
 			&& (strcmp(param.mode, "memory") == 0
 				|| strcmp(param.mode, "dax") == 0)) {
 		error("only 'pmem' namespaces support dax operation\n");
@@ -244,7 +243,7 @@  static int set_defaults(enum device_action mode)
 			error("invalid sector size: %s\n", param.sector_size);
 			rc = -EINVAL;
 		}
-	} else if (((param.type && strcmp(param.type, "blk") == 0)
+	} else if (((uf_param.type && strcmp(uf_param.type, "blk") == 0)
 			|| (param.mode && strcmp(param.mode, "safe") == 0))) {
 		/* default sector size for blk-type or safe-mode */
 		param.sector_size = "4096";
@@ -1000,19 +999,19 @@  static int do_xaction_namespace(const char *namespace,
 		ndctl_set_log_priority(ctx, LOG_DEBUG);
 
         ndctl_bus_foreach(ctx, bus) {
-		if (!util_bus_filter(bus, param.bus))
+		if (!util_bus_filter(bus, uf_param.bus))
 			continue;
 
 		ndctl_region_foreach(bus, region) {
-			if (!util_region_filter(region, param.region))
+			if (!util_region_filter(region, uf_param.region))
 				continue;
 
-			if (param.type) {
-				if (strcmp(param.type, "pmem") == 0
+			if (uf_param.type) {
+				if (strcmp(uf_param.type, "pmem") == 0
 						&& ndctl_region_get_type(region)
 						== ND_DEVICE_REGION_PMEM)
 					/* pass */;
-				else if (strcmp(param.type, "blk") == 0
+				else if (strcmp(uf_param.type, "blk") == 0
 						&& ndctl_region_get_type(region)
 						== ND_DEVICE_REGION_BLK)
 					/* pass */;
@@ -1125,7 +1124,7 @@  int cmd_create_namespace(int argc, const char **argv, void *ctx)
 		 * fallback to blk before giving up.
 		 */
 		memset(&param, 0, sizeof(param));
-		param.type = "blk";
+		uf_param.type = "blk";
 		set_defaults(ACTION_CREATE);
 		created = do_xaction_namespace(NULL, ACTION_CREATE, ctx);
 	}