nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH 1/3] ndctl, check: fix a few error returns
@ 2018-03-29 23:18 Vishal Verma
  2018-03-29 23:18 ` [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno) Vishal Verma
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Vishal Verma @ 2018-03-29 23:18 UTC (permalink / raw)
  To: linux-nvdimm

We were returning a raw '-1' in one case, and a couple of other 'errno'
returns without making them negative. Fix them to make the returns
consistent.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/check.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/ndctl/check.c b/ndctl/check.c
index 57bbf3f..d2d74a2 100644
--- a/ndctl/check.c
+++ b/ndctl/check.c
@@ -139,7 +139,7 @@ static int btt_write_info(struct btt_chk *bttc, struct btt_sb *btt_sb, u64 off)
 		err(bttc, "BTT info block at offset %#lx needs to be restored\n",
 			off);
 		repair_msg(bttc);
-		return -1;
+		return -EIO;
 	}
 	info(bttc, "Restoring BTT info block at offset %#lx\n", off);
 
@@ -184,7 +184,7 @@ static int btt_copy_to_info2(struct arena_info *a)
 	ms_align = (void *)rounddown((u64)a->map.info2, a->bttc->sys_page_size);
 	ms_size = max(BTT_INFO_SIZE, a->bttc->sys_page_size);
 	if (msync(ms_align, ms_size, MS_SYNC) < 0)
-		return errno;
+		return -errno;
 
 	return 0;
 }
@@ -231,7 +231,7 @@ static int btt_map_write(struct arena_info *a, u32 lba, u32 mapping)
 	ms_align = (void *)rounddown((u64)&a->map.map[lba],
 		a->bttc->sys_page_size);
 	if (msync(ms_align, a->bttc->sys_page_size, MS_SYNC) < 0)
-		return errno;
+		return -errno;
 
 	return 0;
 }
-- 
2.14.3

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

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

* [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno)
  2018-03-29 23:18 [ndctl PATCH 1/3] ndctl, check: fix a few error returns Vishal Verma
@ 2018-03-29 23:18 ` Vishal Verma
  2018-03-29 23:28   ` Dan Williams
  2018-03-29 23:18 ` [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Vishal Verma
  2018-03-29 23:27 ` [ndctl PATCH 1/3] ndctl, check: fix a few error returns Dan Williams
  2 siblings, 1 reply; 6+ messages in thread
From: Vishal Verma @ 2018-03-29 23:18 UTC (permalink / raw)
  To: linux-nvdimm

We were incorrectly using strerror(errno) for a number of libndctl
calls, which is incorrect, as libndctl doesn't set errno.
Instead, use the return code from the API to print the error.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/inject-smart.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c
index 45dbc8d..60de9fe 100644
--- a/ndctl/inject-smart.c
+++ b/ndctl/inject-smart.c
@@ -232,8 +232,8 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
 
 	rc = ndctl_cmd_submit(st_cmd);
 	if (rc) {
-		error("%s: smart threshold command failed: %s\n",
-			name, strerror(errno));
+		error("%s: smart threshold command failed: %s (%d)\n",
+			name, strerror(abs(rc)), rc);
 		goto out;
 	}
 
@@ -272,8 +272,8 @@ static int smart_set_thresh(struct ndctl_dimm *dimm)
 
 	rc = ndctl_cmd_submit(sst_cmd);
 	if (rc)
-		error("%s: smart set threshold command failed: %s\n",
-			name, strerror(errno));
+		error("%s: smart set threshold command failed: %s (%d)\n",
+			name, strerror(abs(rc)), rc);
 
 out:
 	ndctl_cmd_unref(sst_cmd);
@@ -291,14 +291,14 @@ out:
 		} \
 		rc = ndctl_cmd_smart_inject_##arg(si_cmd, true, sctx.arg); \
 		if (rc) { \
-			error("%s: smart inject %s cmd invalid: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s cmd invalid: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		rc = ndctl_cmd_submit(si_cmd); \
 		if (rc) { \
-			error("%s: smart inject %s command failed: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s command failed: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		ndctl_cmd_unref(si_cmd); \
@@ -315,14 +315,14 @@ out:
 		} \
 		rc = ndctl_cmd_smart_inject_##arg(si_cmd, true); \
 		if (rc) { \
-			error("%s: smart inject %s cmd invalid: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s cmd invalid: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		rc = ndctl_cmd_submit(si_cmd); \
 		if (rc) { \
-			error("%s: smart inject %s command failed: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s command failed: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		ndctl_cmd_unref(si_cmd); \
-- 
2.14.3

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

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

* [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings
  2018-03-29 23:18 [ndctl PATCH 1/3] ndctl, check: fix a few error returns Vishal Verma
  2018-03-29 23:18 ` [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno) Vishal Verma
@ 2018-03-29 23:18 ` Vishal Verma
  2018-03-29 23:29   ` Dan Williams
  2018-03-29 23:27 ` [ndctl PATCH 1/3] ndctl, check: fix a few error returns Dan Williams
  2 siblings, 1 reply; 6+ messages in thread
From: Vishal Verma @ 2018-03-29 23:18 UTC (permalink / raw)
  To: linux-nvdimm

Make error messages reported to the user friendlier by replacing errno
codes wih strerror strings throughout the various ndctl utilities.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/check.c        | 32 ++++++++++++++++----------------
 ndctl/inject-error.c |  9 ++++++---
 ndctl/namespace.c    |  5 +++--
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/ndctl/check.c b/ndctl/check.c
index d2d74a2..8a71250 100644
--- a/ndctl/check.c
+++ b/ndctl/check.c
@@ -872,8 +872,8 @@ static int btt_discover_arenas(struct btt_chk *bttc)
 			}
 			ret = btt_write_info(bttc, btt_sb, cur_off);
 			if (ret) {
-				err(bttc, "Restoration of the info block failed: %d\n",
-					ret);
+				err(bttc, "Restoration of the info block failed: %s (%d)\n",
+					strerror(abs(ret)), ret);
 				goto out;
 			}
 		}
@@ -924,8 +924,8 @@ static int btt_create_mappings(struct btt_chk *bttc)
 		a->map.info = mmap(NULL, a->map.info_len, mmap_flags,
 			MAP_SHARED, bttc->fd, a->infooff);
 		if (a->map.info == MAP_FAILED) {
-			err(bttc, "mmap arena[%d].info [sz = %#lx, off = %#lx] failed: %d\n",
-				i, a->map.info_len, a->infooff, errno);
+			err(bttc, "mmap arena[%d].info [sz = %#lx, off = %#lx] failed: %s\n",
+				i, a->map.info_len, a->infooff, strerror(errno));
 			return -errno;
 		}
 
@@ -933,8 +933,8 @@ static int btt_create_mappings(struct btt_chk *bttc)
 		a->map.data = mmap(NULL, a->map.data_len, mmap_flags,
 			MAP_SHARED, bttc->fd, a->dataoff);
 		if (a->map.data == MAP_FAILED) {
-			err(bttc, "mmap arena[%d].data [sz = %#lx, off = %#lx] failed: %d\n",
-				i, a->map.data_len, a->dataoff, errno);
+			err(bttc, "mmap arena[%d].data [sz = %#lx, off = %#lx] failed: %s\n",
+				i, a->map.data_len, a->dataoff, strerror(errno));
 			return -errno;
 		}
 
@@ -942,8 +942,8 @@ static int btt_create_mappings(struct btt_chk *bttc)
 		a->map.map = mmap(NULL, a->map.map_len, mmap_flags,
 			MAP_SHARED, bttc->fd, a->mapoff);
 		if (a->map.map == MAP_FAILED) {
-			err(bttc, "mmap arena[%d].map [sz = %#lx, off = %#lx] failed: %d\n",
-				i, a->map.map_len, a->mapoff, errno);
+			err(bttc, "mmap arena[%d].map [sz = %#lx, off = %#lx] failed: %s\n",
+				i, a->map.map_len, a->mapoff, strerror(errno));
 			return -errno;
 		}
 
@@ -951,8 +951,8 @@ static int btt_create_mappings(struct btt_chk *bttc)
 		a->map.log = mmap(NULL, a->map.log_len, mmap_flags,
 			MAP_SHARED, bttc->fd, a->logoff);
 		if (a->map.log == MAP_FAILED) {
-			err(bttc, "mmap arena[%d].log [sz = %#lx, off = %#lx] failed: %d\n",
-				i, a->map.log_len, a->logoff, errno);
+			err(bttc, "mmap arena[%d].log [sz = %#lx, off = %#lx] failed: %s\n",
+				i, a->map.log_len, a->logoff, strerror(errno));
 			return -errno;
 		}
 
@@ -960,8 +960,8 @@ static int btt_create_mappings(struct btt_chk *bttc)
 		a->map.info2 = mmap(NULL, a->map.info2_len, mmap_flags,
 			MAP_SHARED, bttc->fd, a->info2off);
 		if (a->map.info2 == MAP_FAILED) {
-			err(bttc, "mmap arena[%d].info2 [sz = %#lx, off = %#lx] failed: %d\n",
-				i, a->map.info2_len, a->info2off, errno);
+			err(bttc, "mmap arena[%d].info2 [sz = %#lx, off = %#lx] failed: %s\n",
+				i, a->map.info2_len, a->info2off, strerror(errno));
 			return -errno;
 		}
 	}
@@ -1219,8 +1219,8 @@ int namespace_check(struct ndctl_namespace *ndns, bool verbose, bool force,
 	 */
 	rc = ndctl_namespace_set_raw_mode(ndns, 1);
 	if (rc < 0) {
-		err(bttc, "%s: failed to set the raw mode flag: %d\n",
-			devname, rc);
+		err(bttc, "%s: failed to set the raw mode flag: %s (%d)\n",
+			devname, strerror(abs(rc)), rc);
 		goto out_ns;
 	}
 	/*
@@ -1229,8 +1229,8 @@ int namespace_check(struct ndctl_namespace *ndns, bool verbose, bool force,
 	 */
 	rc = ndctl_namespace_enable(ndns);
 	if (rc != 0) {
-		err(bttc, "%s: failed to enable in raw mode: %d\n",
-			devname, rc);
+		err(bttc, "%s: failed to enable in raw mode: %s (%d)\n",
+			devname, strerror(abs(rc)), rc);
 		goto out_ns;
 	}
 
diff --git a/ndctl/inject-error.c b/ndctl/inject-error.c
index efa9f92..32a58a5 100644
--- a/ndctl/inject-error.c
+++ b/ndctl/inject-error.c
@@ -199,7 +199,8 @@ static int inject_error(struct ndctl_namespace *ndns, u64 offset, u64 length,
 
 	rc = ndctl_namespace_inject_error(ndns, offset, length, notify);
 	if (rc) {
-		fprintf(stderr, "Unable to inject error: %d\n", rc);
+		fprintf(stderr, "Unable to inject error: %s (%d)\n",
+			strerror(abs(rc)), rc);
 		return rc;
 	}
 
@@ -212,7 +213,8 @@ static int uninject_error(struct ndctl_namespace *ndns, u64 offset, u64 length)
 
 	rc = ndctl_namespace_uninject_error(ndns, offset, length);
 	if (rc) {
-		fprintf(stderr, "Unable to uninject error: %d\n", rc);
+		fprintf(stderr, "Unable to uninject error: %s (%d)\n",
+			strerror(abs(rc)), rc);
 		return rc;
 	}
 
@@ -232,7 +234,8 @@ static int injection_status(struct ndctl_namespace *ndns)
 
 	rc = ndctl_namespace_injection_status(ndns);
 	if (rc) {
-		fprintf(stderr, "Unable to get injection status: %d\n", rc);
+		fprintf(stderr, "Unable to get injection status: %s (%d)\n",
+			strerror(abs(rc)), rc);
 		return rc;
 	}
 
diff --git a/ndctl/namespace.c b/ndctl/namespace.c
index aef356a..1ff54e6 100644
--- a/ndctl/namespace.c
+++ b/ndctl/namespace.c
@@ -312,8 +312,9 @@ static const char *parse_namespace_options(int argc, const char **argv,
 do { \
 	int __rc = prefix##_##op(dev, p); \
 	if (__rc) { \
-		debug("%s: " #op " failed: %d\n", \
-				prefix##_get_devname(dev), __rc); \
+		debug("%s: " #op " failed: %s\n", \
+				prefix##_get_devname(dev), \
+				strerror(abs(__rc))); \
 		return __rc; \
 	} \
 } while (0)
-- 
2.14.3

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

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

* Re: [ndctl PATCH 1/3] ndctl, check: fix a few error returns
  2018-03-29 23:18 [ndctl PATCH 1/3] ndctl, check: fix a few error returns Vishal Verma
  2018-03-29 23:18 ` [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno) Vishal Verma
  2018-03-29 23:18 ` [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Vishal Verma
@ 2018-03-29 23:27 ` Dan Williams
  2 siblings, 0 replies; 6+ messages in thread
From: Dan Williams @ 2018-03-29 23:27 UTC (permalink / raw)
  To: Vishal Verma; +Cc: linux-nvdimm

On Thu, Mar 29, 2018 at 4:18 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> We were returning a raw '-1' in one case, and a couple of other 'errno'
> returns without making them negative. Fix them to make the returns
> consistent.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Looks good.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno)
  2018-03-29 23:18 ` [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno) Vishal Verma
@ 2018-03-29 23:28   ` Dan Williams
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Williams @ 2018-03-29 23:28 UTC (permalink / raw)
  To: Vishal Verma; +Cc: linux-nvdimm

On Thu, Mar 29, 2018 at 4:18 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> We were incorrectly using strerror(errno) for a number of libndctl
> calls, which is incorrect, as libndctl doesn't set errno.
> Instead, use the return code from the API to print the error.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Looks good.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings
  2018-03-29 23:18 ` [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Vishal Verma
@ 2018-03-29 23:29   ` Dan Williams
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Williams @ 2018-03-29 23:29 UTC (permalink / raw)
  To: Vishal Verma; +Cc: linux-nvdimm

On Thu, Mar 29, 2018 at 4:18 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> Make error messages reported to the user friendlier by replacing errno
> codes wih strerror strings throughout the various ndctl utilities.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Looks good.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2018-03-29 23:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-29 23:18 [ndctl PATCH 1/3] ndctl, check: fix a few error returns Vishal Verma
2018-03-29 23:18 ` [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno) Vishal Verma
2018-03-29 23:28   ` Dan Williams
2018-03-29 23:18 ` [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Vishal Verma
2018-03-29 23:29   ` Dan Williams
2018-03-29 23:27 ` [ndctl PATCH 1/3] ndctl, check: fix a few error returns Dan Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).