All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver O'Halloran <oohall@gmail.com>
To: linux-nvdimm@lists.01.org
Subject: [PATCH 3/4] libndctl: Add helpers to check supported sector sizes
Date: Tue, 27 Jun 2017 18:15:30 +1000	[thread overview]
Message-ID: <20170627081531.7389-3-oohall@gmail.com> (raw)
In-Reply-To: <20170627081531.7389-1-oohall@gmail.com>

libndctl now has the ndctl_{dax|pfn}_supports_align() helper functions
for checking if PFN and DAX regions support a given alignment. The
sector size of a BTT region is similar to the region alignment so add an
equivilent helper to maintain a consistent API across region types.

Adds:
	ndctl_namespace_supports_sector_size()
	ndctl_btt_supports_sector_size()

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 ndctl/lib/libndctl.c   | 12 ++++++++++++
 ndctl/lib/libndctl.sym |  2 ++
 ndctl/libndctl.h.in    |  3 +++
 ndctl/namespace.c      | 30 ++++++++++++------------------
 4 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index d21d372891a4..9668d8c5d34e 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -3586,6 +3586,12 @@ NDCTL_EXPORT int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *nd
 	return ndns->lbasize.num;
 }
 
+NDCTL_EXPORT int ndctl_namespace_supports_sector_size(
+		struct ndctl_namespace *ndns, unsigned long size)
+{
+	return sizes_contains(&ndns->lbasize, size);
+}
+
 NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
 		unsigned int sector_size)
 {
@@ -3912,6 +3918,12 @@ NDCTL_EXPORT int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt)
 	return btt->lbasize.num;
 }
 
+NDCTL_EXPORT int ndctl_btt_supports_sector_size(
+		struct ndctl_btt *btt, unsigned long size)
+{
+	return sizes_contains(&btt->lbasize, size);
+}
+
 NDCTL_EXPORT struct ndctl_namespace *ndctl_btt_get_namespace(struct ndctl_btt *btt)
 {
 	struct ndctl_ctx *ctx = ndctl_btt_get_ctx(btt);
diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym
index 547d1bf133c6..4039f7311222 100644
--- a/ndctl/lib/libndctl.sym
+++ b/ndctl/lib/libndctl.sym
@@ -192,6 +192,7 @@ global:
 	ndctl_namespace_get_sector_size;
 	ndctl_namespace_get_num_sector_sizes;
 	ndctl_namespace_set_sector_size;
+	ndctl_namespace_supports_sector_size;
 	ndctl_namespace_get_raw_mode;
 	ndctl_namespace_set_raw_mode;
 	ndctl_namespace_get_numa_node;
@@ -204,6 +205,7 @@ global:
 	ndctl_btt_get_supported_sector_size;
 	ndctl_btt_get_sector_size;
 	ndctl_btt_get_num_sector_sizes;
+	ndctl_btt_supports_sector_size;
 	ndctl_btt_get_namespace;
 	ndctl_btt_get_uuid;
 	ndctl_btt_get_size;
diff --git a/ndctl/libndctl.h.in b/ndctl/libndctl.h.in
index 1d0924999b03..feefb9653c88 100644
--- a/ndctl/libndctl.h.in
+++ b/ndctl/libndctl.h.in
@@ -513,6 +513,8 @@ int ndctl_namespace_set_size(struct ndctl_namespace *ndns,
 		unsigned long long size);
 unsigned int ndctl_namespace_get_supported_sector_size(
 		struct ndctl_namespace *ndns, int i);
+int ndctl_namespace_supports_sector_size(
+		struct ndctl_namespace *ndns, unsigned long size);
 unsigned int ndctl_namespace_get_sector_size(struct ndctl_namespace *ndns);
 int ndctl_namespace_get_num_sector_sizes(struct ndctl_namespace *ndns);
 int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
@@ -538,6 +540,7 @@ struct ndctl_ctx *ndctl_btt_get_ctx(struct ndctl_btt *btt);
 struct ndctl_bus *ndctl_btt_get_bus(struct ndctl_btt *btt);
 struct ndctl_region *ndctl_btt_get_region(struct ndctl_btt *btt);
 unsigned int ndctl_btt_get_id(struct ndctl_btt *btt);
+int ndctl_btt_supports_sector_size(struct ndctl_btt *btt, unsigned long size);
 unsigned int ndctl_btt_get_supported_sector_size(struct ndctl_btt *btt, int i);
 unsigned int ndctl_btt_get_sector_size(struct ndctl_btt *btt);
 int ndctl_btt_get_num_sector_sizes(struct ndctl_btt *btt);
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index 895e39bb8c7d..0f402e8790a6 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -570,25 +570,21 @@ static int validate_namespace_options(struct ndctl_region *region,
 	}
 
 	if (param.sector_size) {
-		struct ndctl_btt *btt;
-		int num, i;
+		unsigned long long size = parse_size64(param.sector_size);
 
-		p->sector_size = parse_size64(param.sector_size);
-		btt = ndctl_region_get_btt_seed(region);
 		if (p->mode == NDCTL_NS_MODE_SAFE) {
+			struct ndctl_btt *btt =
+				ndctl_region_get_btt_seed(region);
+
 			if (!btt) {
 				debug("%s: does not support 'sector' mode\n",
 						region_name);
 				return -EINVAL;
 			}
-			num = ndctl_btt_get_num_sector_sizes(btt);
-			for (i = 0; i < num; i++)
-				if (ndctl_btt_get_supported_sector_size(btt, i)
-						== p->sector_size)
-					break;
-			if (i >= num) {
+
+			if (!ndctl_btt_supports_sector_size(btt, size)) {
 				debug("%s: does not support btt sector_size %lu\n",
-						region_name, p->sector_size);
+						region_name, size);
 				return -EINVAL;
 			}
 		} else {
@@ -596,17 +592,15 @@ static int validate_namespace_options(struct ndctl_region *region,
 
 			if (!seed)
 				seed = ndctl_region_get_namespace_seed(region);
-			num = ndctl_namespace_get_num_sector_sizes(seed);
-			for (i = 0; i < num; i++)
-				if (ndctl_namespace_get_supported_sector_size(seed, i)
-						== p->sector_size)
-					break;
-			if (i >= num) {
+
+			if (!ndctl_namespace_supports_sector_size(seed, size)) {
 				debug("%s: does not support namespace sector_size %lu\n",
-						region_name, p->sector_size);
+						region_name, size);
 				return -EINVAL;
 			}
 		}
+
+		p->sector_size = size;
 	} else if (ndns) {
 		struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
 
-- 
2.9.4

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

  parent reply	other threads:[~2017-06-27  8:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27  8:15 [PATCH 1/4] libndctl: rename parse_lbasize to parse_sizes Oliver O'Halloran
2017-06-27  8:15 ` [PATCH 2/4] libndctl: Parse supported_alignments for dax and pfn devices Oliver O'Halloran
2017-06-27  8:15 ` Oliver O'Halloran [this message]
2017-06-27  8:15 ` [PATCH 4/4] ndctl, create-namespace: use seed device to check alignments Oliver O'Halloran

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170627081531.7389-3-oohall@gmail.com \
    --to=oohall@gmail.com \
    --cc=linux-nvdimm@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.