daxctl: Change region input type from INTEGER to STRING.
PATCH 1/1 daxctl: Change region input type from INTEGER to STRING.
Allow daxctl to accept both <region-id>, and region name as region parameter. For example:
daxctl list -r region5
daxctl list -r 5
Signed-off-by Redhairer Li <[email protected]>
--- daxctl/device.c | 11 ++++------- daxctl/list.c | 14 ++++++-------- util/filter.c | 16 ++++++++++++++++ util/filter.h | 2 ++ 4 files changed, 28 insertions(+), 15 deletions(-)
daxctl/device.c +4 -7
@@ -19,15 +19,13 @@static struct {const char *dev;const char *mode; -int region_id; +const char *region;bool no_online;bool no_movable;bool force;bool human;bool verbose; -} param = { - .region_id =-1 , -}; +} param;enum dev_mode {DAXCTL_DEV_MODE_UNKNOWN ,
@@ -51,7 +49,7 @@ enum device_action { };#define BASE_OPTIONS () \ -OPT_INTEGER('r', "region", ¶m.region_id, "restrict to the given region"), \ +OPT_STRING('r', "region", ¶m.region, "region-id", "filter by region"), \ OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats"), \ OPT_BOOLEAN('v', "verbose", ¶m.verbose, "emit more debug messages")
@@ -484,8 +482,7 @@ static int do_xaction_device(const char *device, enum device_action action, *processed =0 ; daxctl_region_foreach(ctx, region) { -if (param.region_id >=0 && param.region_id - !=daxctl_region_get_id (region)) +if (!util_daxctl_region_filter (region, param.region))continue ; daxctl_dev_foreach(region, dev) {
daxctl/list.c +6 -8
@@ -44,10 +44,8 @@ static unsigned long listopts_to_flags(void)static struct {const char *dev; -int region_id; -} param = { - .region_id =-1 , -}; +const char *region; +} param;static int did_fail;
@@ -66,7 +64,8 @@ static int num_list_flags(void)int cmd_list (int argc,const char **argv,struct daxctl_ctx *ctx) {const struct option options[] = { -OPT_INTEGER ('r' ,"region" , ¶m.region_id,"filter by region" ), +OPT_STRING ('r' ,"region" , ¶m.region,"region-id" , +"filter by region" ),OPT_STRING ('d' ,"dev" , ¶m.dev,"dev-id" ,"filter by dax device instance name" ),OPT_BOOLEAN ('D' ,"devices" , &list.devs,"include dax device info" ),
@@ -94,7 +93,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx)usage_with_options (u, options);if (num_list_flags () ==0 ) { - list.regions = param.region_id >=0 ; + list.regions = !!param.region; list.devs = !!param.dev; }
@@ -106,8 +105,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx) daxctl_region_foreach(ctx, region) {struct json_object *jregion =NULL ; -if (param.region_id >=0 && param.region_id - !=daxctl_region_get_id (region)) +if (!util_daxctl_region_filter (region, param.region))continue ;if (list.regions) {
util/filter.c +16 -0
@@ -335,6 +335,22 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,return NULL ; } +struct daxctl_region *util_daxctl_region_filter (struct daxctl_region *region, +const char *ident) +{ +int region_id; + +if (!ident ||strcmp (ident,"all" ) ==0 ) +return region; + +if ((sscanf (ident,"%d" , ®ion_id) ==1 + ||sscanf (ident,"region%d" , ®ion_id) ==1 ) + &&daxctl_region_get_id (region) == region_id) +return region; + +return NULL ; +} +static enum ndctl_namespace_mode mode_to_type (const char *mode) {if (!mode)
util/filter.h +2 -0
@@ -37,6 +37,8 @@ struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region const char *ident);struct daxctl_dev *util_daxctl_dev_filter (struct daxctl_dev *dev,const char *ident); +struct daxctl_region *util_daxctl_region_filter (struct daxctl_region *region, +const char *ident);struct json_object ;
Signature · 4 lines
2.20.1.windows.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Quoted 9 lines · redhairer
Allow daxctl to accept both <region-id>, and region name as region parameter. For example:
daxctl list -r region5
daxctl list -r 5Signed-off-by Redhairer Li <[email protected]>
Looks good, applied.
Quoted 134 lines
daxctl/device.c | 11 ++++------- daxctl/list.c | 14 ++++++-------- util/filter.c | 16 ++++++++++++++++ util/filter.h | 2 ++ 4 files changed, 28 insertions(+), 15 deletions(-)daxctl/device.c +4
-7@@ -19,15 +19,13 @@static struct {const char *dev;const char *mode; -int region_id; +const char *region;bool no_online;bool no_movable;bool force;bool human;bool verbose; -} param = { - .region_id =-1 , -}; +} param;enum dev_mode {DAXCTL_DEV_MODE_UNKNOWN ,@@ -51,7 +49,7 @@ enum device_action { };#define BASE_OPTIONS () \ -OPT_INTEGER('r', "region", ¶m.region_id, "restrict to the given region"), \ +OPT_STRING('r', "region", ¶m.region, "region-id", "filter by region"), \ OPT_BOOLEAN('u', "human", ¶m.human, "use human friendly number formats"), \ OPT_BOOLEAN('v', "verbose", ¶m.verbose, "emit more debug messages")@@ -484,8 +482,7 @@ static int do_xaction_device(const char *device, enum device_action action, *processed =0 ; daxctl_region_foreach(ctx, region) { -if (param.region_id >=0 && param.region_id - !=daxctl_region_get_id (region)) +if (!util_daxctl_region_filter (region, param.region))continue ; daxctl_dev_foreach(region, dev) {daxctl/list.c +6
-8@@ -44,10 +44,8 @@ static unsigned long listopts_to_flags(void)static struct {const char *dev; -int region_id; -} param = { - .region_id =-1 , -}; +const char *region; +} param;static int did_fail;@@ -66,7 +64,8 @@ static int num_list_flags(void)int cmd_list (int argc,const char **argv,struct daxctl_ctx *ctx) {const struct option options[] = { -OPT_INTEGER ('r' ,"region" , ¶m.region_id,"filter by region" ), +OPT_STRING ('r' ,"region" , ¶m.region,"region-id" , +"filter by region" ),OPT_STRING ('d' ,"dev" , ¶m.dev,"dev-id" ,"filter by dax device instance name" ),OPT_BOOLEAN ('D' ,"devices" , &list.devs,"include dax device info" ),@@ -94,7 +93,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx)usage_with_options (u, options);if (num_list_flags () ==0 ) { - list.regions = param.region_id >=0 ; + list.regions = !!param.region; list.devs = !!param.dev; }@@ -106,8 +105,7 @@ int cmd_list(int argc, const char **argv, struct daxctl_ctx *ctx) daxctl_region_foreach(ctx, region) {struct json_object *jregion =NULL ; -if (param.region_id >=0 && param.region_id - !=daxctl_region_get_id (region)) +if (!util_daxctl_region_filter (region, param.region))continue ;if (list.regions) {util/filter.c +16
-0@@ -335,6 +335,22 @@ struct daxctl_dev *util_daxctl_dev_filter(struct daxctl_dev *dev,return NULL ; } +struct daxctl_region *util_daxctl_region_filter (struct daxctl_region *region, +const char *ident) +{ +int region_id; + +if (!ident ||strcmp (ident,"all" ) ==0 ) +return region; + +if ((sscanf (ident,"%d" , ®ion_id) ==1 + ||sscanf (ident,"region%d" , ®ion_id) ==1 ) + &&daxctl_region_get_id (region) == region_id) +return region; + +return NULL ; +} +static enum ndctl_namespace_mode mode_to_type (const char *mode) {if (!mode)util/filter.h +2
-1@@ -37,6 +37,8 @@ struct ndctl_region *util_region_filter_by_namespace(struct ndctl_region *region const char *ident);struct daxctl_dev *util_daxctl_dev_filter (struct daxctl_dev *dev,const char *ident); +struct daxctl_region *util_daxctl_region_filter (struct daxctl_region *region, +const char *ident);struct json_object ; --
Quoted 2 lines
2.20.1.windows.1
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]