diff mbox series

[ndctl] ndctl/namespace: Catch attempts to sub-divide legacy / label-less capacity

Message ID 160203920105.2317828.2025624736239651180.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State Accepted
Commit 66244ad43b2b58eebb7dc53d47a62972a04e5746
Headers show
Series [ndctl] ndctl/namespace: Catch attempts to sub-divide legacy / label-less capacity | expand

Commit Message

Dan Williams Oct. 7, 2020, 2:53 a.m. UTC
Fail attempts to specify a size smaller than the host region to
'create-namespace' when labels are not available. Otherwise ndctl
confusingly succeeds and reports that the namespace is still statically
sized to the region:

Example before:

  # ndctl create-namespace -s 32g
    "size":"63.00 GiB (67.64 GB)",

Example after:

  # ndctl create-namespace -e namespace0.0 -s 2G -f
    Error: Legacy / label-less namespaces do not support sub-dividing a region retry without -s/--size=

  failed to reconfigure namespace: Invalid argument

The memmap= parameter while useful, does not emulate many of the
provisioning flows of real persistent memory devices. The set of useful
namespace configuration that can be performed on top of memmap= defined
region+namespace is reconfiguring the namespace between operation modes:

   create-namespace -e namespace0.0 -f -m {devdax,fsdax,sector}

Link: https://github.com/pmem/ndctl/issues/150
Reported-by: Eric Sandeen <esandeen@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/namespace.c |   11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index e734248c9752..e946bb6c9bfa 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -684,6 +684,17 @@  static int validate_namespace_options(struct ndctl_region *region,
 			return rc;
 	}
 
+	/*
+	 * Block attempts to set a custom size on legacy (label-less)
+	 * namespaces
+	 */
+	if (ndctl_region_get_nstype(region) == ND_DEVICE_NAMESPACE_IO
+			&& p->size != ndctl_region_get_size(region)) {
+		error("Legacy / label-less namespaces do not support sub-dividing a region\n");
+		error("Retry without -s/--size=\n");
+		return -EINVAL;
+	}
+
 	if (param.uuid) {
 		if (uuid_parse(param.uuid, p->uuid) != 0) {
 			err("%s: invalid uuid\n", __func__);