diff mbox

ndctl: make ndctl_namspace_set_sector_size() more verbose

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

Commit Message

Dan Williams Sept. 1, 2017, 12:29 a.m. UTC
Since we already walk all the supported sector sizes in the success
case, move that loop to the start of the routine and use it for logging
bad input parameters.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 ndctl/lib/libndctl.c |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
index f52ecfe9d142..4361cd8f26c5 100644
--- a/ndctl/lib/libndctl.c
+++ b/ndctl/lib/libndctl.c
@@ -3549,8 +3549,15 @@  NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
 	char sector_str[40];
 	int i;
 
-	if (ndns->lbasize.num == 0)
-		return -ENXIO;
+	for (i = 0; i < ndns->lbasize.num; i++)
+		if (ndns->lbasize.supported[i] == sector_size)
+			break;
+
+	if (i > ndns->lbasize.num) {
+		err(ctx, "%s: unsupported sector size %d\n",
+				ndctl_namespace_get_devname(ndns), sector_size);
+		return -EOPNOTSUPP;
+	}
 
 	if (snprintf(path, len, "%s/sector_size", ndns->ndns_path) >= len) {
 		err(ctx, "%s: buffer too small!\n",
@@ -3563,9 +3570,8 @@  NDCTL_EXPORT int ndctl_namespace_set_sector_size(struct ndctl_namespace *ndns,
 	if (rc != 0)
 		return rc;
 
-	for (i = 0; i < ndns->lbasize.num; i++)
-		if (ndns->lbasize.supported[i] == sector_size)
-			ndns->lbasize.select = i;
+	ndns->lbasize.select = i;
+
 	return 0;
 }