From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings
Date: Thu, 29 Mar 2018 17:18:36 -0600 [thread overview]
Message-ID: <20180329231836.29453-3-vishal.l.verma@intel.com> (raw)
In-Reply-To: <20180329231836.29453-1-vishal.l.verma@intel.com>
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
next prev parent reply other threads:[~2018-03-29 23:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Vishal Verma [this message]
2018-03-29 23:29 ` [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Dan Williams
2018-03-29 23:27 ` [ndctl PATCH 1/3] ndctl, check: fix a few error returns Dan Williams
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=20180329231836.29453-3-vishal.l.verma@intel.com \
--to=vishal.l.verma@intel.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 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).