From patchwork Fri Dec 1 23:25:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10088291 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 9A3166035E for ; Fri, 1 Dec 2017 23:33:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 888A52A7B3 for ; Fri, 1 Dec 2017 23:33:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D1462A816; Fri, 1 Dec 2017 23:33:50 +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 0501D2A7B3 for ; Fri, 1 Dec 2017 23:33:50 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F2F8D21A10986; Fri, 1 Dec 2017 15:29:22 -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=134.134.136.65; helo=mga03.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 7B09821A10961 for ; Fri, 1 Dec 2017 15:29:21 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Dec 2017 15:33:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,347,1508828400"; d="scan'208";a="8563765" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 01 Dec 2017 15:33:47 -0800 Subject: [ndctl PATCH 12/17] ndctl, debug: improve do_cmd output for ND_CMD_CALL From: Dan Williams To: linux-nvdimm@lists.01.org Date: Fri, 01 Dec 2017 15:25:33 -0800 Message-ID: <151217073370.28402.14730045606301358395.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com> References: <151217066885.28402.7962437173336388439.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Call back to a per-dimm-family operation that can provide a text description for the function number passed in ND_CMD_CALL invocations. Signed-off-by: Dan Williams --- ndctl/lib/intel.c | 17 +++++++++++++++++ ndctl/lib/libndctl.c | 37 +++++++++++++++++++++++++------------ ndctl/lib/private.h | 2 ++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c index af13c60d4f52..3e4260f9dbd1 100644 --- a/ndctl/lib/intel.c +++ b/ndctl/lib/intel.c @@ -283,7 +283,24 @@ intel_smart_set_threshold_field(spares) intel_smart_set_threshold_field(media_temperature) intel_smart_set_threshold_field(ctrl_temperature) +static const char *intel_cmd_desc(int fn) +{ + static const char *descs[] = { + [ND_INTEL_SMART] = "smart", + [ND_INTEL_SMART_THRESHOLD] = "smart_thresh", + [ND_INTEL_SMART_SET_THRESHOLD] = "smart_set_thresh", + }; + const char *desc = descs[fn]; + + if (fn >= (int) ARRAY_SIZE(descs)) + return "unknown"; + if (!desc) + return "unknown"; + return desc; +} + struct ndctl_dimm_ops * const intel_dimm_ops = &(struct ndctl_dimm_ops) { + .cmd_desc = intel_cmd_desc, .new_smart = intel_dimm_cmd_new_smart, .smart_get_flags = intel_cmd_smart_get_flags, .smart_get_health = intel_cmd_smart_get_health, diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index d6d8a7f0c0b3..8471dd8c4f89 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -2372,26 +2372,39 @@ static int to_ioctl_cmd(int cmd, int dimm) } } +static const char *ndctl_dimm_get_cmd_subname(struct ndctl_cmd *cmd) +{ + struct ndctl_dimm *dimm = cmd->dimm; + struct ndctl_dimm_ops *ops = dimm ? dimm->ops : NULL; + + if (!dimm || cmd->type != ND_CMD_CALL || !ops || !ops->cmd_desc) + return NULL; + return ops->cmd_desc(cmd->pkg->nd_command); +} + static int do_cmd(int fd, int ioctl_cmd, struct ndctl_cmd *cmd) { int rc; u32 offset; - const char *name; + const char *name, *sub_name = NULL; + struct ndctl_dimm *dimm = cmd->dimm; struct ndctl_bus *bus = cmd_to_bus(cmd); struct ndctl_cmd_iter *iter = &cmd->iter; struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus); - if (cmd->dimm) - name = ndctl_dimm_get_cmd_name(cmd->dimm, cmd->type); - else + if (dimm) { + name = ndctl_dimm_get_cmd_name(dimm, cmd->type); + sub_name = ndctl_dimm_get_cmd_subname(cmd); + } else name = ndctl_bus_get_cmd_name(cmd->bus, cmd->type); + if (iter->total_xfer == 0) { rc = ioctl(fd, ioctl_cmd, cmd->cmd_buf); - dbg(ctx, "bus: %d dimm: %#x cmd: %s status: %d fw: %d (%s)\n", - bus->id, cmd->dimm - ? ndctl_dimm_get_handle(cmd->dimm) : 0, - name, rc, *(cmd->firmware_status), rc < 0 ? + dbg(ctx, "bus: %d dimm: %#x cmd: %s%s%s status: %d fw: %d (%s)\n", + bus->id, dimm ? ndctl_dimm_get_handle(dimm) : 0, + name, sub_name ? ":" : "", sub_name ? sub_name : "", + rc, *(cmd->firmware_status), rc < 0 ? strerror(errno) : "success"); if (rc < 0) return -errno; @@ -2421,10 +2434,10 @@ static int do_cmd(int fd, int ioctl_cmd, struct ndctl_cmd *cmd) } } - dbg(ctx, "bus: %d dimm: %#x cmd: %s total: %d max_xfer: %d status: %d fw: %d (%s)\n", - bus->id, - cmd->dimm ? ndctl_dimm_get_handle(cmd->dimm) : 0, - name, iter->total_xfer, iter->max_xfer, rc, + dbg(ctx, "bus: %d dimm: %#x cmd: %s%s%s total: %d max_xfer: %d status: %d fw: %d (%s)\n", + bus->id, dimm ? ndctl_dimm_get_handle(dimm) : 0, + name, sub_name ? ":" : "", sub_name ? sub_name : "", + iter->total_xfer, iter->max_xfer, rc, *(cmd->firmware_status), rc < 0 ? strerror(errno) : "success"); diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index 490de96f6ce6..67260970bfb2 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -260,6 +260,7 @@ struct ndctl_cmd { struct nd_cmd_ars_start ars_start[0]; struct nd_cmd_ars_status ars_status[0]; struct nd_cmd_clear_error clear_err[0]; + struct nd_cmd_pkg pkg[0]; struct ndn_pkg_hpe1 hpe1[0]; struct ndn_pkg_msft msft[0]; struct nd_pkg_intel intel[0]; @@ -278,6 +279,7 @@ struct ndctl_bb { }; struct ndctl_dimm_ops { + const char *(*cmd_desc)(int); struct ndctl_cmd *(*new_smart)(struct ndctl_dimm *); unsigned int (*smart_get_flags)(struct ndctl_cmd *); unsigned int (*smart_get_health)(struct ndctl_cmd *);