@@ -116,7 +116,7 @@ int cmd_disable_namespace(int argc, const char **argv)
{
char *xable_usage = "ndctl disable-namespace <namespace> [<options>]";
const char *namespace = parse_namespace_options(argc, argv, xable_usage);
- int disabled = do_xable_namespace(namespace, ndctl_namespace_disable);
+ int disabled = do_xable_namespace(namespace, ndctl_namespace_disable_invalidate);
if (disabled < 0) {
fprintf(stderr, "error disabling namespaces: %s\n",
@@ -82,7 +82,7 @@ static struct ndctl_namespace *create_blk_namespace(int region_fraction,
static int disable_blk_namespace(struct ndctl_namespace *ndns)
{
- if (ndctl_namespace_disable(ndns) < 0)
+ if (ndctl_namespace_disable_invalidate(ndns) < 0)
return ENODEV;
if (ndctl_namespace_delete(ndns) < 0)
@@ -3196,6 +3196,20 @@ NDCTL_EXPORT int ndctl_namespace_disable(struct ndctl_namespace *ndns)
return 0;
}
+NDCTL_EXPORT int ndctl_namespace_disable_invalidate(struct ndctl_namespace *ndns)
+{
+ struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
+
+ if (btt) {
+ int rc = ndctl_btt_delete(btt);
+
+ if (rc)
+ return rc;
+ }
+
+ return ndctl_namespace_disable(ndns);
+}
+
static int pmem_namespace_is_configured(struct ndctl_namespace *ndns)
{
if (ndctl_namespace_get_size(ndns) < ND_MIN_NAMESPACE_SIZE)
@@ -136,6 +136,7 @@ global:
ndctl_namespace_is_enabled;
ndctl_namespace_enable;
ndctl_namespace_disable;
+ ndctl_namespace_disable_invalidate;
ndctl_namespace_is_valid;
ndctl_namespace_is_configured;
ndctl_namespace_delete;
@@ -288,6 +288,7 @@ const char *ndctl_namespace_get_block_device(struct ndctl_namespace *ndns);
int ndctl_namespace_is_enabled(struct ndctl_namespace *ndns);
int ndctl_namespace_enable(struct ndctl_namespace *ndns);
int ndctl_namespace_disable(struct ndctl_namespace *ndns);
+int ndctl_namespace_disable_invalidate(struct ndctl_namespace *ndns);
int ndctl_namespace_is_valid(struct ndctl_namespace *ndns);
int ndctl_namespace_is_configured(struct ndctl_namespace *ndns);
int ndctl_namespace_delete(struct ndctl_namespace *ndns);
@@ -60,7 +60,7 @@ static struct ndctl_namespace *create_pmem_namespace(struct ndctl_region *region
static int disable_pmem_namespace(struct ndctl_namespace *ndns)
{
- if (ndctl_namespace_disable(ndns) < 0)
+ if (ndctl_namespace_disable_invalidate(ndns) < 0)
return ENODEV;
if (ndctl_namespace_delete(ndns) < 0)
@@ -143,7 +143,7 @@ static int do_test(struct ndctl_ctx *ctx, struct ndctl_test *test)
ndctl_namespace_get_devname(ndns), rc);
return rc;
}
- ndctl_namespace_disable(ndns);
+ ndctl_namespace_disable_invalidate(ndns);
rc = ndctl_namespace_set_size(ndns, SZ_4K);
if (rc) {
fprintf(stderr, "failed to init %s to size: %d\n",
@@ -930,7 +930,7 @@ static int check_namespaces(struct ndctl_region *region,
close(fd);
fd = -1;
- if (ndctl_namespace_disable(ndns) < 0) {
+ if (ndctl_namespace_disable_invalidate(ndns) < 0) {
fprintf(stderr, "%s: failed to disable\n", devname);
rc = -ENXIO;
break;
@@ -970,7 +970,7 @@ static int check_namespaces(struct ndctl_region *region,
if (!retry_cnt)
break;
- if (ndctl_namespace_disable(ndns) < 0) {
+ if (ndctl_namespace_disable_invalidate(ndns) < 0) {
fprintf(stderr, "%s: failed to disable\n", devname);
break;
}
@@ -100,7 +100,7 @@ static struct ndctl_namespace *create_blk_namespace(int region_fraction,
static int disable_blk_namespace(struct ndctl_namespace *ndns)
{
- if (ndctl_namespace_disable(ndns) < 0)
+ if (ndctl_namespace_disable_invalidate(ndns) < 0)
return -ENODEV;
if (ndctl_namespace_delete(ndns) < 0)
@@ -172,19 +172,16 @@ static int do_test(struct ndctl_ctx *ctx)
if (!btt)
return -ENXIO;
+ ndctl_namespace_disable_invalidate(ndns);
ndctl_btt_set_uuid(btt, btt_uuid);
ndctl_btt_set_sector_size(btt, 512);
ndctl_btt_set_namespace(btt, ndns);
- ndctl_namespace_disable(ndns);
rc = ndctl_btt_enable(btt);
if (rc) {
fprintf(stderr, "failed to create btt 0\n");
return rc;
}
- /* disable the btt */
- ndctl_btt_delete(btt);
-
/* re-create the namespace - this should auto-enable the btt */
disable_blk_namespace(ndns);
ndns = create_blk_namespace(1, blk_region, ns_size, uuid);
This is driven by the rationale that disabling a namespace should guarantee that the capacity it represents is not in active use upon return. However, we don't want to change the existing meaning of ndctl_namespace_disable() that simply means the namespace device is not bound to a driver. Introduce a new symbol, similar to ndctl_region_disable_invalidate(), that implies dependent objects like btt instances are destroyed. Note that we don't have an ndctl_namespace_disable_preserve() as enabling a namespace will dynamically re-establish the claim. The _invalidate() implies that the result of a prior call to ndctl_namespace_get_btt() on the same namespace is now an invalid pointer. Reported-by: Nicholas Moulin <nicholas.w.moulin@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com> --- builtin-xable-namespace.c | 2 +- lib/blk_namespaces.c | 2 +- lib/libndctl.c | 14 ++++++++++++++ lib/libndctl.sym | 1 + lib/ndctl/libndctl.h | 1 + lib/pmem_namespaces.c | 2 +- lib/test-dpa-alloc.c | 2 +- lib/test-libndctl.c | 4 ++-- lib/test-parent-uuid.c | 7 ++----- 9 files changed, 24 insertions(+), 11 deletions(-)