diff mbox

[v2,3/4] ndctl: introduce ndctl_namespace_disable_invalidate()

Message ID 20150909230137.4976.64773.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 388c4f4ec53a
Headers show

Commit Message

Dan Williams Sept. 9, 2015, 11:01 p.m. UTC
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(-)
diff mbox

Patch

diff --git a/builtin-xable-namespace.c b/builtin-xable-namespace.c
index 1ba616257f11..13a08633487a 100644
--- a/builtin-xable-namespace.c
+++ b/builtin-xable-namespace.c
@@ -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",
diff --git a/lib/blk_namespaces.c b/lib/blk_namespaces.c
index 040da41a64e3..c3fee58f793b 100644
--- a/lib/blk_namespaces.c
+++ b/lib/blk_namespaces.c
@@ -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)
diff --git a/lib/libndctl.c b/lib/libndctl.c
index 5de7359f1cc5..3f653dc06630 100644
--- a/lib/libndctl.c
+++ b/lib/libndctl.c
@@ -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)
diff --git a/lib/libndctl.sym b/lib/libndctl.sym
index 3d5603757cea..cf99d6f8d2f0 100644
--- a/lib/libndctl.sym
+++ b/lib/libndctl.sym
@@ -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;
diff --git a/lib/ndctl/libndctl.h b/lib/ndctl/libndctl.h
index 4c64f78f212c..db8345e4b4ea 100644
--- a/lib/ndctl/libndctl.h
+++ b/lib/ndctl/libndctl.h
@@ -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);
diff --git a/lib/pmem_namespaces.c b/lib/pmem_namespaces.c
index 124900269a8b..127e3bee79d8 100644
--- a/lib/pmem_namespaces.c
+++ b/lib/pmem_namespaces.c
@@ -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)
diff --git a/lib/test-dpa-alloc.c b/lib/test-dpa-alloc.c
index c5d536df3881..edc403b9f7be 100644
--- a/lib/test-dpa-alloc.c
+++ b/lib/test-dpa-alloc.c
@@ -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",
diff --git a/lib/test-libndctl.c b/lib/test-libndctl.c
index c13958334860..696f54151562 100644
--- a/lib/test-libndctl.c
+++ b/lib/test-libndctl.c
@@ -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;
 			}
diff --git a/lib/test-parent-uuid.c b/lib/test-parent-uuid.c
index cf48a8c4a58b..a9d7eb1ec2dc 100644
--- a/lib/test-parent-uuid.c
+++ b/lib/test-parent-uuid.c
@@ -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);