All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] ndctl: rename parse_lbasize to parse_sizes
@ 2017-04-27  9:14 Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices Oliver O'Halloran
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Oliver O'Halloran @ 2017-04-27  9:14 UTC (permalink / raw)
  To: linux-nvdimm

We want to re-use this code to parse the list of supported alignments
for dax and PFN devices so rename the function to reflect the more
generic usage.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 ndctl/lib/libndctl.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 565c969170ce..25a1e6d20d10 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -230,12 +230,12 @@ struct ndctl_region {
 };
 
 /**
- * struct ndctl_lbasize - lbasize info for btt and blk-namespace devices
+ * struct ndctl_sizes - list of supported sector or alignments
  * @select: currently selected sector_size
  * @supported: possible sector_size options
  * @num: number of entries in @supported
  */
-struct ndctl_lbasize {
+struct ndctl_sizes {
 	int select;
 	unsigned int *supported;
 	int num;
@@ -266,7 +266,7 @@ struct ndctl_namespace {
 	unsigned long long resource, size;
 	char *alt_name;
 	uuid_t uuid;
-	struct ndctl_lbasize lbasize;
+	struct ndctl_sizes lbasize;
 	int numa_node;
 };
 
@@ -287,7 +287,7 @@ struct ndctl_btt {
 	struct ndctl_region *region;
 	struct ndctl_namespace *ndns;
 	struct list_node list;
-	struct ndctl_lbasize lbasize;
+	struct ndctl_sizes lbasize;
 	unsigned long long size;
 	char *btt_path;
 	char *btt_buf;
@@ -2735,8 +2735,8 @@ static char *get_block_device(struct ndctl_ctx *ctx, const char *block_path)
 	return bdev_name;
 }
 
-static int parse_lbasize_supported(struct ndctl_ctx *ctx, const char *devname,
-		const char *buf, struct ndctl_lbasize *lba);
+static int parse_sizes(struct ndctl_ctx *ctx, const char *devname,
+		const char *buf, struct ndctl_sizes *lba);
 
 static void *add_namespace(void *parent, int id, const char *ndns_base)
 {
@@ -2788,7 +2788,7 @@ static void *add_namespace(void *parent, int id, const char *ndns_base)
 		sprintf(path, "%s/sector_size", ndns_base);
 		if (sysfs_read_attr(ctx, path, buf) < 0)
 			goto err_read;
-		if (parse_lbasize_supported(ctx, devname, buf, &ndns->lbasize) < 0)
+		if (parse_sizes(ctx, devname, buf, &ndns->lbasize) < 0)
 			goto err_read;
 		/* fall through */
 	case ND_DEVICE_NAMESPACE_PMEM:
@@ -3559,8 +3559,8 @@ NDCTL_EXPORT int ndctl_namespace_delete(struct ndctl_namespace *ndns)
 	return 0;
 }
 
-static int parse_lbasize_supported(struct ndctl_ctx *ctx, const char *devname,
-		const char *buf, struct ndctl_lbasize *lba)
+static int parse_sizes(struct ndctl_ctx *ctx, const char *devname,
+		const char *buf, struct ndctl_sizes *lba)
 {
 	char *s = strdup(buf), *end, *field;
 	void *temp;
@@ -3651,7 +3651,7 @@ static void *add_btt(void *parent, int id, const char *btt_base)
 	sprintf(path, "%s/sector_size", btt_base);
 	if (sysfs_read_attr(ctx, path, buf) < 0)
 		goto err_read;
-	if (parse_lbasize_supported(ctx, devname, buf, &btt->lbasize) < 0)
+	if (parse_sizes(ctx, devname, buf, &btt->lbasize) < 0)
 		goto err_read;
 
 	sprintf(path, "%s/size", btt_base);
-- 
2.9.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices
  2017-04-27  9:14 [PATCH 1/4] ndctl: rename parse_lbasize to parse_sizes Oliver O'Halloran
@ 2017-04-27  9:14 ` Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 3/4] ndctl, create-namespace: use seed device to check dax alignment Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 4/4] ndctl: print alignment for dax and pfn devs Oliver O'Halloran
  2 siblings, 0 replies; 4+ messages in thread
From: Oliver O'Halloran @ 2017-04-27  9:14 UTC (permalink / raw)
  To: linux-nvdimm

Newer kernels advertise the list of alignments that they support
through sysfs. This patch adds parsing inside of libndctl to
determine the alignments permitted.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 ndctl/lib/libndctl.c   | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ndctl/lib/libndctl.sym |  4 ++++
 ndctl/libndctl.h.in    |  4 ++++
 3 files changed, 61 insertions(+)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index 25a1e6d20d10..f9bc4ee72bb8 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -34,6 +34,7 @@
 #include <ndctl.h>
 #endif
 
+#include <util/size.h>
 #include <util/sysfs.h>
 #include <ndctl/libndctl.h>
 #include <daxctl/libdaxctl.h>
@@ -323,6 +324,8 @@ struct ndctl_pfn {
 	int buf_len;
 	uuid_t uuid;
 	int id, generation;
+	struct ndctl_sizes alignments;
+	unsigned long default_align;
 };
 
 struct ndctl_dax {
@@ -4025,6 +4028,29 @@ static void *__add_pfn(struct ndctl_pfn *pfn, const char *pfn_base)
 	else
 		pfn->size = strtoull(buf, NULL, 0);
 
+	/*
+	 * Newer kernels explicitly state what they support with the
+	 * supported_alignments attribuate and older kernels only
+	 * support 4K, 2M or 1G alignments.
+	 */
+	sprintf(path, "%s/supported_alignments", pfn_base);
+	if (!sysfs_read_attr(ctx, path, buf)) {
+		if (parse_sizes(ctx, devpath_to_devname(pfn_base),
+				buf, &pfn->alignments)) {
+			goto err_read;
+		}
+
+		sprintf(path, "%s/default_alignment", pfn_base);
+		if (sysfs_read_attr(ctx, path, buf) < 0)
+			goto err_read;
+
+		pfn->default_align = strtoull(buf, NULL, 0);
+	} else {
+		pfn->alignments.supported =
+			(unsigned int []) {SZ_4K, SZ_2M, SZ_1G};
+		pfn->default_align = SZ_2M;
+	}
+
 	free(path);
 	return pfn;
 
@@ -4256,6 +4282,22 @@ NDCTL_EXPORT int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align)
 	return 0;
 }
 
+NDCTL_EXPORT unsigned long ndctl_pfn_def_align(struct ndctl_pfn *pfn)
+{
+	return pfn->default_align;
+}
+
+NDCTL_EXPORT int ndctl_pfn_supports_align(struct ndctl_pfn *pfn,
+		unsigned long align)
+{
+	int i;
+
+	for (i = 0; i < pfn->alignments.num; i++)
+		if (pfn->alignments.supported[i] == align)
+			return true;
+	return false;
+}
+
 NDCTL_EXPORT int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn,
 		struct ndctl_namespace *ndns)
 {
@@ -4482,6 +4524,17 @@ NDCTL_EXPORT int ndctl_dax_has_align(struct ndctl_dax *dax)
 	return ndctl_pfn_has_align(&dax->pfn);
 }
 
+NDCTL_EXPORT unsigned long ndctl_dax_def_align(struct ndctl_dax *dax)
+{
+	return ndctl_pfn_def_align(&dax->pfn);
+}
+
+NDCTL_EXPORT int ndctl_dax_supports_align(struct ndctl_dax *dax,
+		unsigned long align)
+{
+	return ndctl_pfn_supports_align(&dax->pfn, align);
+}
+
 NDCTL_EXPORT int ndctl_dax_set_align(struct ndctl_dax *dax, unsigned long align)
 {
 	return ndctl_pfn_set_align(&dax->pfn, align);
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index be2e3680d202..fa60dfb82a9e 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -231,6 +231,8 @@ global:
 	ndctl_pfn_get_location;
 	ndctl_pfn_set_location;
 	ndctl_pfn_get_align;
+	ndctl_pfn_def_align;
+	ndctl_pfn_supports_align;
 	ndctl_pfn_get_size;
 	ndctl_pfn_get_resource;
 	ndctl_pfn_has_align;
@@ -259,6 +261,8 @@ global:
 	ndctl_dax_get_location;
 	ndctl_dax_set_location;
 	ndctl_dax_get_align;
+	ndctl_dax_def_align;
+	ndctl_dax_supports_align;
 	ndctl_dax_has_align;
 	ndctl_dax_set_align;
 	ndctl_dax_set_namespace;
diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in
index c27581d939c5..be0e20b706fa 100644
--- a/ndctl/libndctl.h.in
+++ b/ndctl/libndctl.h.in
@@ -572,6 +572,8 @@ void ndctl_pfn_get_uuid(struct ndctl_pfn *pfn, uuid_t uu);
 int ndctl_pfn_has_align(struct ndctl_pfn *pfn);
 int ndctl_pfn_set_align(struct ndctl_pfn *pfn, unsigned long align);
 unsigned long ndctl_pfn_get_align(struct ndctl_pfn *pfn);
+unsigned long ndctl_pfn_def_align(struct ndctl_pfn *pfn);
+int ndctl_pfn_supports_align(struct ndctl_pfn *pfn, unsigned long align);
 unsigned long long ndctl_pfn_get_resource(struct ndctl_pfn *pfn);
 unsigned long long ndctl_pfn_get_size(struct ndctl_pfn *pfn);
 int ndctl_pfn_set_namespace(struct ndctl_pfn *pfn, struct ndctl_namespace *ndns);
@@ -603,6 +605,8 @@ int ndctl_dax_set_uuid(struct ndctl_dax *dax, uuid_t uu);
 enum ndctl_pfn_loc ndctl_dax_get_location(struct ndctl_dax *dax);
 int ndctl_dax_set_location(struct ndctl_dax *dax, enum ndctl_pfn_loc loc);
 unsigned long ndctl_dax_get_align(struct ndctl_dax *dax);
+unsigned long ndctl_dax_def_align(struct ndctl_dax *dax);
+int ndctl_dax_supports_align(struct ndctl_dax *dax, unsigned long align);
 int ndctl_dax_has_align(struct ndctl_dax *dax);
 int ndctl_dax_set_align(struct ndctl_dax *dax, unsigned long align);
 int ndctl_dax_set_namespace(struct ndctl_dax *dax,
-- 
2.9.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] ndctl, create-namespace: use seed device to check dax alignment
  2017-04-27  9:14 [PATCH 1/4] ndctl: rename parse_lbasize to parse_sizes Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices Oliver O'Halloran
@ 2017-04-27  9:14 ` Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 4/4] ndctl: print alignment for dax and pfn devs Oliver O'Halloran
  2 siblings, 0 replies; 4+ messages in thread
From: Oliver O'Halloran @ 2017-04-27  9:14 UTC (permalink / raw)
  To: linux-nvdimm

The alignments supported by a dax or pfn device are depend on the fault
granularities supported by the kernel. Currently we just assume this
means 4K, 2M and 1G alignments are allowed, but now what we can query
the supported values from the seed namespace we should use that instead.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 ndctl/builtin-xaction-namespace.c | 79 +++++++++++++++++++++------------------
 1 file changed, 42 insertions(+), 37 deletions(-)

diff --git a/ndctl/builtin-xaction-namespace.c b/ndctl/builtin-xaction-namespace.c
index 46d651e86153..4fdf50ef785a 100644
--- a/ndctl/builtin-xaction-namespace.c
+++ b/ndctl/builtin-xaction-namespace.c
@@ -397,7 +397,7 @@ static int validate_namespace_options(struct ndctl_region *region,
 		struct ndctl_namespace *ndns, struct parsed_parameters *p)
 {
 	const char *region_name = ndctl_region_get_devname(region);
-	unsigned long long size_align, units = 1;
+	unsigned long long size_align = 0, units = 1;
 	unsigned int ways;
 	int rc = 0;
 
@@ -460,57 +460,62 @@ static int validate_namespace_options(struct ndctl_region *region,
 
 		p->align = parse_size64(param.align);
 
-		if (p->mode == NDCTL_NS_MODE_MEMORY && p->align != SZ_2M
-				&& (!pfn || !ndctl_pfn_has_align(pfn))) {
+		if (p->mode == NDCTL_NS_MODE_MEMORY) {
+			if (!pfn) {
+				debug("%s does not support memory mode\n",
+					region_name);
+				return -EAGAIN;
+			}
+
 			/*
 			 * Initial pfn device support in the kernel
 			 * supported a 2M default alignment when
 			 * ndctl_pfn_has_align() returns false.
 			 */
-			debug("%s not support 'align' for memory mode\n",
+			if (p->align != SZ_2M && !ndctl_pfn_has_align(pfn)) {
+				debug("%s not support 'align' for memory mode\n",
 					region_name);
-			return -EAGAIN;
-		} else if (p->mode == NDCTL_NS_MODE_DAX
-				&& (!dax || !ndctl_dax_has_align(dax))) {
+				return -EAGAIN;
+			}
+
+			if (param.align_default)
+				p->align = ndctl_pfn_def_align(pfn);
+
+			if (!ndctl_pfn_supports_align(pfn, p->align)) {
+				error("unsupported alignment for memory mode: %s\n",
+					param.align);
+				return -EINVAL;
+			}
+
+			size_align = p->align;
+		} else if (p->mode == NDCTL_NS_MODE_DAX) {
 			/*
 			 * Unlike the pfn case, we require the kernel to
 			 * have 'align' support for device-dax.
 			 */
-			debug("%s not support 'align' for dax mode\n",
-					region_name);
-			return -EAGAIN;
-		} else if (!param.align_default
-				&& (p->mode == NDCTL_NS_MODE_SAFE
-					|| p->mode == NDCTL_NS_MODE_RAW)) {
-			/*
-			 * Specifying an alignment has no effect for
-			 * raw, or btt mode namespaces.
-			 */
+			if (!dax || !ndctl_dax_has_align(dax)) {
+				debug("%s not support 'align' for dax mode\n",
+						region_name);
+				return -EAGAIN;
+			}
+
+			if (param.align_default)
+				p->align = ndctl_dax_def_align(dax);
+
+			if (!ndctl_dax_supports_align(dax, p->align)) {
+				error("unsupported alignment for dax mode: %s\n",
+					param.align);
+				return -EINVAL;
+			}
+
+			size_align = p->align;
+		} else if (!param.align_default) {
+			/* in other cases the user should not supply an alignment */
 			error("%s mode does not support setting an alignment\n",
 					p->mode == NDCTL_NS_MODE_SAFE
 					? "sector" : "raw");
 			return -ENXIO;
 		}
-
-		switch (p->align) {
-		case SZ_4K:
-		case SZ_2M:
-		case SZ_1G:
-			break;
-		default:
-			error("unsupported align: %s\n", param.align);
-			return -ENXIO;
-		}
-
-		/*
-		 * 'raw' and 'sector' mode namespaces don't support an
-		 * alignment attribute.
-		 */
-		if (p->mode == NDCTL_NS_MODE_MEMORY
-				|| p->mode == NDCTL_NS_MODE_DAX)
-			size_align = p->align;
-		else
-			size_align = SZ_4K;
 	}
 
 	/* (re-)validate that the size satisfies the alignment */
-- 
2.9.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] ndctl: print alignment for dax and pfn devs
  2017-04-27  9:14 [PATCH 1/4] ndctl: rename parse_lbasize to parse_sizes Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices Oliver O'Halloran
  2017-04-27  9:14 ` [PATCH 3/4] ndctl, create-namespace: use seed device to check dax alignment Oliver O'Halloran
@ 2017-04-27  9:14 ` Oliver O'Halloran
  2 siblings, 0 replies; 4+ messages in thread
From: Oliver O'Halloran @ 2017-04-27  9:14 UTC (permalink / raw)
  To: linux-nvdimm

It's handy to know. Doubly so if the user didn't supply an alignment.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 util/json.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/util/json.c b/util/json.c
index d6a8d4c899ed..f454163df0e9 100644
--- a/util/json.c
+++ b/util/json.c
@@ -217,6 +217,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 	struct ndctl_btt *btt;
 	struct ndctl_pfn *pfn;
 	struct ndctl_dax *dax;
+	unsigned long align = 0;
 	char buf[40];
 	uuid_t uuid;
 
@@ -283,6 +284,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 
 		bdev = ndctl_btt_get_block_device(btt);
 	} else if (pfn) {
+		align = ndctl_pfn_get_align(pfn);
 		ndctl_pfn_get_uuid(pfn, uuid);
 		uuid_unparse(uuid, buf);
 		jobj = json_object_new_string(buf);
@@ -293,6 +295,7 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 	} else if (dax) {
 		struct daxctl_region *dax_region;
 
+		align = ndctl_dax_get_align(dax);
 		ndctl_dax_get_uuid(dax, uuid);
 		uuid_unparse(uuid, buf);
 		jobj = json_object_new_string(buf);
@@ -327,6 +330,13 @@ struct json_object *util_namespace_to_json(struct ndctl_namespace *ndns,
 	} else
 		bdev = ndctl_namespace_get_block_device(ndns);
 
+	if (align) {
+		jobj = json_object_new_int64(align);
+		if (!jobj)
+			goto err;
+		json_object_object_add(jndns, "align", jobj);
+	}
+
 	if (bdev && bdev[0]) {
 		jobj = json_object_new_string(bdev);
 		if (!jobj)
-- 
2.9.3

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-27  9:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27  9:14 [PATCH 1/4] ndctl: rename parse_lbasize to parse_sizes Oliver O'Halloran
2017-04-27  9:14 ` [PATCH 2/4] ndctl: Parse supported_alignments for dax and pfn devices Oliver O'Halloran
2017-04-27  9:14 ` [PATCH 3/4] ndctl, create-namespace: use seed device to check dax alignment Oliver O'Halloran
2017-04-27  9:14 ` [PATCH 4/4] ndctl: print alignment for dax and pfn devs Oliver O'Halloran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.