ndctl: change ndctl to support multiple arguments per option
cover ndctl: change ndctl to support multiple arguments per option
This patch set is to support multiple arguments per option of ndctl. Currently, ndctl supports only one argument per option, and only one dimm can be filtered by dimm's name. As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature can let monitor support filter multiple dimms by dimms' name in one process. Also applied in ndctl list:
# ndclt list --dimm="nmem0 nmem1 nmem2"
[
{
"dev":"nmem1",
"id":"cdab-0a-07e0-feffffff",
"handle":1,
"phys_id":1
},
{
"dev":"nmem0",
"id":"cdab-0a-07e0-ffffffff",
"handle":0,
"phys_id":0
},
{
"dev":"nmem2",
"id":"cdab-0a-07e0-fffeffff",
"handle":256,
"phys_id":2
}
]QI Fuli (2):
ndctl, util: add OPT_STRING_LIST to parse_option
ndctl, list: change -b -d -r -n options to support multiple arguments
ccan/list/list.h | 6 ++++ ndctl/list.c | 35 ++++++++++++++----- util/filter.c | 81 +++++++++++++++++++++++++++++++------------- util/filter.h | 9 ++--- util/parse-options.c | 25 ++++++++++++++ util/parse-options.h | 3 ++ 6 files changed, 122 insertions(+), 37 deletions(-)
Signature · 7 lines
2.17.0.140.g0b0cc9f86 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 1/2 ndctl, util: add OPT_STRING_LIST to parse_option
This patch adds OPT_STRING_LIST to parse_option in order to support multiple space seperated string objects in one option.
--- ccan/list/list.h | 6 ++++++ util/parse-options.c | 25 +++++++++++++++++++++++++ util/parse-options.h | 3 +++ 3 files changed, 34 insertions(+)
ccan/list/list.h +6 -0
@@ -26,6 +26,12 @@ struct list_nodestruct list_node *next, *prev; }; +struct string_list_node +{ +char *str; +struct list_node list; +}; +/** * struct list_head - the head of a doubly-linked list * @h: the list_head (containing next and prev pointers)
util/parse-options.c +25 -0
@@ -20,6 +20,7 @@#include <util/util.h> #include <util/strbuf.h> #include <util/parse-options.h> +#include <ccan/list/list.h> #define OPT_SHORT 1#define OPT_UNSET 2
@@ -695,3 +696,27 @@ int parse_opt_verbosity_cb(const struct option *opt, }return 0 ; } + +int parse_opt_string_list (const struct option *opt,const char *arg,int unset) +{ +if (unset) +return 0 ; + +if (!arg) +return -1 ; + +struct list_head *v = opt->value; +char *temp =strdup (arg); +const char *deli =" " ; + + temp =strtok (temp, deli); +while (temp !=NULL ) { +struct string_list_node *sln =malloc (sizeof (*sln)); + sln->str = temp; +list_add_tail (v, &sln->list); + temp =strtok (NULL , deli); + } + +free (temp); +return 0 ; +}
util/parse-options.h +3 -0
@@ -135,6 +135,8 @@ struct option {#define OPT_LONG (s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) }#define OPT_U64 (s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) }#define OPT_STRING (s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) } +#define OPT_STRING_LIST (s, l, v, a, h) \ + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = check_vtype(v, struct list_head *), (a), .help = (h) , 0, &parse_opt_string_list }#define OPT_DATE (s, l, v, h) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }#define OPT_CALLBACK (s, l, v, a, h, f) \
@@ -206,6 +208,7 @@ extern int parse_options_end(struct parse_opt_ctx_t *ctx);extern int parse_opt_abbrev_cb (const struct option *,const char *,int );extern int parse_opt_approxidate_cb (const struct option *,const char *,int );extern int parse_opt_verbosity_cb (const struct option *,const char *,int ); +extern int parse_opt_string_list (const struct option *,const char *,int );#define OPT__VERBOSE (var) OPT_BOOLEAN('v', "verbose", (var), "be verbose")#define OPT__QUIET (var) OPT_BOOLEAN('q', "quiet", (var), "be quiet")
Signature · 7 lines
2.17.0.140.g0b0cc9f86 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 57 lines · QI Fuli
This patch adds
OPT_STRING_LISTtoparse_optionin order to support multiple space seperated string objects in one option.Signed-off-by QI Fuli <[email protected]>--- ccan/list/list.h | 6 ++++++ util/parse-options.c | 25 +++++++++++++++++++++++++ util/parse-options.h | 3 +++ 3 files changed, 34 insertions(+)ccan/list/list.h +6
-0@@ -26,6 +26,12 @@ struct list_nodestruct list_node *next, *prev; }; +struct string_list_node +{ +char *str; +struct list_node list; +}; +/** * struct list_head - the head of a doubly-linked list * @h: the list_head (containing next and prev pointers) util/parse-options.c +15
-0@@ -20,6 +20,7 @@#include <util/util.h> #include <util/strbuf.h> #include <util/parse-options.h> +#include <ccan/list/list.h> #define OPT_SHORT 1#define OPT_UNSET 2@@ -695,3 +696,27 @@ int parse_opt_verbosity_cb(const struct option *opt, }return 0 ; } + +int parse_opt_string_list (const struct option *opt,const char *arg,int unset) +{ +if (unset) +return 0 ; + +if (!arg) +return -1 ; + +struct list_head *v = opt->value; +char *temp =strdup (arg); +const char *deli =" " ; + + temp =strtok (temp, deli);
util/parse-options.c int parse_opt_verbosity_cb(const struct option *opt, · line 722
Quoted 10 lines
util/parse-options.c +10
-0+while (temp !=NULL ) { +struct string_list_node *sln =malloc (sizeof (*sln)); + sln->str = temp; +list_add_tail (v, &sln->list); + temp =strtok (NULL , deli); + } + +free (temp); +return 0 ; +}
As far as I can see we do not need to allocate a list or add this new OPT_STRING_LIST argument type. Just teach the util_<object>_filter() routines that the 'ident' argument may be a space delimited list. See the attached patch:
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
RE: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 71 lines
-----Original Message-----
From: Dan Williams [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 11:57 PM
To: Qi, Fuli/斉 福利 <[email protected]>
Cc: linux-nvdimm <[email protected]>
Subject: Re: [PATCH 1/2] ndctl, util: addOPT_STRING_LISTtoparse_optionQuoted 62 lines · QI Fuli
This patch adds
OPT_STRING_LISTtoparse_optionin order to support multiple space seperated string objects in one option.Signed-off-by QI Fuli <[email protected]>--- ccan/list/list.h | 6 ++++++ util/parse-options.c | 25 +++++++++++++++++++++++++ util/parse-options.h | 3 +++ 3 files changed, 34 insertions(+)ccan/list/list.h index renamed from ccan/list/list.h +0
-04d1d34e..f6c927f 100644
ccan/list/list.h +6
-0@@ -26,6 +26,12 @@ struct list_nodestruct list_node *next, *prev; }; +struct string_list_node +{ +char *str; +struct list_node list; +}; +/** * struct list_head - the head of a doubly-linked list * @h: the list_head (containing next and prev pointers) diff --git
a/util/parse-options.cb/util/parse-options.cindex 751c091..cac18f0 100644util/parse-options.c +21
-0@@ -20,6 +20,7 @@#include <util/util.h> #include <util/strbuf.h> #include <util/parse-options.h> +#include <ccan/list/list.h> #define OPT_SHORT 1#define OPT_UNSET 2@@ -695,3 +696,27 @@ int parse_opt_verbosity_cb(const struct option *opt, }return 0 ; } + +int parse_opt_string_list (const struct option *opt,const char *arg, +int unset) { +if (unset) +return 0 ; + +if (!arg) +return -1 ; + +struct list_head *v = opt->value; +char *temp =strdup (arg); +const char *deli =" " ; + + temp =strtok (temp, deli); +while (temp !=NULL ) { +struct string_list_node *sln =malloc (sizeof (*sln)); + sln->str = temp; +list_add_tail (v, &sln->list); + temp =strtok (NULL , deli); + }
Quoted 8 lines
util/parse-options.c int parse_opt_verbosity_cb(const struct option *opt, · line 722
Quoted 4 lines
util/parse-options.c +4
-0+ +free (temp); +return 0 ; +}As far as I can see we do not need to allocate a list or add this new
OPT_STRING_LISTargument type. Just teach the util_<object>_filter() routines that the 'ident' argument may be a space delimited list. See the attached patch:
Thank you for your comment.
The OPT_STRING_LIST is copied from git.
Consider multiple arguments per option should be supported not only in monitor and list but also in other commands, as Vishal mentioned:
"ndctl disable-namespace namespace1.0 namespace2.0 ..."
If you think this feature is not needed in other commands, I will delete OPT_STRING_LIST and make a v2 patch.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 80 lines · Fuli
Quoted 71 lines
-----Original Message-----
From: Dan Williams [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 11:57 PM
To: Qi, Fuli/斉 福利 <[email protected]>
Cc: linux-nvdimm <[email protected]>
Subject: Re: [PATCH 1/2] ndctl, util: addOPT_STRING_LISTtoparse_optionQuoted 62 lines · QI Fuli
This patch adds
OPT_STRING_LISTtoparse_optionin order to support multiple space seperated string objects in one option.Signed-off-by QI Fuli <[email protected]>--- ccan/list/list.h | 6 ++++++ util/parse-options.c | 25 +++++++++++++++++++++++++ util/parse-options.h | 3 +++ 3 files changed, 34 insertions(+)ccan/list/list.h index renamed from ccan/list/list.h +0
-04d1d34e..f6c927f 100644
ccan/list/list.h +6
-0@@ -26,6 +26,12 @@ struct list_nodestruct list_node *next, *prev; }; +struct string_list_node +{ +char *str; +struct list_node list; +}; +/** * struct list_head - the head of a doubly-linked list * @h: the list_head (containing next and prev pointers) diff --git
a/util/parse-options.cb/util/parse-options.cindex 751c091..cac18f0 100644util/parse-options.c +21
-0@@ -20,6 +20,7 @@#include <util/util.h> #include <util/strbuf.h> #include <util/parse-options.h> +#include <ccan/list/list.h> #define OPT_SHORT 1#define OPT_UNSET 2@@ -695,3 +696,27 @@ int parse_opt_verbosity_cb(const struct option *opt, }return 0 ; } + +int parse_opt_string_list (const struct option *opt,const char *arg, +int unset) { +if (unset) +return 0 ; + +if (!arg) +return -1 ; + +struct list_head *v = opt->value; +char *temp =strdup (arg); +const char *deli =" " ; + + temp =strtok (temp, deli); +while (temp !=NULL ) { +struct string_list_node *sln =malloc (sizeof (*sln)); + sln->str = temp; +list_add_tail (v, &sln->list); + temp =strtok (NULL , deli); + }Quoted 8 lines
util/parse-options.c int parse_opt_verbosity_cb(const struct option *opt, · line 722
Quoted 4 lines
util/parse-options.c +4
-0+ +free (temp); +return 0 ; +}As far as I can see we do not need to allocate a list or add this new
OPT_STRING_LISTargument type. Just teach the util_<object>_filter() routines that the 'ident' argument may be a space delimited list. See the attached patch:
Quoted 6 lines
Thank you for your comment.
The
OPT_STRING_LISTis copied from git.
Consider multiple arguments per option should be supported not only in monitor and list but also in other commands, as Vishal mentioned:
"ndctl disable-namespace namespace1.0 namespace2.0 ..."
In this case there's no "-n" option so the list parsing is already handled by standard shell argument parsing, i.e. the argv[] array already has the list split.
Quoted 2 lines
If you think this feature is not needed in other commands, I will delete
OPT_STRING_LISTand make a v2 patch.
I can see OPT_STRING_LIST potentially being useful in other scenarios, but for the util_<object>_filter functions it seems an awkward fit to me. We end up doing the parsing twice. Once to parse the space separated list and again to parse each entry against the object to be filtered. In this case I think it is cleaner to handle it internally to the utility functions. It also makes the util functions more generically useful as I can now use them in scenarios where the string list is not coming from the command line.
Ross noted that the attachment got swallowed by the list, so here it is pasted, please forgive any whitespace damage:
util/filter.c +0 -0
@@ -98,28 +98,38 @@ struct ndctl_namespace
*util_namespace_filter(struct ndctl_namespace *ndns
return NULL;
}
-struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *ident) +struct ndctl_dimm *util_dimm_filter(struct ndctl_dimm *dimm, const char *__ident)
{
- char *end = NULL;
- const char *name;
+ char *end = NULL, *ident, *save;
+ const char *name, *dimm_name;
unsigned long dimm_id, id;- if (!ident || strcmp(ident, "all") == 0)
+ if (!__ident || strcmp(__ident, "all") == 0)
return dimm;
- dimm_id = strtoul(ident, &end, 0);
- if (end == ident || end[0])
- dimm_id = ULONG_MAX;
+ ident = strdup(__ident);
+ if (!ident)
+ return NULL;
- name = ndctl_dimm_get_devname(dimm); - id = ndctl_dimm_get_id(dimm); + for (name = strtok_r(ident, " ", &save); name;
+ name = strtok_r(NULL, " ", &save)) {
+ dimm_id = strtoul(name, &end, 0);
+ if (end == ident || end[0])
+ dimm_id = ULONG_MAX;
- if (dimm_id < ULONG_MAX && dimm_id == id)
- return dimm; + dimm_name = ndctl_dimm_get_devname(dimm); + id = ndctl_dimm_get_id(dimm);
- if (dimm_id == ULONG_MAX && strcmp(ident, name) == 0)
- return dimm;
+ if (dimm_id < ULONG_MAX && dimm_id == id)
+ break;
+
+ if (dimm_id == ULONG_MAX && strcmp(dimm_name, name) == 0)
+ break;
+ }
+ free(ident);
+ if (name)
+ return dimm;
return NULL; }
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
RE: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines
As far as I can see we do not need to allocate a list or add this new
OPT_STRING_LISTargument type. Just teach the util_<object>_filter()routines
Quoted 1 line
Quoted 1 line
that the 'ident' argument may be a space delimited list. See the attached
patch:
Quoted 7 lines
Thank you for your comment.
The
OPT_STRING_LISTis copied from git.
Consider multiple arguments per option should be supported not only in monitor and list but also in other commands, as Vishal mentioned:
"ndctl disable-namespace namespace1.0 namespace2.0 ..."In this case there's no "-n" option so the list parsing is already handled by standard shell argument parsing, i.e. the argv[] array already has the list split.
Quoted 2 lines
If you think this feature is not needed in other commands, I will delete
OPT_STRING_LISTand make a v2 patch.I can see
OPT_STRING_LISTpotentially being useful in other scenarios, but for the util_<object>_filter functions it seems an awkward fit to me. We end up doing the parsing twice. Once to parse the space separated list and again to parse each entry against the object to be filtered. In this case I think it is cleaner to handle it internally to the utility functions. It also makes the util functions more generically useful as I can now use them in scenarios where the string list is not coming from the command line.
Quoted 2 lines
Ross noted that the attachment got swallowed by the list, so here it is pasted, please forgive any whitespace damage:
Thank you very much, I made a v2 patch by referring to your sample patch.
Going back to the OPT_STRING_LIST, I think it is necessary for ndctl. Because the other options in monitor like --dimm-event, --bus-event also need to support multiple space-separated arguments, these options should be made as a string_list.
One more question is that do you think it is necessary for ndctl to copy OPT_FILENAME in parse_option from git? The difference between OPT_FILENAME and OPT_STRING is that there is an additional fix_filename() in OPTION_FILENAME to process file's path. Considering that ndctl monitor also has file options like --logfile, --conf-file, I think we'd better to copy it.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 32 lines · Fuli
Quoted 29 lines
Quoted 2 lines
Quoted 2 lines
As far as I can see we do not need to allocate a list or add this new
OPT_STRING_LISTargument type. Just teach the util_<object>_filter()routines
Quoted 1 line
Quoted 1 line
that the 'ident' argument may be a space delimited list. See the attached
patch:
Quoted 7 lines
Thank you for your comment.
The
OPT_STRING_LISTis copied from git.
Consider multiple arguments per option should be supported not only in monitor and list but also in other commands, as Vishal mentioned:
"ndctl disable-namespace namespace1.0 namespace2.0 ..."In this case there's no "-n" option so the list parsing is already handled by standard shell argument parsing, i.e. the argv[] array already has the list split.
Quoted 2 lines
If you think this feature is not needed in other commands, I will delete
OPT_STRING_LISTand make a v2 patch.I can see
OPT_STRING_LISTpotentially being useful in other scenarios, but for the util_<object>_filter functions it seems an awkward fit to me. We end up doing the parsing twice. Once to parse the space separated list and again to parse each entry against the object to be filtered. In this case I think it is cleaner to handle it internally to the utility functions. It also makes the util functions more generically useful as I can now use them in scenarios where the string list is not coming from the command line.Quoted 2 lines
Ross noted that the attachment got swallowed by the list, so here it is pasted, please forgive any whitespace damage:
Quoted 6 lines
Thank you very much, I made a v2 patch by referring to your sample patch.
Going back to the
OPT_STRING_LIST, I think it is necessary for ndctl. Because the other options in monitor like --dimm-event, --bus-event also need to support multiple space-separated arguments, these options should be made as astring_list.
Ok, yes, lets bring in string_list for that case.
Quoted 5 lines
One more question is that do you think it is necessary for ndctl to copy
OPT_FILENAMEinparse_optionfrom git? The difference betweenOPT_FILENAMEandOPT_STRINGis that there is an additionalfix_filename()inOPTION_FILENAMEto process file's path. Considering that ndctl monitor also has file options like --logfile, --conf-file, I think we'd better to copy it.
Yes, let's copy git's lead for filename fixups.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
RE: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 9 lines
Quoted 6 lines
Thank you very much, I made a v2 patch by referring to your sample patch.
Going back to the
OPT_STRING_LIST, I think it is necessary for ndctl. Because the other options in monitor like --dimm-event, --bus-event also need to support multiple space-separated arguments, these options should be made as astring_list.Ok, yes, lets bring in
string_listfor that case.
Could you merge the OPT_STRING_LIST first?
Quoted 9 lines
Quoted 5 lines
One more question is that do you think it is necessary for ndctl to
copyOPT_FILENAMEinparse_optionfrom git? The difference betweenOPT_FILENAMEandOPT_STRINGis that there is an additionalfix_filename()inOPTION_FILENAMEto process file's path. Considering
that ndctl monitor also has file options like --logfile, --conf-file, I think we'd betterto copy it.
Yes, let's copy git's lead for filename fixups.
OK, I will make a patch for adding the OPTION_FILENAME to parse_option.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Re: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 11 lines · Fuli
Quoted 9 lines
Quoted 6 lines
Thank you very much, I made a v2 patch by referring to your sample patch.
Going back to the
OPT_STRING_LIST, I think it is necessary for ndctl. Because the other options in monitor like --dimm-event, --bus-event also need to support multiple space-separated arguments, these options should be made as astring_list.Ok, yes, lets bring in
string_listfor that case.Could you merge the
OPT_STRING_LISTfirst?
Oh, I was assuming when you said string_list that you would redo the patch to bring in the struct string_list implementation from git, and not use the strtok() approach. I'd like to not diverge from that implementation.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
RE: [PATCH 1/2] ndctl, util: add OPT_STRING_LIST to parse_option
Quoted 18 lines
-----Original Message-----
From: Dan Williams [mailto:[email protected]]
Sent: Thursday, April 19, 2018 11:10 AM
To: Qi, Fuli/斉 福利 <[email protected]>
Cc: linux-nvdimm <[email protected]>
Subject: Re: [PATCH 1/2] ndctl, util: addOPT_STRING_LISTtoparse_optionQuoted 10 lines · Fuli
Quoted 9 lines
Quoted 6 lines
Thank you very much, I made a v2 patch by referring to your sample patch.
Going back to the
OPT_STRING_LIST, I think it is necessary for ndctl. Because the other options in monitor like --dimm-event, --bus-event also need to support multiple space-separated arguments, these options should be made as astring_list.Ok, yes, lets bring in
string_listfor that case.
Quoted 7 lines
Quoted 1 line
Could you merge the
OPT_STRING_LISTfirst?Oh, I was assuming when you said
string_listthat you would redo the patch to bring in the structstring_listimplementation from git, and not use thestrtok()approach. I'd like to not diverge from that implementation.
Ok, I see. I will redo the patch to bring in the struct string_list from git. Thank you.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 2/2 ndctl, list: change -b -d -r -n options to support multiple arguments
In reply to QI FuliThis patch changes --bus, --dimm, --region --namespace options to OPT_STRING_LIST in order to support multiple arguments. Users can specify multiple dimm like following:
ndctl list --dimm="nmem1 nmem2" --bus="ndbus0 ndbus1" ndctl list -d "nmem1 nmem2" -b "ndbus0 ndbus1"
--- ndctl/list.c | 35 ++++++++++++++++------ util/filter.c | 81 ++++++++++++++++++++++++++++++++++++--------------- util/filter.h | 9 +++--- 3 files changed, 88 insertions(+), 37 deletions(-)
ndctl/list.c +26 -9
@@ -129,11 +129,23 @@ static struct json_object *region_to_json(struct ndctl_region *region, ndctl_mapping_foreach(region, mapping) {struct ndctl_dimm *dimm =ndctl_mapping_get_dimm (mapping);struct json_object *jmapping; +struct string_list_node *sln; +bool flag = false;if (!list.dimms)break ; -if (!util_dimm_filter (dimm, param.dimm)) +if (!list_empty (¶m.dimm)) { +list_for_each (¶m.dimm, sln, list) { +if (util_dimm_filter (dimm, sln->str)) { + flag = true; +break ; + } + } + }else + flag = true; + +if (!flag)continue ;if (!list.idle && !ndctl_dimm_is_enabled (dimm))
@@ -415,14 +427,19 @@ static int num_list_flags(void) int cmd_list(int argc, const char **argv, void *ctx) { + list_head_init(¶m.bus); + list_head_init(¶m.dimm); + list_head_init(¶m.region); + list_head_init(¶m.namespace); const struct option options[] = { - OPT_STRING('b', "bus", ¶m.bus, "bus-id", "filter by bus"), - OPT_STRING('r', "region", ¶m.region, "region-id", + OPT_STRING_LIST('b', "bus", ¶m.bus, "bus-id", + "filter by bus"), + OPT_STRING_LIST('r', "region", ¶m.region, "region-id", "filter by region"), - OPT_STRING('d', "dimm", ¶m.dimm, "dimm-id", + OPT_STRING_LIST('d', "dimm", ¶m.dimm, "dimm-id", "filter by dimm"), - OPT_STRING('n', "namespace", ¶m.namespace, "namespace-id", - "filter by namespace id"), + OPT_STRING_LIST('n', "namespace", ¶m.namespace, + "namespace-id", "filter by namespace id"), OPT_STRING('m', "mode", ¶m.mode, "namespace-mode", "filter by namespace mode"), OPT_STRING('t', "type", ¶m.type, "region-type",
@@ -461,9 +478,9 @@ int cmd_list(int argc, const char **argv, void *ctx)usage_with_options (u, options);if (num_list_flags () ==0 ) { - list.buses = !!param.bus; - list.regions = !!param.region; - list.dimms = !!param.dimm; + list.buses = !list_empty (¶m.bus); + list.regions = !list_empty (¶m.region); + list.dimms = !list_empty (¶m.dimm);if (list.dax && !param.mode) param.mode ="dax" ; }
util/filter.c +57 -24
127 lines not on this page · raw message
util/filter.h +5 -4
@@ -13,6 +13,7 @@#ifndef _UTIL_FILTER_H_#define _UTIL_FILTER_H_#include <stdbool.h> +#include <ccan/list/list.h> struct ndctl_bus *util_bus_filter (struct ndctl_bus *bus,const char *ident); struct ndctl_region *util_region_filter(struct ndctl_region *region,
@@ -71,12 +72,12 @@ struct util_filter_ctx { };struct util_filter_params { -const char *bus; -const char *region; +struct list_head bus; +struct list_head dimm; +struct list_head region; +struct list_head namespace;const char *type; -const char *dimm;const char *mode; -const char *namespace;const char *numa_node; };
Signature · 7 lines
2.17.0.140.g0b0cc9f86 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm