Skip to contentSkip to conversation

ndctl, check: fix a few error returns

PATCH In review Vishal Verma 2 participants 6 messages Mar 29, 2018 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/3 ndctl, check: fix a few error returns

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.

---
 ndctl/check.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
ndctl/check.c +3 -3
index 57bbf3f..d2d74a2 100644
@@ -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;
 }
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author maintainer
#1 lore raw

PATCH 2/3 ndctl, inject-smart: fix usage of strerror(errno)

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.

---
 ndctl/inject-smart.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
ndctl/inject-smart.c +12 -12
index 45dbc8d..60de9fe 100644
@@ -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); \
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Reviewed-by on v1 2/3
#2 lore raw

Re: [ndctl PATCH 2/3] ndctl, inject-smart: fix usage of strerror(errno)

Quoted 6 lines · Vishal Verma

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.

Looks good.

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author maintainer
#3 lore raw

PATCH 3/3 ndctl: replace direct errno prints with strerror strings

In reply to Vishal Verma

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

---
 ndctl/check.c        | 32 ++++++++++++++++----------------
 ndctl/inject-error.c |  9 ++++++---
 ndctl/namespace.c    |  5 +++--
 3 files changed, 25 insertions(+), 21 deletions(-)
ndctl/check.c +16 -16
index d2d74a2..8a71250 100644
@@ -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;
 	}
 
ndctl/inject-error.c +6 -3
index efa9f92..32a58a5 100644
@@ -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;
 	}
 
ndctl/namespace.c +3 -2
index aef356a..1ff54e6 100644
@@ -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)
Signature · 6 lines
2.14.3

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Reviewed-by on v1 3/3
#4 lore raw

Re: [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings

Quoted 5 lines · Vishal Verma

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

Looks good.

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

Reviewed-by on v1 1/3
#5 lore raw
In reply to Vishal Verma
Quoted 6 lines · Vishal Verma

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.

Looks good.

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm