read-labels, destroy-namespace, and misc updates
Subsystems (4)
cover read-labels, destroy-namespace, and misc updates
For debug it is useful to be able to dump a DIMM's label area, this includes a json dump option in addition to a raw binary format.
For completeness with create-namespace, add a destroy-namespace facility. This simply refactors the namespace teardown that occurs during reconfiguration into its own utility.
Finally, a few cleanups and fixups for compiling against older ndctl.h headers.
---
Dan Williams (4):
ndctl: fix compile in the HAVE_NDCTL_{ARS|CLEAR_ERROR}=n cases
ndctl: use filter utility routines zero-labels
ndctl: new 'read-labels' utility
ndctl: new 'destroy-namespace' utility
Documentation/Makefile.am | 6 Documentation/labels-description.txt | 6 Documentation/labels-options.txt | 13 + Documentation/ndctl-destroy-namespace.txt | 27 ++ Documentation/ndctl-read-labels.txt | 30 ++ Documentation/ndctl-zero-labels.txt | 23 -- Makefile.am | 1 builtin-list.c | 21 - builtin-read-labels.c | 420 +++++++++++++++++++++++++++++ builtin-xaction-namespace.c | 61 ++++ builtin-zero-labels.c | 27 -- builtin.h | 2 lib/libndctl-ars.c | 18 + lib/libndctl.c | 10 + ndctl.c | 4 test/libndctl.c | 55 +--- util/json.c | 15 + util/json.h | 3 18 files changed, 638 insertions(+), 104 deletions(-) create mode 100644 Documentation/labels-description.txt create mode 100644 Documentation/labels-options.txt create mode 100644 Documentation/ndctl-destroy-namespace.txt create mode 100644 Documentation/ndctl-read-labels.txt create mode 100644 builtin-read-labels.c
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 1/4 ndctl: fix compile in the HAVE_NDCTL_{ARS|CLEAR_ERROR}=n cases
While we have stub routines for the library apis in libndctl-ars.c we do not have any protection against usage of the ARS or CLEAR_ERROR definitions. Arrange for those usages to be conditionally compiled.
--- lib/libndctl-ars.c | 18 ++++++++++++++--- lib/libndctl.c | 10 +++++++++ test/libndctl.c | 55 ++++++++++++++++++++-------------------------------- 3 files changed, 46 insertions(+), 37 deletions(-)
lib/libndctl-ars.c +15 -3
@@ -43,20 +43,32 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_bus_cmd_new_ars_cap(struct ndctl_bus *bus,return cmd; } +#ifdef HAVE_NDCTL_CLEAR_ERROR static bool is_power_of_2 (unsigned int v) {return v && ((v & (v -1 )) ==0 ); } +static bool validate_clear_error (struct ndctl_cmd *ars_cap) +{ +if (!is_power_of_2 (ars_cap->ars_cap->clear_err_unit)) +return false; +return true; +} +#else +static bool validate_clear_error (struct ndctl_cmd *ars_cap) +{ +return true; +} +#endif +static bool __validate_ars_cap (struct ndctl_cmd *ars_cap) {if (ars_cap->type !=ND_CMD_ARS_CAP || ars_cap->status !=0 )return false;if ((*ars_cap->firmware_status &ARS_STATUS_MASK ) !=0 )return false; -if (!is_power_of_2 (ars_cap->ars_cap->clear_err_unit)) -return false; -return true; +return validate_clear_error (ars_cap); }#define validate_ars_cap (ctx, ars_cap) \
lib/libndctl.c +10 -0
@@ -813,7 +813,13 @@ static int to_dsm_index(const char *name, int dimm) end_cmd =ND_CMD_VENDOR ; cmd_name_fn = nvdimm_cmd_name; }else { + end_cmd =0 ; +#ifdef HAVE_NDCTL_ARS + end_cmd =ND_CMD_ARS_STATUS ; +#endif +#ifdef HAVE_NDCTL_CLEAR_ERROR end_cmd =ND_CMD_CLEAR_ERROR ; +#endif cmd_name_fn = nvdimm_bus_cmd_name; }
@@ -2143,10 +2149,14 @@ static int to_ioctl_cmd(int cmd, int dimm) {if (!dimm) {switch (cmd) { +#ifdef HAVE_NDCTL_ARS case ND_CMD_ARS_CAP :return ND_IOCTL_ARS_CAP ;case ND_CMD_ARS_START :return ND_IOCTL_ARS_START ;case ND_CMD_ARS_STATUS :return ND_IOCTL_ARS_STATUS ; +#endif +#ifdef HAVE_NDCTL_CLEAR_ERROR case ND_CMD_CLEAR_ERROR :return ND_IOCTL_CLEAR_ERROR ; +#endif default :return 0 ; };
test/libndctl.c +21 -34
83 lines not on this page · raw message
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 2/4 ndctl: use filter utility routines zero-labels
In reply to Dan WilliamsUse the common routines for filtering a bus or a dimm by name/id.
--- builtin-zero-labels.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
builtin-zero-labels.c +7 -20
@@ -4,6 +4,7 @@#include <unistd.h> #include <limits.h> #include <syslog.h> +#include <util/filter.h> #include <util/parse-options.h> #include <ndctl/libndctl.h>
@@ -11,11 +12,10 @@ static int do_zero_dimm(struct ndctl_dimm *dimm, const char **argv, int argc, bool verbose) {struct ndctl_ctx *ctx =ndctl_dimm_get_ctx (dimm); -const char *name =ndctl_dimm_get_devname (dimm);int i, rc, log;for (i =0 ; i < argc; i++) -if (strcmp (argv[i],"all" ) ==0 ||strcmp (argv[i], name) ==0 ) +if (util_dimm_filter (dimm, argv[i]))break ;if (i >= argc)return -ENODEV ;
@@ -31,7 +31,7 @@ static int do_zero_dimm(struct ndctl_dimm *dimm, const char **argv, int argc, int cmd_zero_labels(int argc, const char **argv) { - const char *nmem_bus = NULL, *provider; + const char *nmem_bus = NULL; bool verbose = false; const struct option nmem_options[] = { OPT_STRING('b', "bus", &nmem_bus, "bus-id",
@@ -39,7 +39,6 @@ int cmd_zero_labels(int argc, const char **argv)OPT_BOOLEAN ('v' ,"verbose" , &verbose,"turn on debug" ), OPT_END(), }; -unsigned long bus_id =ULONG_MAX , dimm_id;const char *const u[] = {"ndctl zero-labels <nmem0> [<nmem1>..<nmemN>] [<options>]" , NULL
@@ -54,9 +53,11 @@ int cmd_zero_labels(int argc, const char **argv)if (argc ==0 )usage_with_options (u, nmem_options);for (i =0 ; i < argc; i++) { +unsigned long id; +if (strcmp (argv[i],"all" ) ==0 )continue ; -if (sscanf (argv[i],"nmem%lu" , &dimm_id) !=1 ) { +if (sscanf (argv[i],"nmem%lu" , &id) !=1 ) {fprintf (stderr,"unknown extra parameter \"%s\"\n" , argv[i]);usage_with_options (u, nmem_options);
@@ -67,23 +68,9 @@ int cmd_zero_labels(int argc, const char **argv)if (rc <0 )return rc; -if (nmem_bus) { -char *end =NULL ; - - bus_id =strtoul (nmem_bus, &end,0 ); -if (end) - bus_id =ULONG_MAX ; - } - count =0 ; ndctl_bus_foreach(ctx, bus) { -unsigned int id =ndctl_bus_get_id (bus); - - provider =ndctl_bus_get_provider (bus); -if (bus_id <ULONG_MAX && bus_id != id) -continue ; -else if (bus_id ==ULONG_MAX && nmem_bus - &&strcmp (nmem_bus, provider) !=0 ) +if (!util_bus_filter (bus, nmem_bus))continue ; ndctl_dimm_foreach(bus, dimm) {
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 3/4 ndctl: new 'read-labels' utility
In reply to Dan WilliamsFor debug, it is useful to be able to dump the label area of a dimm.
--- Documentation/Makefile.am | 5 Documentation/labels-description.txt | 6 Documentation/labels-options.txt | 13 + Documentation/ndctl-read-labels.txt | 30 ++ Documentation/ndctl-zero-labels.txt | 23 -- Makefile.am | 1 builtin-list.c | 21 -- builtin-read-labels.c | 420 ++++++++++++++++++++++++++++++++++ builtin.h | 1 ndctl.c | 1 util/json.c | 15 + util/json.h | 3 12 files changed, 501 insertions(+), 38 deletions(-) create mode 100644 Documentation/labels-description.txt create mode 100644 Documentation/labels-options.txt create mode 100644 Documentation/ndctl-read-labels.txt create mode 100644 builtin-read-labels.c
Documentation/Makefile.am +4 -1
@@ -1,6 +1,7 @@ man1_MANS = \ ndctl.1 \ ndctl-zero-labels.1 \ + ndctl-read-labels.1 \ ndctl-enable-region.1 \ ndctl-disable-region.1 \ ndctl-enable-namespace.1 \
@@ -15,7 +16,9 @@ XML_DEPS = \ Makefile \ region-description.txt \ xable-region-options.txt \ - xable-namespace-options.txt + xable-namespace-options.txt \ + labels-description.txt \ + labels-options.txt RM ?= rm -f
Documentation/labels-description.txt new file +6 -0
@@ -0,0 +1,6 @@ +DESCRIPTION +----------- +The namespace label area is a small persistent partition of capacity +available on some NVDIMM devices. The label area is used to resolve +aliasing between 'pmem' and 'blk' capacity by lineating namespace +boundaries.
Documentation/labels-options.txt new file +13 -0
@@ -0,0 +1,13 @@ +<memory device(s)>...:: + One or more 'nmemX' device names. The keyword 'all' can be specified to + operate on every dimm in the system, optionally filtered by bus id (see + --bus= option). + +-b:: +--bus=:: + Limit operation to memory devices (dimms) that are on the given bus. + Where 'bus' can be a provider name or a bus id number. + +-v:: + Turn on verbose debug messages in the library (if ndctl was built with + logging and debug enabled).
Documentation/ndctl-read-labels.txt new file +30 -0
@@ -0,0 +1,30 @@ +ndctl-read-labels(1) +==================== + +NAME +---- +ndctl-read-labels - read out the label area on a dimm or set of dimms + +SYNOPSIS +-------- +[verse] +'ndctl read-labels' <nmem0> [<nmem1>..<nmemN>] [<options>] + +include::labels-description.txt[] +This command dumps the raw binary data in a dimm's label area to stdout or a +file. In the multi-dimm case the data is concatenated. + +OPTIONS +------- +include::labels-options.txt[] +-o:: + output file +-j:: +--json:: + parse the label data into json assuming the 'NVDIMM Namespace + Specification' format. + +SEE ALSO +-------- +http://pmem.io/documents/NVDIMM_Namespace_Spec.pdf[NVDIMM Namespace +Specification]
Documentation/ndctl-zero-labels.txt +3 -20
@@ -10,30 +10,13 @@ SYNOPSIS [verse] 'ndctl zero-labels' <nmem0> [<nmem1>..<nmemN>] [<options>] -DESCRIPTION ------------ -The namespace label area is a small persistent partition of capacity -available on some NVDIMM devices. The label area is used to resolve -aliasing between 'pmem' and 'blk' capacity by lineating namespace -boundaries. This command resets the device to its default state by +include::labels-description.txt[] +This command resets the device to its default state by deleting all labels. OPTIONS ------- - -<memory device(s)>...:: - One or more 'nmemX' device names. The keyword 'all' can be specified to - zero every dimm in the system, optionally filtered by bus id (see --bus= - option). - --b:: ---bus=:: - Limit zeroing to memory devices (dimms) that are on the given bus. - Where 'bus' can be a provider name or a bus id number. - --v:: - Turn on verbose debug messages in the library (if ndctl was built with - logging and debug enabled). +include::labels-options.txt[] SEE ALSO --------
Makefile.am +1 -0
@@ -99,6 +99,7 @@ ndctl_SOURCES = ndctl.c \ builtin-test.c \ builtin-help.c \ builtin-zero-labels.c \ + builtin-read-labels.c \ util/parse-options.c \ util/parse-options.h \ util/usage.c \
builtin-list.c +4 -17
@@ -179,19 +179,6 @@ static struct json_object *region_to_json(struct ndctl_region *region)return NULL ; } -static void display_array (struct json_object *jarray) -{ -if (json_object_array_length (jarray) >1 ) -printf ("%s\n" ,json_object_to_json_string_ext (jarray, jflag)); -else { -struct json_object *jobj; - - jobj =json_object_array_get_idx (jarray,0 ); -printf ("%s\n" ,json_object_to_json_string_ext (jobj, jflag)); - } -json_object_put (jarray); -} -int cmd_list (int argc,const char **argv) {const struct option options[] = {
@@ -387,7 +374,7 @@ int cmd_list(int argc, const char **argv) }if (jbuses) -display_array (jbuses); +util_display_json_array (stdout, jbuses, jflag);else if ((!!jdimms + !!jregions + !!jnamespaces) >1 ) {struct json_object *jplatform =json_object_new_object ();
@@ -407,11 +394,11 @@ int cmd_list(int argc, const char **argv) jflag));json_object_put (jplatform); }else if (jdimms) -display_array (jdimms); +util_display_json_array (stdout, jdimms, jflag);else if (jregions) -display_array (jregions); +util_display_json_array (stdout, jregions, jflag);else if (jnamespaces) -display_array (jnamespaces); +util_display_json_array (stdout, jnamespaces, jflag);if (did_fail)return -ENOMEM ;
builtin-read-labels.c new file +420 -0
420 lines not on this page · raw message
builtin.h +1 -0
@@ -15,6 +15,7 @@ int cmd_disable_namespace(int argc, const char **argv);int cmd_enable_region (int argc,const char **argv);int cmd_disable_region (int argc,const char **argv);int cmd_zero_labels (int argc,const char **argv); +int cmd_read_labels (int argc,const char **argv);int cmd_help (int argc,const char **argv);int cmd_list (int argc,const char **argv);#ifdef ENABLE_TEST
ndctl.c +1 -0
@@ -31,6 +31,7 @@ static struct cmd_struct commands[] = { { "enable-region", cmd_enable_region }, { "disable-region", cmd_disable_region }, { "zero-labels", cmd_zero_labels }, + { "read-labels", cmd_read_labels }, { "list", cmd_list }, { "help", cmd_help }, #ifdef ENABLE_TEST
util/json.c +15 -0
@@ -11,6 +11,21 @@#include <ndctl.h> #endif +void util_display_json_array (FILE *f_out,struct json_object *jarray,int jflag) +{ +int len =json_object_array_length (jarray); + +if (json_object_array_length (jarray) >1 ) +fprintf (f_out,"%s\n" ,json_object_to_json_string_ext (jarray, jflag)); +else if (len) { +struct json_object *jobj; + + jobj =json_object_array_get_idx (jarray,0 ); +fprintf (f_out,"%s\n" ,json_object_to_json_string_ext (jobj, jflag)); + } +json_object_put (jarray); +} +struct json_object *util_bus_to_json (struct ndctl_bus *bus) {struct json_object *jbus =json_object_new_object ();
util/json.h +3 -0
@@ -1,8 +1,11 @@#ifndef __NDCTL_JSON_H__#define __NDCTL_JSON_H__ +#include <stdio.h> #include <stdbool.h> #include <ndctl/libndctl.h> +struct json_object ; +void util_display_json_array (FILE *f_out,struct json_object *jarray,int jflag);bool util_namespace_active (struct ndctl_namespace *ndns);struct json_object *util_bus_to_json (struct ndctl_bus *bus);struct json_object *util_dimm_to_json (struct ndctl_dimm *dimm);
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
PATCH 4/4 ndctl: new 'destroy-namespace' utility
In reply to Dan WilliamsUndo a create-namespace operation. Zero any info blocks, revoke all claims, and unallocate the region capacity.
--- Documentation/Makefile.am | 1 Documentation/ndctl-destroy-namespace.txt | 27 +++++++++++++ builtin-xaction-namespace.c | 61 +++++++++++++++++++++++++---- builtin.h | 1 ndctl.c | 3 + 5 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 Documentation/ndctl-destroy-namespace.txt
Documentation/Makefile.am +1 -0
@@ -7,6 +7,7 @@ man1_MANS = \ ndctl-enable-namespace.1 \ ndctl-disable-namespace.1 \ ndctl-create-namespace.1 \ + ndctl-destroy-namespace.1 \ ndctl-list.1 CLEANFILES = $(man1_MANS)
Documentation/ndctl-destroy-namespace.txt new file +27 -0
@@ -0,0 +1,27 @@ +ndctl-destroy-namespace(1) +========================= + +NAME +---- +ndctl-destroy-namespace - destroy the given namespace(s) + +SYNOPSIS +-------- +[verse] +'ndctl destroy-namespace' <namespace> [<options>] + +include::namespace-description.txt[] + +OPTIONS +------- +include::xable-namespace-options.txt[] +-f:: +--force:: + Unless this option is specified the 'destroy namespace' + operation will fail if the namespace is presently active. + Specifying --force causes the namespace to be disabled before + the operation is attempted. + +SEE ALSO +-------- +linkndctl:ndctl-create-namespace[1]
builtin-xaction-namespace.c +53 -8
118 lines not on this page · raw message
builtin.h +1 -0
@@ -11,6 +11,7 @@ struct cmd_struct {int cmd_create_nfit (int argc,const char **argv);int cmd_enable_namespace (int argc,const char **argv);int cmd_create_namespace (int argc,const char **argv); +int cmd_destroy_namespace (int argc,const char **argv);int cmd_disable_namespace (int argc,const char **argv);int cmd_enable_region (int argc,const char **argv);int cmd_disable_region (int argc,const char **argv);
ndctl.c +2 -1
@@ -26,8 +26,9 @@ static struct cmd_struct commands[] = { { "version", cmd_version }, { "create-nfit", cmd_create_nfit }, { "enable-namespace", cmd_enable_namespace }, - { "create-namespace", cmd_create_namespace }, { "disable-namespace", cmd_disable_namespace }, + { "create-namespace", cmd_create_namespace }, + { "destroy-namespace", cmd_destroy_namespace }, { "enable-region", cmd_enable_region }, { "disable-region", cmd_disable_region }, { "zero-labels", cmd_zero_labels },
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm