ndctl, filter: refacor util_<obj>_filter() to support multiple space-seperated arguments
PATCH v2 1/1 ndctl, filter: refacor util_<obj>_filter() to support multiple space-seperated arguments
This patch refactors util_<obj>_filter to support multiple space-seperated arguments. Currently, only one <object> can be filtered by <object>'s name in util_<obj>_filter(). As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature teachs the util_dimm_filter() that the "ident" argument maybe a space-seperatd string which includes multiple dimm_names. Therefore the monitor can filter multiple dimms in one process.
Change log since v1:
- Removing OPT_STRING_LIST from parse-option
--- util/filter.c | 141 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 49 deletions(-)
util/filter.c +92 -49
@@ -25,101 +25,144 @@#define NUMA_NO_NODE (-1) -struct ndctl_bus *util_bus_filter (struct ndctl_bus *bus,const char *ident) +struct ndctl_bus *util_bus_filter (struct ndctl_bus *bus,const char *__ident) { -char *end =NULL ; +char *end =NULL , *ident, *save;unsigned long bus_id, id; -const char *provider, *devname; +const char *provider, *devname, *name; -if (!ident ||strcmp (ident,"all" ) ==0 ) +if (!__ident ||strcmp (__ident,"all" ) ==0 )return bus; - bus_id =strtoul (ident, &end,0 ); -if (end == ident || end[0 ]) - bus_id =ULONG_MAX ; + ident =strdup (__ident); +if (!ident) +return NULL ; - provider =ndctl_bus_get_provider (bus); - devname =ndctl_bus_get_devname (bus); - id =ndctl_bus_get_id (bus); +for (name =strtok_r (ident," " , &save); name; + name =strtok_r (NULL ," " , &save)) { + bus_id =strtoul (ident, &end,0 ); +if (end == ident || end[0 ]) + bus_id =ULONG_MAX ; -if (bus_id <ULONG_MAX && bus_id == id) -return bus; + provider =ndctl_bus_get_provider (bus); + devname =ndctl_bus_get_devname (bus); + id =ndctl_bus_get_id (bus); -if (bus_id ==ULONG_MAX && (strcmp (ident, provider) ==0 - ||strcmp (ident, devname) ==0 )) -return bus; +if (bus_id <ULONG_MAX && bus_id == id) +break ; +if (bus_id ==ULONG_MAX && (strcmp (provider, name) ==0 + ||strcmp (devname, name) ==0 )) +break ; + } +free (ident); + +if (name) +return bus;return NULL ; }struct ndctl_region *util_region_filter (struct ndctl_region *region, -const char *ident) +const char *__ident) { -char *end =NULL ; -const char *name; +char *end =NULL , *ident, *save; +const char *name, *region_name;unsigned long region_id, id; -if (!ident ||strcmp (ident,"all" ) ==0 ) +if (!__ident ||strcmp (__ident,"all" ) ==0 )return region; - region_id =strtoul (ident, &end,0 ); -if (end == ident || end[0 ]) - region_id =ULONG_MAX ; + ident =strdup (__ident); +if (!ident) +return NULL ; - name =ndctl_region_get_devname (region); - id =ndctl_region_get_id (region); +for (name =strtok_r (ident," " , &save); name; + name =strtok_r (NULL ," " , &save)) { + region_id =strtoul (ident, &end,0 ); +if (end == ident || end[0 ]) + region_id =ULONG_MAX ; -if (region_id <ULONG_MAX && region_id == id) -return region; + region_name =ndctl_region_get_devname (region); + id =ndctl_region_get_id (region); -if (region_id ==ULONG_MAX &&strcmp (ident, name) ==0 ) -return region; +if (region_id <ULONG_MAX && region_id == id) +break ; + +if (region_id ==ULONG_MAX &&strcmp (region_name, name) ==0 ) +break ; + } +free (ident); +if (name) +return region;return NULL ; }struct ndctl_namespace *util_namespace_filter (struct ndctl_namespace *ndns, -const char *ident) +const char *__ident) {struct ndctl_region *region =ndctl_namespace_get_region (ndns);unsigned long region_id, ndns_id; +const char *name; +char *ident, *save; -if (!ident ||strcmp (ident,"all" ) ==0 ) +if (!__ident ||strcmp (__ident,"all" ) ==0 )return ndns; -if (strcmp (ident,ndctl_namespace_get_devname (ndns)) ==0 ) -return ndns; + ident =strdup (__ident); +if (!ident) +return NULL ; -if (sscanf (ident,"%ld.%ld" , ®ion_id, &ndns_id) ==2 - &&ndctl_region_get_id (region) == region_id - &&ndctl_namespace_get_id (ndns) == ndns_id) -return ndns; +for (name =strtok_r (ident," " , &save); name; + name =strtok_r (NULL ," " , &save)) { +if (strcmp (name,ndctl_namespace_get_devname (ndns)) ==0 ) +break ; + +if (sscanf (name,"%ld.%ld" , ®ion_id, &ndns_id) ==2 + &&ndctl_region_get_id (region) == region_id + &&ndctl_namespace_get_id (ndns) == ndns_id) +break ; + } +free (ident); +if (name) +return 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 (ident, &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 ; }
Signature · 7 lines
2.17.0.140.g0b0cc9f86 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 8 lines · QI Fuli
This patch refactors util_<obj>_filter to support multiple space-seperated arguments. Currently, only one <object> can be filtered by <object>'s name in util_<obj>_filter(). As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature teachs the
util_dimm_filter()that the "ident" argument maybe a space-seperatd string which includes multipledimm_names. Therefore the monitor can filter multiple dimms in one process.
Quoted 5 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Dan Williams <[email protected]>Change log since v1:
- RemovingOPT_STRING_LISTfrom parse-option
Looks good:
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 14 lines · Dan Williams
Quoted 13 lines · QI Fuli
This patch refactors util_<obj>_filter to support multiple space- seperated
arguments. Currently, only one <object> can be filtered by <object>'s name
in util_<obj>_filter(). As a result, when users want to moniotr multiple
dimms, they have to run multiple monitor processes. This feature teachs theutil_dimm_filter()that the "ident" argument maybe a space-seperatd string
which includes multipledimm_names. Therefore the monitor can filter multiple dimms in one process.
Quoted 2 lines
Quoted 2 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Dan Williams <[email protected]>
I'll fix up the tags like so:
Thanks,
-Vishal
Quoted 11 lines
Quoted 3 lines
Change log since v1:
- RemovingOPT_STRING_LISTfrom parse-optionLooks good:
Reviewed-by Dan Williams <[email protected]>_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 24 lines
From: Verma, Vishal L [mailto:[email protected]]
Sent: Thursday, April 19, 2018 1:06 AM
To: Williams, Dan J <[email protected]>; Qi, Fuli/斉 福利 <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] ndctl, filter: refacor util_<obj>_filter() to support multiple space-seperated argumentsQuoted 10 lines · Dan Williams
Quoted 9 lines · QI Fuli
This patch refactors util_<obj>_filter to support multiple space- seperated arguments. Currently, only one <object> can be filtered by <object>'s name in util_<obj>_filter(). As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature teachs the
util_dimm_filter()that the "ident" argument maybe a space-seperatd string which includes multipledimm_names. Therefore the monitor can filter multiple dimms in one process.Quoted 2 lines
Quoted 2 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Dan Williams <[email protected]>I'll fix up the tags like so:
Quoted 15 lines
Based-on-a-patch-by Dan Williams <[email protected]>Reviewed-by Dan Williams <[email protected]>Signed-off-by QI Fuli <[email protected]>Thanks,
-VishalQuoted 7 lines
Quoted 3 lines
Change log since v1:
- RemovingOPT_STRING_LISTfrom parse-optionLooks good:
Reviewed-by Dan Williams <[email protected]>
Thank you very much.
- Qi
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
When I ran the command # ndctl list --dimm="all nmem1 nmem2", I found only "nmem1" and "nmem2" can be listed, the keyword "all" was ignored. I want to confirm is this result expected?
If not, I will make a follow up patch to fix this bug.
Quoted 48 lines
-----Original Message-----
From: Linux-nvdimm [mailto:[email protected]] On Behalf Of Qi, Fuli
Sent: Thursday, April 19, 2018 11:10 AM
To: 'Verma, Vishal L' <[email protected]>; Williams, Dan J <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2] ndctl, filter: refacor util_<obj>_filter() to support multiple space-seperated argumentsQuoted 38 lines
From: Verma, Vishal L [mailto:[email protected]]
Sent: Thursday, April 19, 2018 1:06 AM
To: Williams, Dan J <[email protected]>; Qi, Fuli/斉 福利 <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] ndctl, filter: refacor util_<obj>_filter() to support multiple space-seperated argumentsQuoted 10 lines · Dan Williams
Quoted 9 lines · QI Fuli
This patch refactors util_<obj>_filter to support multiple space- seperated arguments. Currently, only one <object> can be filtered by <object>'s name in util_<obj>_filter(). As a result, when users want to moniotr multiple dimms, they have to run multiple monitor processes. This feature teachs the
util_dimm_filter()that the "ident" argument maybe a space-seperatd string which includes multipledimm_names. Therefore the monitor can filter multiple dimms in one process.Quoted 2 lines
Quoted 2 lines
Signed-off-by QI Fuli <[email protected]>Signed-off-by Dan Williams <[email protected]>I'll fix up the tags like so:
Based-on-a-patch-by Dan Williams <[email protected]>Reviewed-by Dan Williams <[email protected]>Signed-off-by QI Fuli <[email protected]>Thanks,
-VishalQuoted 6 lines
Quoted 3 lines
Change log since v1:
- RemovingOPT_STRING_LISTfrom parse-optionLooks good:
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Reviewed-by Dan Williams <[email protected]>Thank you very much.
- Qi
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 4 lines · Fuli
When I ran the command # ndctl list --dimm="all nmem1 nmem2", I found only "nmem1" and "nmem2" can be listed, the keyword "all" was ignored. I want to confirm is this result expected?
If not, I will make a follow up patch to fix this bug.
Yes, good catch, that's a bug.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm