@@ -907,6 +907,7 @@ static int namespace_destroy(struct ndctl_region *region,
struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns);
struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
+ unsigned long long size;
bool did_zero = false;
int rc;
@@ -953,10 +954,19 @@ static int namespace_destroy(struct ndctl_region *region,
goto out;
}
+ size = ndctl_namespace_get_size(ndns);
+
rc = ndctl_namespace_delete(ndns);
if (rc)
debug("%s: failed to reclaim\n", devname);
+ /*
+ * Don't report a destroyed namespace when no capacity was
+ * allocated.
+ */
+ if (size == 0 && rc == 0)
+ rc = 1;
+
out:
return rc;
}
Seed namespaces are included in "ndctl destroy-namespace all". However since the user never "creates" them it is surprising to see "destroy-namespace" report 1 more namespace relative to the number that have been created. Catch attempts to destroy a zero-sized namespace: Before: # ndctl create-namespace -s 500M { "dev":"namespace1.0", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1" } # ndctl create-namespace -s 500M { "dev":"namespace1.1", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1.1" } # ndctl create-namespace -s 500M { "dev":"namespace1.2", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1.2" } # ndctl destroy-namespace -r 1 all -f destroyed 4 namespaces After: # ndctl create-namespace -s 500M { "dev":"namespace1.0", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1" } # ndctl create-namespace -s 500M { "dev":"namespace1.3", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1.3" } # ndctl create-namespace -s 500M { "dev":"namespace1.1", "size":"492.00 MiB (515.90 MB)", "blockdev":"pmem1.1" } # ndctl destroy-namespace -r 1 all -f destroyed 3 namespaces Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- ndctl/namespace.c | 10 ++++++++++ 1 file changed, 10 insertions(+)