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 7637e2403132..92a89dd71e82 100644
--- a/Documentation/ndctl/ndctl-create-namespace.txt
+++ b/Documentation/ndctl/ndctl-create-namespace.txt
@@ -229,6 +229,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 91e25044145b..cd75038f5ae3 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -44,6 +44,7 @@ static struct parameters {
        bool autolabel;
        bool greedy;
        bool verify;
+       bool autorecover;
        bool human;
        bool json;
        const char *bus;
@@ -61,6 +62,7 @@ static struct parameters {
        const char *infile;
 } param = {
        .autolabel = true,
+       .autorecover = true,
 };
 
 const char *cmd_name = "namespace";
@@ -87,6 +89,7 @@ struct parsed_parameters {
        unsigned long sector_size;
        unsigned long align;
        bool autolabel;
+       bool autorecover;
 };
 
 #define pr_verbose(fmt, ...) \
@@ -136,7 +139,8 @@ OPT_STRING('a', "align", &param.align, "align", \
 OPT_BOOLEAN('f', "force", &force, "reconfigure namespace even if currently 
active"), \
 OPT_BOOLEAN('L', "autolabel", &param.autolabel, "automatically initialize 
labels"), \
 OPT_BOOLEAN('c', "continue", &param.greedy, \
-       "continue creating namespaces as long as the filter criteria are met")
+       "continue creating namespaces as long as the filter criteria are met"), 
\
+OPT_BOOLEAN('R', "autorecover", &param.autorecover, "automatically cleanup on 
failure")
 
 #define CHECK_OPTIONS() \
 OPT_BOOLEAN('R', "repair", &repair, "perform metadata repairs"), \
@@ -474,7 +478,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);
@@ -488,7 +492,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);
@@ -848,6 +852,7 @@ static int validate_namespace_options(struct ndctl_region 
*region,
 
 
        p->autolabel = param.autolabel;
+       p->autorecover = param.autorecover;
 
        return 0;
 }
@@ -906,7 +911,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]
To unsubscribe send an email to [email protected]

Reply via email to