diff mbox

[ndctl,6/6] ndctl, create-namespace: set pmem namespace sector size

Message ID 149928774707.25150.9359431758968306936.stgit@dwillia2-desk3.amr.corp.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Williams July 5, 2017, 8:49 p.m. UTC
Starting with v1.2 namespace labels, the "lbasize" field is expected to
be non-zero for all namespace types.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/namespace.c |   40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)
diff mbox

Patch

diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index c28d00193a62..778a65d02c2a 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -244,18 +244,14 @@  static int set_defaults(enum namespace_action mode)
 			error("invalid sector size: %s\n", param.sector_size);
 			rc = -EINVAL;
 		}
-
-		if (param.type && param.mode && strcmp(param.type, "pmem") == 0
-				&& strcmp(param.mode, "safe") != 0) {
-			error("'pmem' namespaces do not support setting 'sector size'\n");
-			rc = -EINVAL;
-		}
-	} else if (!param.reconfig
-			&& ((param.type && strcmp(param.type, "blk") == 0)
+	} else if (!param.reconfig) {
+		if ((param.type && strcmp(param.type, "blk") == 0)
 				|| (param.mode
-					&& strcmp(param.mode, "safe") == 0))) {
+					&& strcmp(param.mode, "safe") == 0))
 			/* default sector size for blk-type or safe-mode */
 			param.sector_size = "4096";
+		else
+			param.sector_size = "512";
 	}
 
 	return rc;
@@ -356,7 +352,7 @@  static int setup_namespace(struct ndctl_region *region,
 		try(ndctl_namespace, set_size, ndns, p->size);
 	}
 
-	if (ndctl_namespace_get_type(ndns) == ND_DEVICE_NAMESPACE_BLK)
+	if (p->sector_size)
 		try(ndctl_namespace, set_sector_size, ndns, p->sector_size);
 
 	uuid_generate(uuid);
@@ -608,22 +604,36 @@  static int validate_namespace_options(struct ndctl_region *region,
 				if (ndctl_namespace_get_supported_sector_size(seed, i)
 						== p->sector_size)
 					break;
-			if (i >= num) {
+			if (i >= num)
 				debug("%s: does not support namespace sector_size %lu\n",
 						region_name, p->sector_size);
+
+			/*
+			 * Pre-4.13 kernels did not support sector sizes
+			 * for pmem namespaces. Revert to the zero
+			 * default in that case.
+			 */
+			if (i >= num && ndctl_region_get_type(region)
+					!= ND_DEVICE_REGION_BLK
+					&& (p->sector_size == 512
+						|| p->sector_size == 4096)) {
+				debug("%s: revert to default sector size\n",
+						region_name);
+				p->sector_size = 0;
+			} else if (i >= num)
 				return -EINVAL;
-			}
 		}
 	} else if (ndns) {
 		struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
 
 		if (btt)
 			p->sector_size = ndctl_btt_get_sector_size(btt);
-		else if (ndctl_namespace_get_type(ndns)
-				== ND_DEVICE_NAMESPACE_BLK)
-			p->sector_size = ndctl_namespace_get_sector_size(ndns);
 		else if (p->mode == NDCTL_NS_MODE_SAFE)
 				p->sector_size = 4096;
+		else
+			p->sector_size = ndctl_namespace_get_sector_size(ndns);
+		if (p->sector_size == UINT_MAX)
+			p->sector_size = 0;
 	}
 
 	if (param.map) {