Add an option to disable the behavior of cleaning up namespaces that failed creation. This is useful for doing forensics on the label and info-block state after the failure with assurances that the kernel has not made further modifications.
Signed-off-by: Dan Williams <[email protected]> --- Documentation/ndctl/ndctl-create-namespace.txt | 9 +++++++++ ndctl/namespace.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Documentation/ndctl/ndctl-create-namespace.txt b/Documentation/ndctl/ndctl-create-namespace.txt index 343733dedfd9..ed936c87e483 100644 --- a/Documentation/ndctl/ndctl-create-namespace.txt +++ b/Documentation/ndctl/ndctl-create-namespace.txt @@ -203,6 +203,15 @@ OPTIONS ndctl init-labels all ndctl enable-region all +-R:: +--autorecover:: +--no-autorecover:: + By default, if a namespace creation attempt fails, ndctl will + cleanup the partially initialized namespace. Use + --no-autorecover to disable this behavior for debug and + development scenarios where it useful to have the label and + info-block state preserved after a failure. + -v:: --verbose:: Emit debug messages for the namespace creation process diff --git a/ndctl/namespace.c b/ndctl/namespace.c index a3963d79831a..58fec194ab94 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -43,6 +43,7 @@ static struct parameters { bool mode_default; bool autolabel; bool verify; + bool autorecover; bool human; bool json; const char *bus; @@ -60,6 +61,7 @@ static struct parameters { const char *infile; } param = { .autolabel = true, + .autorecover = true, }; void builtin_xaction_namespace_reset(void) @@ -84,6 +86,7 @@ struct parsed_parameters { unsigned long sector_size; unsigned long align; bool autolabel; + bool autorecover; }; #define pr_verbose(fmt, ...) \ @@ -127,7 +130,8 @@ OPT_STRING('t', "type", ¶m.type, "type", \ OPT_STRING('a', "align", ¶m.align, "align", \ "specify the namespace alignment in bytes (default: 2M)"), \ OPT_BOOLEAN('f', "force", &force, "reconfigure namespace even if currently active"), \ -OPT_BOOLEAN('L', "autolabel", ¶m.autolabel, "automatically initialize labels") +OPT_BOOLEAN('L', "autolabel", ¶m.autolabel, "automatically initialize labels"), \ +OPT_BOOLEAN('R', "autorecover", ¶m.autorecover, "automatically cleanup on failure") #define CHECK_OPTIONS() \ OPT_BOOLEAN('R', "repair", &repair, "perform metadata repairs"), \ @@ -444,7 +448,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_pfn, set_align, pfn, p->align); try(ndctl_pfn, set_namespace, pfn, ndns); rc = ndctl_pfn_enable(pfn); - if (rc) + if (rc && p->autorecover) ndctl_pfn_set_namespace(pfn, NULL); } else if (p->mode == NDCTL_NS_MODE_DAX) { struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); @@ -455,7 +459,7 @@ static int setup_namespace(struct ndctl_region *region, try(ndctl_dax, set_align, dax, p->align); try(ndctl_dax, set_namespace, dax, ndns); rc = ndctl_dax_enable(dax); - if (rc) + if (rc && p->autorecover) ndctl_dax_set_namespace(dax, NULL); } else if (p->mode == NDCTL_NS_MODE_SAFE) { struct ndctl_btt *btt = ndctl_region_get_btt_seed(region); @@ -798,6 +802,7 @@ static int validate_namespace_options(struct ndctl_region *region, p->autolabel = param.autolabel; + p->autorecover = param.autorecover; return 0; } @@ -852,7 +857,7 @@ static int namespace_create(struct ndctl_region *region) } rc = setup_namespace(region, ndns, &p); - if (rc) { + if (rc && p.autorecover) { ndctl_namespace_set_enforce_mode(ndns, NDCTL_NS_MODE_RAW); ndctl_namespace_delete(ndns); } _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
