From patchwork Sat Jan 12 01:30:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10760835 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D6CF1874 for ; Sat, 12 Jan 2019 01:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D61429F0B for ; Sat, 12 Jan 2019 01:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 41D1629F12; Sat, 12 Jan 2019 01:31:08 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 C6B3729F1D for ; Sat, 12 Jan 2019 01:31:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 52F9121BADAB9; Fri, 11 Jan 2019 17:31:07 -0800 (PST) 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=192.55.52.88; helo=mga01.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 5084B2118FF2F for ; Fri, 11 Jan 2019 17:31:06 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2019 17:31:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,467,1539673200"; d="scan'208";a="117481094" Received: from vverma7-desk1.lm.intel.com ([10.232.112.170]) by orsmga003.jf.intel.com with ESMTP; 11 Jan 2019 17:31:00 -0800 From: Vishal Verma To: Subject: [ndctl PATCH v2 1/4] libndctl, intel: Add infrastructure for firmware_status translation Date: Fri, 11 Jan 2019 18:30:32 -0700 Message-Id: <20190112013035.32087-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190112013035.32087-1-vishal.l.verma@intel.com> References: <20190112013035.32087-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ami Pathak MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Add a new routine to ndctl_dimm_ops that allows a DSM family to provide a translation routine that will translate the status codes of the result of a DSM to generic errno style error codes. To use this routine effectively, add a new wrapper around ndctl_cmd_submit (called ndctl_cmd_submit_xlat) that submits the command, and also runs it through the above translator dimm_op (if one is is defined). Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams --- ndctl/lib/intel.c | 49 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/intel.h | 1 + ndctl/lib/libndctl.c | 28 ++++++++++++++++++++++++ ndctl/lib/libndctl.sym | 6 ++++++ ndctl/lib/private.h | 1 + ndctl/libndctl.h | 3 +++ 6 files changed, 88 insertions(+) diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c index 744386f..d684bac 100644 --- a/ndctl/lib/intel.c +++ b/ndctl/lib/intel.c @@ -16,6 +16,54 @@ #include #include "private.h" +static int intel_cmd_xlat_firmware_status(struct ndctl_cmd *cmd) +{ + struct nd_pkg_intel *pkg = cmd->intel; + unsigned int status, ext_status; + + status = (*cmd->firmware_status) & ND_INTEL_STATUS_MASK; + ext_status = (*cmd->firmware_status) & ND_INTEL_STATUS_EXTEND_MASK; + + /* Common statuses */ + switch (status) { + case ND_INTEL_STATUS_SUCCESS: + return 0; + case ND_INTEL_STATUS_NOTSUPP: + return -EOPNOTSUPP; + case ND_INTEL_STATUS_NOTEXIST: + return -ENXIO; + case ND_INTEL_STATUS_INVALPARM: + return -EINVAL; + case ND_INTEL_STATUS_HWERR: + return -EIO; + case ND_INTEL_STATUS_RETRY: + return -EAGAIN; + case ND_INTEL_STATUS_EXTEND: + /* refer to extended status, break out of this */ + break; + case ND_INTEL_STATUS_NORES: + return -EAGAIN; + case ND_INTEL_STATUS_NOTREADY: + return -EBUSY; + } + + /* Extended status is command specific */ + switch (pkg->gen.nd_command) { + case ND_INTEL_SMART: + case ND_INTEL_SMART_THRESHOLD: + case ND_INTEL_SMART_SET_THRESHOLD: + /* ext status not specified */ + break; + case ND_INTEL_SMART_INJECT: + /* smart injection not enabled */ + if (ext_status == ND_INTEL_STATUS_INJ_DISABLED) + return -ENXIO; + break; + } + + return -ENOMSG; +} + static struct ndctl_cmd *alloc_intel_cmd(struct ndctl_dimm *dimm, unsigned func, size_t in_size, size_t out_size) { @@ -780,4 +828,5 @@ struct ndctl_dimm_ops * const intel_dimm_ops = &(struct ndctl_dimm_ops) { .fw_xlat_firmware_status = intel_cmd_fw_xlat_firmware_status, .new_ack_shutdown_count = intel_dimm_cmd_new_lss, .fw_update_supported = intel_dimm_fw_update_supported, + .xlat_firmware_status = intel_cmd_xlat_firmware_status, }; diff --git a/ndctl/lib/intel.h b/ndctl/lib/intel.h index 3b01bba..530c996 100644 --- a/ndctl/lib/intel.h +++ b/ndctl/lib/intel.h @@ -179,5 +179,6 @@ struct nd_pkg_intel { #define ND_INTEL_STATUS_FQ_BUSY 0x20000 #define ND_INTEL_STATUS_FQ_BAD 0x30000 #define ND_INTEL_STATUS_FQ_ORDER 0x40000 +#define ND_INTEL_STATUS_INJ_DISABLED 0x10000 #endif /* __INTEL_H__ */ diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index e82a08d..830b791 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -2704,6 +2704,16 @@ static const char *ndctl_dimm_get_cmd_subname(struct ndctl_cmd *cmd) return ops->cmd_desc(cmd->pkg->nd_command); } +NDCTL_EXPORT int ndctl_cmd_xlat_firmware_status(struct ndctl_cmd *cmd) +{ + struct ndctl_dimm *dimm = cmd->dimm; + struct ndctl_dimm_ops *ops = dimm ? dimm->ops : NULL; + + if (!dimm || !ops || !ops->xlat_firmware_status) + return -ENOMSG; + return ops->xlat_firmware_status(cmd); +} + static int do_cmd(int fd, int ioctl_cmd, struct ndctl_cmd *cmd) { int rc; @@ -2819,6 +2829,24 @@ NDCTL_EXPORT int ndctl_cmd_submit(struct ndctl_cmd *cmd) return rc; } +NDCTL_EXPORT int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd) +{ + int rc, xlat_rc; + + rc = ndctl_cmd_submit(cmd); + if (rc < 0) + return rc; + + /* + * NOTE: This can lose a positive rc when xlat_rc is non-zero. The + * positive rc indicates a buffer underrun from the original command + * submission. If the caller cares about that (generally not very + * useful), then the xlat function is available separately as well. + */ + xlat_rc = ndctl_cmd_xlat_firmware_status(cmd); + return (xlat_rc == 0) ? rc : xlat_rc; +} + NDCTL_EXPORT int ndctl_cmd_get_status(struct ndctl_cmd *cmd) { return cmd->status; diff --git a/ndctl/lib/libndctl.sym b/ndctl/lib/libndctl.sym index 6c4c8b4..275db92 100644 --- a/ndctl/lib/libndctl.sym +++ b/ndctl/lib/libndctl.sym @@ -385,3 +385,9 @@ global: ndctl_namespace_get_next_badblock; ndctl_dimm_get_dirty_shutdown; } LIBNDCTL_17; + +LIBNDCTL_19 { +global: + ndctl_cmd_xlat_firmware_status; + ndctl_cmd_submit_xlat; +} LIBNDCTL_18; diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index 4fbea56..a387b0b 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -338,6 +338,7 @@ struct ndctl_dimm_ops { enum ND_FW_STATUS (*fw_xlat_firmware_status)(struct ndctl_cmd *); struct ndctl_cmd *(*new_ack_shutdown_count)(struct ndctl_dimm *); int (*fw_update_supported)(struct ndctl_dimm *); + int (*xlat_firmware_status)(struct ndctl_cmd *); }; struct ndctl_dimm_ops * const intel_dimm_ops; diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h index c81cc03..e55a593 100644 --- a/ndctl/libndctl.h +++ b/ndctl/libndctl.h @@ -681,6 +681,9 @@ enum ND_FW_STATUS ndctl_cmd_fw_xlat_firmware_status(struct ndctl_cmd *cmd); struct ndctl_cmd *ndctl_dimm_cmd_new_ack_shutdown_count(struct ndctl_dimm *dimm); int ndctl_dimm_fw_update_supported(struct ndctl_dimm *dimm); +int ndctl_cmd_xlat_firmware_status(struct ndctl_cmd *cmd); +int ndctl_cmd_submit_xlat(struct ndctl_cmd *cmd); + #ifdef __cplusplus } /* extern "C" */ #endif From patchwork Sat Jan 12 01:30:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10760837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B87C791E for ; Sat, 12 Jan 2019 01:31:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA5EE29F0B for ; Sat, 12 Jan 2019 01:31:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E88529F1B; Sat, 12 Jan 2019 01:31:10 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 4F4EC29F0B for ; Sat, 12 Jan 2019 01:31:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 666BE21CB74A4; Fri, 11 Jan 2019 17:31:07 -0800 (PST) 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=192.55.52.88; helo=mga01.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 6BB65211A1E3B for ; Fri, 11 Jan 2019 17:31:06 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2019 17:31:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,467,1539673200"; d="scan'208";a="117481095" Received: from vverma7-desk1.lm.intel.com ([10.232.112.170]) by orsmga003.jf.intel.com with ESMTP; 11 Jan 2019 17:31:00 -0800 From: Vishal Verma To: Subject: [ndctl PATCH v2 2/4] ndctl, inject-smart: switch to ndctl_cmd_submit_xlat Date: Fri, 11 Jan 2019 18:30:33 -0700 Message-Id: <20190112013035.32087-3-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190112013035.32087-1-vishal.l.verma@intel.com> References: <20190112013035.32087-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ami Pathak MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The ndctl inject-smart command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission. Reported-by: Ami Pathak Cc: Dan Williams Signed-off-by: Vishal Verma --- ndctl/inject-smart.c | 16 ++++++++-------- ndctl/util/json-smart.c | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c index eaa137a..00c81b8 100644 --- a/ndctl/inject-smart.c +++ b/ndctl/inject-smart.c @@ -280,8 +280,8 @@ static int smart_set_thresh(struct ndctl_dimm *dimm) goto out; } - rc = ndctl_cmd_submit(st_cmd); - if (rc) { + rc = ndctl_cmd_submit_xlat(st_cmd); + if (rc < 0) { error("%s: smart threshold command failed: %s (%d)\n", name, strerror(abs(rc)), rc); goto out; @@ -320,8 +320,8 @@ static int smart_set_thresh(struct ndctl_dimm *dimm) ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm); } - rc = ndctl_cmd_submit(sst_cmd); - if (rc) + rc = ndctl_cmd_submit_xlat(sst_cmd); + if (rc < 0) error("%s: smart set threshold command failed: %s (%d)\n", name, strerror(abs(rc)), rc); @@ -351,8 +351,8 @@ out: if (sctx.err_continue == false) \ goto out; \ } \ - rc = ndctl_cmd_submit(si_cmd); \ - if (rc) { \ + rc = ndctl_cmd_submit_xlat(si_cmd); \ + if (rc < 0) { \ error("%s: smart inject %s command failed: %s (%d)\n", \ name, #arg, strerror(abs(rc)), rc); \ if (sctx.err_continue == false) \ @@ -382,8 +382,8 @@ out: if (sctx.err_continue == false) \ goto out; \ } \ - rc = ndctl_cmd_submit(si_cmd); \ - if (rc) { \ + rc = ndctl_cmd_submit_xlat(si_cmd); \ + if (rc < 0) { \ error("%s: smart inject %s command failed: %s (%d)\n", \ name, #arg, strerror(abs(rc)), rc); \ if (sctx.err_continue == false) \ diff --git a/ndctl/util/json-smart.c b/ndctl/util/json-smart.c index 3c1b917..92a9313 100644 --- a/ndctl/util/json-smart.c +++ b/ndctl/util/json-smart.c @@ -30,8 +30,8 @@ static void smart_threshold_to_json(struct ndctl_dimm *dimm, if (!cmd) return; - rc = ndctl_cmd_submit(cmd); - if (rc || ndctl_cmd_get_firmware_status(cmd)) + rc = ndctl_cmd_submit_xlat(cmd); + if ((rc < 0) || ndctl_cmd_get_firmware_status(cmd)) goto out; alarm_control = ndctl_cmd_smart_threshold_get_alarm_control(cmd); @@ -115,8 +115,8 @@ struct json_object *util_dimm_health_to_json(struct ndctl_dimm *dimm) if (!cmd) goto err; - rc = ndctl_cmd_submit(cmd); - if (rc || ndctl_cmd_get_firmware_status(cmd)) { + rc = ndctl_cmd_submit_xlat(cmd); + if ((rc < 0) || ndctl_cmd_get_firmware_status(cmd)) { jobj = json_object_new_string("unknown"); if (jobj) json_object_object_add(jhealth, "health_state", jobj); From patchwork Sat Jan 12 01:30:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10760831 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E317F91E for ; Sat, 12 Jan 2019 01:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3C2A29F0B for ; Sat, 12 Jan 2019 01:31:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6D0729F1E; Sat, 12 Jan 2019 01:31:07 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 6D7DB29F0B for ; Sat, 12 Jan 2019 01:31:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 25302211B6C3B; Fri, 11 Jan 2019 17:31:07 -0800 (PST) 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=192.55.52.88; helo=mga01.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 118632118FF2F for ; Fri, 11 Jan 2019 17:31:05 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2019 17:31:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,467,1539673200"; d="scan'208";a="117481096" Received: from vverma7-desk1.lm.intel.com ([10.232.112.170]) by orsmga003.jf.intel.com with ESMTP; 11 Jan 2019 17:31:00 -0800 From: Vishal Verma To: Subject: [ndctl PATCH v2 3/4] ndctl, monitor: switch to ndctl_cmd_submit_xlat Date: Fri, 11 Jan 2019 18:30:34 -0700 Message-Id: <20190112013035.32087-4-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190112013035.32087-1-vishal.l.verma@intel.com> References: <20190112013035.32087-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ami Pathak MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The ndctl monitor command was neglecting to check the 'firmware_status' field that is set by the platform firmware to indicate failure. Use the new ndctl_cmd_submit_xlat facility to include the firmware_status check as part of the command submission. Cc: QI Fuli Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams --- ndctl/monitor.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 233f2bb..4ad1429 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -226,7 +226,7 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm) err(&monitor, "%s: no smart threshold command support\n", name); goto out; } - if (ndctl_cmd_submit(st_cmd)) { + if (ndctl_cmd_submit_xlat(st_cmd) < 0) { err(&monitor, "%s: smart threshold command failed\n", name); goto out; } @@ -246,8 +246,8 @@ static int enable_dimm_supported_threshold_alarms(struct ndctl_dimm *dimm) alarm |= ND_SMART_CTEMP_TRIP; ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, alarm); - rc = ndctl_cmd_submit(sst_cmd); - if (rc) { + rc = ndctl_cmd_submit_xlat(sst_cmd); + if (rc < 0) { err(&monitor, "%s: smart set threshold command failed\n", name); goto out; } From patchwork Sat Jan 12 01:30:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 10760839 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 309BD17FB for ; Sat, 12 Jan 2019 01:31:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2169329F0B for ; Sat, 12 Jan 2019 01:31:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 159C729F15; Sat, 12 Jan 2019 01:31:11 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 751B829F12 for ; Sat, 12 Jan 2019 01:31:10 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 79F1A211B6C32; Fri, 11 Jan 2019 17:31:07 -0800 (PST) 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=192.55.52.88; helo=mga01.intel.com; envelope-from=vishal.l.verma@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 8F5342118FF2F for ; Fri, 11 Jan 2019 17:31:06 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2019 17:31:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,467,1539673200"; d="scan'208";a="117481097" Received: from vverma7-desk1.lm.intel.com ([10.232.112.170]) by orsmga003.jf.intel.com with ESMTP; 11 Jan 2019 17:31:01 -0800 From: Vishal Verma To: Subject: [ndctl PATCH v2 4/4] ndctl: clean up usage of ndctl_cmd_submit Date: Fri, 11 Jan 2019 18:30:35 -0700 Message-Id: <20190112013035.32087-5-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190112013035.32087-1-vishal.l.verma@intel.com> References: <20190112013035.32087-1-vishal.l.verma@intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ami Pathak MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP It is possible for ndctl_cmd_submit to return a positive number, indicating a buffer underrun. It is only truly an error if it returns a negative number. Several places in the library, the ndctl utility, and in test/ were simply checking for an error with "if (rc)". Fix these to only error out for negative returns. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams --- ndctl/lib/dimm.c | 6 +++--- ndctl/lib/inject.c | 8 ++++---- ndctl/lib/nfit.c | 2 +- ndctl/util/json-firmware.c | 2 +- test/daxdev-errors.c | 8 ++++---- test/libndctl.c | 18 +++++++++--------- test/smart-notify.c | 8 ++++---- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ndctl/lib/dimm.c b/ndctl/lib/dimm.c index 79e2ca0..12dc74a 100644 --- a/ndctl/lib/dimm.c +++ b/ndctl/lib/dimm.c @@ -332,7 +332,7 @@ static int nvdimm_set_config_data(struct nvdimm_data *ndd, size_t offset, goto out; rc = ndctl_cmd_submit(cmd_write); - if (rc || ndctl_cmd_get_firmware_status(cmd_write)) + if ((rc < 0) || ndctl_cmd_get_firmware_status(cmd_write)) rc = -ENXIO; out: ndctl_cmd_unref(cmd_write); @@ -488,14 +488,14 @@ NDCTL_EXPORT struct ndctl_cmd *ndctl_dimm_read_labels(struct ndctl_dimm *dimm) if (!cmd_size) return NULL; rc = ndctl_cmd_submit(cmd_size); - if (rc || ndctl_cmd_get_firmware_status(cmd_size)) + if ((rc < 0) || ndctl_cmd_get_firmware_status(cmd_size)) goto out_size; cmd_read = ndctl_dimm_cmd_new_cfg_read(cmd_size); if (!cmd_read) goto out_size; rc = ndctl_cmd_submit(cmd_read); - if (rc || ndctl_cmd_get_firmware_status(cmd_read)) + if ((rc < 0) || ndctl_cmd_get_firmware_status(cmd_read)) goto out_read; ndctl_cmd_unref(cmd_size); diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c index 2b0702e..c35d0f3 100644 --- a/ndctl/lib/inject.c +++ b/ndctl/lib/inject.c @@ -156,7 +156,7 @@ static int ndctl_namespace_inject_one_error(struct ndctl_namespace *ndns, (1 << ND_ARS_ERR_INJ_OPT_NOTIFY); rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { dbg(ctx, "Error submitting command: %d\n", rc); goto out; } @@ -234,7 +234,7 @@ static int ndctl_namespace_uninject_one_error(struct ndctl_namespace *ndns, err_inj_clr->err_inj_clr_spa_range_length = length; rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { dbg(ctx, "Error submitting command: %d\n", rc); goto out; } @@ -443,7 +443,7 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns) cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size); rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { dbg(ctx, "Error submitting ars_cap: %d\n", rc); goto out; } @@ -464,7 +464,7 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns) (struct nd_cmd_ars_err_inj_stat *)&pkg->nd_payload[0]; rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { dbg(ctx, "Error submitting command: %d\n", rc); goto out; } diff --git a/ndctl/lib/nfit.c b/ndctl/lib/nfit.c index 2ae3f07..b10edb1 100644 --- a/ndctl/lib/nfit.c +++ b/ndctl/lib/nfit.c @@ -133,7 +133,7 @@ int ndctl_bus_nfit_translate_spa(struct ndctl_bus *bus, translate_spa->spa = address; rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { ndctl_cmd_unref(cmd); return rc; } diff --git a/ndctl/util/json-firmware.c b/ndctl/util/json-firmware.c index 118424f..f7150d8 100644 --- a/ndctl/util/json-firmware.c +++ b/ndctl/util/json-firmware.c @@ -25,7 +25,7 @@ struct json_object *util_dimm_firmware_to_json(struct ndctl_dimm *dimm, goto err; rc = ndctl_cmd_submit(cmd); - if (rc || ndctl_cmd_fw_xlat_firmware_status(cmd) != FW_SUCCESS) { + if ((rc < 0) || ndctl_cmd_fw_xlat_firmware_status(cmd) != FW_SUCCESS) { jobj = util_json_object_hex(-1, flags); if (jobj) json_object_object_add(jfirmware, "current_version", diff --git a/test/daxdev-errors.c b/test/daxdev-errors.c index 94fbebe..29de16b 100644 --- a/test/daxdev-errors.c +++ b/test/daxdev-errors.c @@ -75,7 +75,7 @@ static int check_ars_cap(struct ndctl_bus *bus, uint64_t start, } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: bus: %s failed to submit cmd: %d\n", __func__, ndctl_bus_get_provider(bus), rc); ndctl_cmd_unref(cmd); @@ -115,7 +115,7 @@ static int check_ars_start(struct ndctl_bus *bus, struct check_cmd *check) } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: bus: %s failed to submit cmd: %d\n", __func__, ndctl_bus_get_provider(bus), rc); ndctl_cmd_unref(cmd); @@ -149,7 +149,7 @@ static int check_ars_status(struct ndctl_bus *bus, struct check_cmd *check) } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: bus: %s failed to submit cmd: %d\n", __func__, ndctl_bus_get_provider(bus), rc); ndctl_cmd_unref(cmd); @@ -210,7 +210,7 @@ static int check_clear_error(struct ndctl_bus *bus, struct check_cmd *check) } rc = ndctl_cmd_submit(clear_err); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: bus: %s failed to submit cmd: %d\n", __func__, ndctl_bus_get_provider(bus), rc); ndctl_cmd_unref(clear_err); diff --git a/test/libndctl.c b/test/libndctl.c index 50365f0..59f68d8 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -2057,7 +2057,7 @@ static int check_get_config_size(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %d\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2091,7 +2091,7 @@ static int check_get_config_data(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %zd\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2127,7 +2127,7 @@ static int check_set_config_data(struct ndctl_bus *bus, struct ndctl_dimm *dimm, memset(buf, 0, sizeof(buf)); ndctl_cmd_cfg_write_set_data(cmd, buf, sizeof(buf), 0); rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %zd\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2135,7 +2135,7 @@ static int check_set_config_data(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd_read); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit read1: %zd\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2152,7 +2152,7 @@ static int check_set_config_data(struct ndctl_bus *bus, struct ndctl_dimm *dimm, sprintf(buf, "dimm-%#x", ndctl_dimm_get_handle(dimm)); ndctl_cmd_cfg_write_set_data(cmd, buf, sizeof(buf), 0); rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %zd\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2160,7 +2160,7 @@ static int check_set_config_data(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd_read); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit read2: %zd\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2225,7 +2225,7 @@ static int check_smart(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %d\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2326,7 +2326,7 @@ static int check_smart_threshold(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd: %d\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd); @@ -2375,7 +2375,7 @@ static int check_smart_threshold(struct ndctl_bus *bus, struct ndctl_dimm *dimm, } rc = ndctl_cmd_submit(cmd_set); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: dimm: %#x failed to submit cmd_set: %d\n", __func__, ndctl_dimm_get_handle(dimm), rc); ndctl_cmd_unref(cmd_set); diff --git a/test/smart-notify.c b/test/smart-notify.c index 24e9a21..e28e0f4 100644 --- a/test/smart-notify.c +++ b/test/smart-notify.c @@ -22,7 +22,7 @@ static void do_notify(struct ndctl_dimm *dimm) } rc = ndctl_cmd_submit(s_cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: smart command failed: %d %s\n", name, rc, strerror(errno)); goto out; @@ -49,7 +49,7 @@ static void do_notify(struct ndctl_dimm *dimm) } rc = ndctl_cmd_submit(st_cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: smart threshold command failed: %d %s\n", name, rc, strerror(errno)); goto out; @@ -148,7 +148,7 @@ static void do_notify(struct ndctl_dimm *dimm) ndctl_cmd_smart_threshold_set_alarm_control(sst_cmd, set_alarm); rc = ndctl_cmd_submit(sst_cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: smart set threshold command failed: %d %s\n", name, rc, strerror(errno)); goto out; @@ -166,7 +166,7 @@ static void do_notify(struct ndctl_dimm *dimm) } rc = ndctl_cmd_submit(sst_cmd); - if (rc) { + if (rc < 0) { fprintf(stderr, "%s: smart set threshold defaults failed: %d %s\n", name, rc, strerror(errno)); goto out;