From patchwork Thu Mar 29 23:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10316661 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9610460353 for ; Thu, 29 Mar 2018 23:18:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83F6B2894E for ; Thu, 29 Mar 2018 23:18:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78ED12A41F; Thu, 29 Mar 2018 23:18:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DAB982894E for ; Thu, 29 Mar 2018 23:18:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 86487225501E5; Thu, 29 Mar 2018 16:12:13 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 823C0225501D9 for ; Thu, 29 Mar 2018 16:12:12 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Mar 2018 16:18:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,378,1517904000"; d="scan'208";a="46452639" Received: from littlefp-mobl.amr.corp.intel.com (HELO vverma7-mobl4.lm.intel.com) ([10.252.136.18]) by orsmga002.jf.intel.com with ESMTP; 29 Mar 2018 16:18:52 -0700 From: Vishal Verma To: Subject: [ndctl PATCH 3/3] ndctl: replace direct errno prints with strerror strings Date: Thu, 29 Mar 2018 17:18:36 -0600 Message-Id: <20180329231836.29453-3-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180329231836.29453-1-vishal.l.verma@intel.com> References: <20180329231836.29453-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Make error messages reported to the user friendlier by replacing errno codes wih strerror strings throughout the various ndctl utilities. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams --- 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)