From patchwork Sat Mar 23 04:20:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10866755 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 3FBE1922 for ; Sat, 23 Mar 2019 04:20:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09C2A2A94F for ; Sat, 23 Mar 2019 04:20:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0D212A95D; Sat, 23 Mar 2019 04:20:38 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 662F12A94F for ; Sat, 23 Mar 2019 04:20:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4EFB0211E9FA5; Fri, 22 Mar 2019 21:20:38 -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=2607:f8b0:4864:20::741; helo=mail-qk1-x741.google.com; envelope-from=dexuan.cui@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D9AE2211E95BE for ; Fri, 22 Mar 2019 21:20:36 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id o129so2458297qke.8 for ; Fri, 22 Mar 2019 21:20:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ED828ESF4TV6+QScdxw1SGHw4GXhqLFcJzI5YRL4H6E=; b=hSLraxbBBM4Vb8UMYlKCzQPlFHduWtRuk/mPzUDUVishYXNRCvpLLw6U3YQhkr1+JZ OK9FIqIu7O2VLCHE2f/68R3y3vSllkuX7TqjNf+aEjfSE7WrzoneO9jRozuaS/SajfPb tZXQO0C+ct7TfP4Vw9dAsk7/uALJXNwiR3uXgT+jACTzcorYpeLY7FBcTesuXN7okYqM khV/unNri7VGt1cnXatOLCiv26vzycLKjZ/DRruuRHgm9fSxUJcLs0BhSdhP5jZbiqaw G+WjtnHXJp6SjZN4t5PmLPlsuhDMlA0rHOtO/nmFTPZgeP1e3K1pn2isrT2hKvGe+bJc bCsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ED828ESF4TV6+QScdxw1SGHw4GXhqLFcJzI5YRL4H6E=; b=be4O+VRAulDqXFbNBeN6bpoauGqikE7xAdtgmWmV3zXHg9bKNgNyHhSsciTLTqhblg L6l7iFdQ6CAlB3LCviLQrh3OkNGpOZYopHb/V1YTgagFqGQoA0igL6bHViIAeezBm7GJ BruTPMUJ9WYbnUl5UjiAryzWzQm5XmvveQX1evu5PsIuwLb2GLBMde34DHlUjZICvkfJ kyFbUHCFP5x+N7TydWyW+e0b9aupxN3uHbdaSzgLKdrjAb3BMMMsxjFTeERjH071lJ4K KuvJRErqxSMfOlpT+kApXwPOzDIa6pRqqn2UWYLVufG8PRpDI9aCMzAccqgCU5L5vss5 LDSg== X-Gm-Message-State: APjAAAVKgTUYfxDLsDahhwwO4uobnjXHIw0X+VI56kbE7L2ftIcdDx8m CtJ3IhigAUCCH3BQFotpeJc= X-Google-Smtp-Source: APXvYqxU6WrpOJRiem5/w8VCZEu2OCuMpP1zbqiCKmz43FJ9jrtEnrXPjkYR2Cxy9MKD7800SUfOCA== X-Received: by 2002:a37:7383:: with SMTP id o125mr10933805qkc.56.1553314835867; Fri, 22 Mar 2019 21:20:35 -0700 (PDT) Received: from linuxonhyperv2.linuxonhyperv.com (ip-107-180-71-197.ip.secureserver.net. [107.180.71.197]) by smtp.gmail.com with ESMTPSA id k12sm6919699qti.38.2019.03.22.21.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 21:20:35 -0700 (PDT) From: Dexuan Cui X-Google-Original-From: Dexuan Cui To: vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, linux-nvdimm@lists.01.org, mikelley@microsoft.com Subject: [ndctl PATCH v3 1/5] libndctl: Implement the "smart_get_health" dimm-op for Hyper-V Date: Sat, 23 Mar 2019 04:20:25 +0000 Message-Id: <20190323042028.4310-2-decui@microsoft.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190323042028.4310-1-decui@microsoft.com> References: <20190323042028.4310-1-decui@microsoft.com> MIME-Version: 1.0 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: qi.fuli@fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Show the health info of the NVDIMM by "Get Health Information (Function Index 1)" See http://www.uefi.org/RFIC_LIST ("Virtual NVDIMM 0x1901"). Now "ndctl list --dimms --health" can show a line "health_state":"ok" for Hyper-V NVDIMM, e.g. { "dev":"nmem0", "id":"04d5-01-1701-00000000", "handle":0, "phys_id":0, "health":{ "health_state":"ok" } } If the NVDIMM has an error, the string "ok" will be replaced with "fatal", "critical", or "non-critical". If ndctl fails to retrieve the health info due to some reason, a string of "unknown" will be shown. Signed-off-by: Dexuan Cui --- ndctl/lib/Makefile.am | 1 + ndctl/lib/hyperv.c | 126 ++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/hyperv.h | 30 ++++++++++ ndctl/lib/libndctl.c | 2 + ndctl/lib/private.h | 3 + ndctl/ndctl.h | 1 + 6 files changed, 163 insertions(+) create mode 100644 ndctl/lib/hyperv.c create mode 100644 ndctl/lib/hyperv.h diff --git a/ndctl/lib/Makefile.am b/ndctl/lib/Makefile.am index 7797039..fb75fda 100644 --- a/ndctl/lib/Makefile.am +++ b/ndctl/lib/Makefile.am @@ -20,6 +20,7 @@ libndctl_la_SOURCES =\ intel.c \ hpe1.c \ msft.c \ + hyperv.c \ ars.c \ firmware.c \ libndctl.c diff --git a/ndctl/lib/hyperv.c b/ndctl/lib/hyperv.c new file mode 100644 index 0000000..6ed2125 --- /dev/null +++ b/ndctl/lib/hyperv.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2019, Microsoft Corporation. All rights reserved. */ + +#include +#include +#include +#include +#include +#include "private.h" +#include "hyperv.h" + +static struct ndctl_cmd *alloc_hyperv_cmd(struct ndctl_dimm *dimm, + unsigned int command) +{ + struct ndctl_bus *bus = ndctl_dimm_get_bus(dimm); + struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus); + struct nd_pkg_hyperv *hyperv; + struct ndctl_cmd *cmd; + size_t size; + + if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_CALL)) { + dbg(ctx, "unsupported cmd\n"); + return NULL; + } + + if (test_dimm_dsm(dimm, command) == DIMM_DSM_UNSUPPORTED) { + dbg(ctx, "unsupported function\n"); + return NULL; + } + + size = sizeof(*cmd) + sizeof(struct nd_pkg_hyperv); + cmd = calloc(1, size); + if (!cmd) + return NULL; + + ndctl_cmd_ref(cmd); + + cmd->dimm = dimm; + cmd->type = ND_CMD_CALL; + cmd->size = size; + cmd->status = 1; + + hyperv = cmd->hyperv; + hyperv->gen.nd_family = NVDIMM_FAMILY_HYPERV; + hyperv->gen.nd_command = command; + hyperv->gen.nd_size_out = sizeof(hyperv->u.health_info); + + cmd->firmware_status = &hyperv->u.health_info.status; + return cmd; +} + +static struct ndctl_cmd *hyperv_dimm_cmd_new_smart(struct ndctl_dimm *dimm) +{ + return alloc_hyperv_cmd(dimm, ND_HYPERV_CMD_GET_HEALTH_INFO); +} + +static int hyperv_cmd_valid(struct ndctl_cmd *cmd, unsigned int command) +{ + if (cmd->type != ND_CMD_CALL || + cmd->size != sizeof(*cmd) + sizeof(struct nd_pkg_hyperv) || + cmd->hyperv->gen.nd_family != NVDIMM_FAMILY_HYPERV || + cmd->hyperv->gen.nd_command != command || + cmd->status != 0 || + cmd->hyperv->u.status != 0) + return cmd->status < 0 ? cmd->status : -EINVAL; + + return 0; +} + +static int hyperv_valid_health_info(struct ndctl_cmd *cmd) +{ + return hyperv_cmd_valid(cmd, ND_HYPERV_CMD_GET_HEALTH_INFO); +} + +static unsigned int hyperv_cmd_get_flags(struct ndctl_cmd *cmd) +{ + unsigned int flags = 0; + int rc; + + rc = hyperv_valid_health_info(cmd); + if (rc < 0) { + errno = -rc; + return 0; + } + flags |= ND_SMART_HEALTH_VALID; + + return flags; +} + +static unsigned int hyperv_cmd_get_health(struct ndctl_cmd *cmd) +{ + unsigned int health = 0; + __u32 num; + int rc; + + rc = hyperv_valid_health_info(cmd); + if (rc < 0) { + errno = -rc; + return UINT_MAX; + } + + num = cmd->hyperv->u.health_info.health & 0x3F; + + if (num & (BIT(0) | BIT(1))) + health |= ND_SMART_CRITICAL_HEALTH; + + if (num & BIT(2)) + health |= ND_SMART_FATAL_HEALTH; + + if (num & (BIT(3) | BIT(4) | BIT(5))) + health |= ND_SMART_NON_CRITICAL_HEALTH; + + return health; +} + +static int hyperv_cmd_xlat_firmware_status(struct ndctl_cmd *cmd) +{ + return cmd->hyperv->u.status == 0 ? 0 : -EINVAL; +} + +struct ndctl_dimm_ops * const hyperv_dimm_ops = &(struct ndctl_dimm_ops) { + .new_smart = hyperv_dimm_cmd_new_smart, + .smart_get_flags = hyperv_cmd_get_flags, + .smart_get_health = hyperv_cmd_get_health, + .xlat_firmware_status = hyperv_cmd_xlat_firmware_status, +}; diff --git a/ndctl/lib/hyperv.h b/ndctl/lib/hyperv.h new file mode 100644 index 0000000..45bbc12 --- /dev/null +++ b/ndctl/lib/hyperv.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2019, Microsoft Corporation. All rights reserved. */ + +#ifndef __NDCTL_HYPERV_H__ +#define __NDCTL_HYPERV_H__ + +/* See http://www.uefi.org/RFIC_LIST ("Virtual NVDIMM 0x1901") */ + +enum { + ND_HYPERV_CMD_QUERY_SUPPORTED_FUNCTIONS = 0, + ND_HYPERV_CMD_GET_HEALTH_INFO = 1, +}; + +/* Get Health Information (Function Index 1) */ +struct nd_hyperv_health_info { + __u32 status; + __u32 health; +} __attribute__((packed)); + +union nd_hyperv_cmd { + __u32 status; + struct nd_hyperv_health_info health_info; +} __attribute__((packed)); + +struct nd_pkg_hyperv { + struct nd_cmd_pkg gen; + union nd_hyperv_cmd u; +} __attribute__((packed)); + +#endif /* __NDCTL_HYPERV_H__ */ diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 98893bc..24b8ad3 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1543,6 +1543,8 @@ static void *add_dimm(void *parent, int id, const char *dimm_base) dimm->ops = hpe1_dimm_ops; if (dimm->cmd_family == NVDIMM_FAMILY_MSFT) dimm->ops = msft_dimm_ops; + if (dimm->cmd_family == NVDIMM_FAMILY_HYPERV) + dimm->ops = hyperv_dimm_ops; sprintf(path, "%s/nfit/dsm_mask", dimm_base); if (sysfs_read_attr(ctx, path, buf) == 0) diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index a387b0b..a9d35c5 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -31,6 +31,7 @@ #include "intel.h" #include "hpe1.h" #include "msft.h" +#include "hyperv.h" struct nvdimm_data { struct ndctl_cmd *cmd_read; @@ -270,6 +271,7 @@ struct ndctl_cmd { struct nd_cmd_pkg pkg[0]; struct ndn_pkg_hpe1 hpe1[0]; struct ndn_pkg_msft msft[0]; + struct nd_pkg_hyperv hyperv[0]; struct nd_pkg_intel intel[0]; struct nd_cmd_get_config_size get_size[0]; struct nd_cmd_get_config_data_hdr get_data[0]; @@ -344,6 +346,7 @@ struct ndctl_dimm_ops { struct ndctl_dimm_ops * const intel_dimm_ops; struct ndctl_dimm_ops * const hpe1_dimm_ops; struct ndctl_dimm_ops * const msft_dimm_ops; +struct ndctl_dimm_ops * const hyperv_dimm_ops; static inline struct ndctl_bus *cmd_to_bus(struct ndctl_cmd *cmd) { diff --git a/ndctl/ndctl.h b/ndctl/ndctl.h index c6aaa4c..008f81c 100644 --- a/ndctl/ndctl.h +++ b/ndctl/ndctl.h @@ -262,6 +262,7 @@ struct nd_cmd_pkg { #define NVDIMM_FAMILY_HPE1 1 #define NVDIMM_FAMILY_HPE2 2 #define NVDIMM_FAMILY_MSFT 3 +#define NVDIMM_FAMILY_HYPERV 4 #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\ struct nd_cmd_pkg) From patchwork Sat Mar 23 04:20:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10866757 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 756AD139A for ; Sat, 23 Mar 2019 04:20:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FA5E2A94F for ; Sat, 23 Mar 2019 04:20:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 343FB2A95D; Sat, 23 Mar 2019 04:20:40 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 CEC222A94F for ; Sat, 23 Mar 2019 04:20:39 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 732A9211E9FAA; Fri, 22 Mar 2019 21:20:39 -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=2607:f8b0:4864:20::742; helo=mail-qk1-x742.google.com; envelope-from=dexuan.cui@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3E2D7211E9FA3 for ; Fri, 22 Mar 2019 21:20:38 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id y5so2444933qkc.11 for ; Fri, 22 Mar 2019 21:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LgDGLPBpAfdlNzgnU+QGuql5PG5IXRO/vApnCBr3Axw=; b=g9bHkKWAha7l9ccZOtvGz1SuoqLFaCLTrW60+z2VEQkPk3gKgStpqd/kmLvV5b+I7y Sb3hI3HBVOGtkDgQX6fb9Sl6QMlVOjBbgBIPao29GBTmhTbVRl9qjOHA2newwK20NTxM 0xP0tmdGoYx+I8/ykPhiZX4uuUMRbeJTGvhTgsFsLRYJQBMkFyTfwlEM1xAbmc7ZN3OW lr/uksE1Dee26yOreHe4GszRnCC/uqN2sgaKq9nVSE6fnDyx5kjcLrDha29YA/371NTr bGJhUmrRsCrTAJZMhN+gxE2AvpDDFvZmEWqdLdPBuWeC0p6gTFBnUprMG0m+2ZeyDE9Y pvyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LgDGLPBpAfdlNzgnU+QGuql5PG5IXRO/vApnCBr3Axw=; b=fpBPRS/QS0tVgKenfy6nFSBVEAzzEAjHdTQ8UWfhzxSzhnlqwFSSCMqBRDEpySWNJO r8l65zcw4vlF/P/PUK5WlA/ZGGgbB/5qAXux3/oUUr8TFx5/f7mZCtsSluiSG9XIBHj+ Bev3/YjvqiG0FE4JCtMNXgeYfShZ6OhghyCGvK/gFEPCLY/zGOs7p94Xz9c3812VqVFG 3yWFlQQGHvciWwvf6Vm+VI5b9ESS1MknZ1M8YyMpnRpIvORpDTsZUTYgzHRucJh7Ks+F q7BXv2M8r/ZNutd+WGHBuOFz6EzVr/WH/wCOTEEWms5qdAGtrOan7EAS9vmrAx0MYHZi djLA== X-Gm-Message-State: APjAAAXR1MvcDgl6A4Zlgi1vWQfebsNkAjVgu96cO8Ol0iSMBWlQJUqJ SleVAtNYcbA6AbH4h5e+Elw= X-Google-Smtp-Source: APXvYqzFZeLDrvmAO3tseKkf3bHSnrhVdEYvtwns0RQPCawmGT4jNDPH1o0eaBUijlqkvgtTqL7Scw== X-Received: by 2002:a37:7e84:: with SMTP id z126mr10242666qkc.31.1553314837251; Fri, 22 Mar 2019 21:20:37 -0700 (PDT) Received: from linuxonhyperv2.linuxonhyperv.com (ip-107-180-71-197.ip.secureserver.net. [107.180.71.197]) by smtp.gmail.com with ESMTPSA id k12sm6919699qti.38.2019.03.22.21.20.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 21:20:36 -0700 (PDT) From: Dexuan Cui X-Google-Original-From: Dexuan Cui To: vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, linux-nvdimm@lists.01.org, mikelley@microsoft.com Subject: [ndctl PATCH v3 2/5] libndctl: Implement the smart_get_shutdown_count dimm-op for Hyper-V Date: Sat, 23 Mar 2019 04:20:26 +0000 Message-Id: <20190323042028.4310-3-decui@microsoft.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190323042028.4310-1-decui@microsoft.com> References: <20190323042028.4310-1-decui@microsoft.com> MIME-Version: 1.0 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: qi.fuli@fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The "smart_get_shutdown_count" dimm-op is expected to return a shutdown count, but for the Hyper-V family this is only available from a separate DSM. Perform a command submission in the "hyperv_cmd_get_shutdown_count" dimm-op and the "hyperv_cmd_get_flags" dimm-op to retrieve this info, so that a smart health listing can display this info. Now "ndctl list --dimms --health" can show a line of "shutdown_count" for Hyper-V NVDIMM, e.g. { "dev":"nmem0", "id":"04d5-01-1701-00000000", "handle":0, "phys_id":0, "health":{ "health_state":"ok", "shutdown_count":2 } } Signed-off-by: Dexuan Cui --- ndctl/lib/hyperv.c | 43 +++++++++++++++++++++++++++++++++++++++++++ ndctl/lib/hyperv.h | 8 ++++++++ 2 files changed, 51 insertions(+) diff --git a/ndctl/lib/hyperv.c b/ndctl/lib/hyperv.c index 6ed2125..efd8b03 100644 --- a/ndctl/lib/hyperv.c +++ b/ndctl/lib/hyperv.c @@ -72,9 +72,33 @@ static int hyperv_valid_health_info(struct ndctl_cmd *cmd) return hyperv_cmd_valid(cmd, ND_HYPERV_CMD_GET_HEALTH_INFO); } +static int hyperv_get_shutdown_count(struct ndctl_cmd *cmd, unsigned int *count) +{ + unsigned int command = ND_HYPERV_CMD_GET_SHUTDOWN_INFO; + struct ndctl_cmd *cmd_get_shutdown_info; + int rc; + + cmd_get_shutdown_info = alloc_hyperv_cmd(cmd->dimm, command); + if (!cmd_get_shutdown_info) + return -EINVAL; + + if (ndctl_cmd_submit_xlat(cmd_get_shutdown_info) < 0 || + hyperv_cmd_valid(cmd_get_shutdown_info, command) < 0) { + rc = -EINVAL; + goto out; + } + + *count = cmd_get_shutdown_info->hyperv->u.shutdown_info.count; + rc = 0; +out: + ndctl_cmd_unref(cmd_get_shutdown_info); + return rc; +} + static unsigned int hyperv_cmd_get_flags(struct ndctl_cmd *cmd) { unsigned int flags = 0; + unsigned int count; int rc; rc = hyperv_valid_health_info(cmd); @@ -84,6 +108,9 @@ static unsigned int hyperv_cmd_get_flags(struct ndctl_cmd *cmd) } flags |= ND_SMART_HEALTH_VALID; + if (hyperv_get_shutdown_count(cmd, &count) == 0) + flags |= ND_SMART_SHUTDOWN_COUNT_VALID; + return flags; } @@ -113,6 +140,21 @@ static unsigned int hyperv_cmd_get_health(struct ndctl_cmd *cmd) return health; } +static unsigned int hyperv_cmd_get_shutdown_count(struct ndctl_cmd *cmd) +{ + unsigned int count; + int rc;; + + rc = hyperv_get_shutdown_count(cmd, &count); + + if (rc < 0) { + errno = -rc; + return UINT_MAX; + } + + return count; +} + static int hyperv_cmd_xlat_firmware_status(struct ndctl_cmd *cmd) { return cmd->hyperv->u.status == 0 ? 0 : -EINVAL; @@ -122,5 +164,6 @@ struct ndctl_dimm_ops * const hyperv_dimm_ops = &(struct ndctl_dimm_ops) { .new_smart = hyperv_dimm_cmd_new_smart, .smart_get_flags = hyperv_cmd_get_flags, .smart_get_health = hyperv_cmd_get_health, + .smart_get_shutdown_count = hyperv_cmd_get_shutdown_count, .xlat_firmware_status = hyperv_cmd_xlat_firmware_status, }; diff --git a/ndctl/lib/hyperv.h b/ndctl/lib/hyperv.h index 45bbc12..0c1677f 100644 --- a/ndctl/lib/hyperv.h +++ b/ndctl/lib/hyperv.h @@ -9,6 +9,7 @@ enum { ND_HYPERV_CMD_QUERY_SUPPORTED_FUNCTIONS = 0, ND_HYPERV_CMD_GET_HEALTH_INFO = 1, + ND_HYPERV_CMD_GET_SHUTDOWN_INFO = 2, }; /* Get Health Information (Function Index 1) */ @@ -17,9 +18,16 @@ struct nd_hyperv_health_info { __u32 health; } __attribute__((packed)); +/* Get Unsafe Shutdown Count (Function Index 2) */ +struct nd_hyperv_shutdown_info { + __u32 status; + __u32 count; +} __attribute__((packed)); + union nd_hyperv_cmd { __u32 status; struct nd_hyperv_health_info health_info; + struct nd_hyperv_shutdown_info shutdown_info; } __attribute__((packed)); struct nd_pkg_hyperv { From patchwork Sat Mar 23 04:20:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10866759 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 86C0B139A for ; Sat, 23 Mar 2019 04:20:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 622C62A94F for ; Sat, 23 Mar 2019 04:20:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55C3E2A95D; Sat, 23 Mar 2019 04:20:41 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 0EF6F2A94F for ; Sat, 23 Mar 2019 04:20:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8FCDD211E9FB0; Fri, 22 Mar 2019 21:20:40 -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=2607:f8b0:4864:20::744; helo=mail-qk1-x744.google.com; envelope-from=dexuan.cui@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 66513211E95B2 for ; Fri, 22 Mar 2019 21:20:39 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id b74so2452349qkg.9 for ; Fri, 22 Mar 2019 21:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cEfoMWMXtV4me6P5oRx2UkgAu2VOmPX/Bt3nkztq25o=; b=SoN0EsktNb2vKowgn3C8JaMKJb0a8GMOtqrFvdrpW9jIpW11VcgK8qp3045Y56wVa/ uyRXQO0QflEpAZagMjiReMqcMJKk3oPHba+H0knP3lP2DLb9dWFAVDGmUw36OS1AJtB7 Gqud3hrUYBgpuze73CUDs+byYP7wQWn/9p5uQlgoj11rT3lnEA9Sw8fmdtXYWdAV4Ln4 OQaYZDSRNvHzHGKiYFfFjPJHwKpP9aG1nVAaAE6IdI19X5o4u7TvPOfaoMGUoZKhMGUz /HroOUTaD6WoCcv8kW/0F0ipJOwYl+EEy+G/1rvE6IroeAD1hU0KLg5o5IxQ31kOeVTb dSRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cEfoMWMXtV4me6P5oRx2UkgAu2VOmPX/Bt3nkztq25o=; b=AOCxD5jPxWYhCgEFMehClbt+ws+lBkXV5zaVs3kVMSwYOL2wuQw3Ek47yMvV9M2bc4 AzfnBihrgMJmqsv16YFDNmdpMkIRf7O/zkriX5rsFpoIpJ7e94uEhnXuRN3J4bpE4gOm y/D7TZsy5Xq50jFGZOeaJc19E7PyWI0JPZpoFEfg+O/mxJllFJNhOXtf4kvLzaW4muEc FQyUhhygMNtgMlKTd9dGZXiG3dtmNk3VgdJxHY53F836F0C3B2twHqN3CJUhC3ZIdlEq ZHCIc7NYih47GSb3GxidbhrLeZsEYEnJOMs6XY0cWau9c5cqAv5kPLqPick093/+i7gu zghw== X-Gm-Message-State: APjAAAWKowwVNK1Tv6XOs5MACg7xfrUrGUZv01r61+DnIpYdriE8TjIX r3RxqZK31aB1tQ8/TeAWWnI= X-Google-Smtp-Source: APXvYqxlHC6VcdQ9vpsaK+l+1HPcX4irKpnZxny52vdN+Z5edAXHdoG1aBxs9akgrZw2zbeKBBKw/g== X-Received: by 2002:ae9:e21a:: with SMTP id c26mr10920342qkc.293.1553314838643; Fri, 22 Mar 2019 21:20:38 -0700 (PDT) Received: from linuxonhyperv2.linuxonhyperv.com (ip-107-180-71-197.ip.secureserver.net. [107.180.71.197]) by smtp.gmail.com with ESMTPSA id k12sm6919699qti.38.2019.03.22.21.20.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 21:20:38 -0700 (PDT) From: Dexuan Cui X-Google-Original-From: Dexuan Cui To: vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, linux-nvdimm@lists.01.org, mikelley@microsoft.com Subject: [ndctl PATCH v3 3/5] ndctl, monitor: Don't require the support of ND_CMD_SMART_THRESHOLD Date: Sat, 23 Mar 2019 04:20:27 +0000 Message-Id: <20190323042028.4310-4-decui@microsoft.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190323042028.4310-1-decui@microsoft.com> References: <20190323042028.4310-1-decui@microsoft.com> MIME-Version: 1.0 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: qi.fuli@fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When a NVDIMM doesn't support ND_CMD_SMART_THRESHOLD, it may support ND_CMD_SMART or a variant of ND_CMD_SMART. Allow such a NVDIMM to work with "ndctl monitor". Signed-off-by: Dexuan Cui --- ndctl/monitor.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 43b2abe..346a6df 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -275,17 +275,13 @@ static void filter_dimm(struct ndctl_dimm *dimm, struct util_filter_ctx *fctx) err(&monitor, "%s: no smart support\n", name); return; } - if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_SMART_THRESHOLD)) { - err(&monitor, "%s: no smart threshold support\n", name); - return; - } - if (!ndctl_dimm_is_flag_supported(dimm, ND_SMART_ALARM_VALID)) { + if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_SMART_THRESHOLD)) { + dbg(&monitor, "%s: no smart threshold support\n", name); + } else if (!ndctl_dimm_is_flag_supported(dimm, ND_SMART_ALARM_VALID)) { err(&monitor, "%s: smart alarm invalid\n", name); return; - } - - if (enable_dimm_supported_threshold_alarms(dimm)) { + } else if (enable_dimm_supported_threshold_alarms(dimm)) { err(&monitor, "%s: enable supported threshold alarms failed\n", name); return; } From patchwork Sat Mar 23 04:20:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10866761 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 22856922 for ; Sat, 23 Mar 2019 04:20:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 004A12A94F for ; Sat, 23 Mar 2019 04:20:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8E402A95D; Sat, 23 Mar 2019 04:20:42 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 AC8F42A94F for ; Sat, 23 Mar 2019 04:20:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A5CF2211E9FA8; Fri, 22 Mar 2019 21:20:42 -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=2607:f8b0:4864:20::844; helo=mail-qt1-x844.google.com; envelope-from=dexuan.cui@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4D3F2211E9FA3 for ; Fri, 22 Mar 2019 21:20:41 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id t28so4881358qte.6 for ; Fri, 22 Mar 2019 21:20:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JK73HA9FlClT5xM0YEyWS2jmQcS1f9MvElb1iZtc/+E=; b=KbnwzG/RBEmG+3+EltcsTTRGD5J5Tzq+YX6vMwT1GOL3fo8zGMI6ND/tGtSYUTwBZa 05FZVKNOaUQRgvunqmiKElTsJRPvpAf3TcPdMDGti2CFK3kZhgJ/7PtNoBKadNQdxRRy ql9WG9JYqUyo+gPbHgiZ9xTn2BHJHYa6CjcfWh/wMnP1KHDHkCE57tBkNt66OyGOzfZw IIFSjlBn4jvAPvUxfURu3MSYJJYE2ApmuIR1fJ33MKTGA9NxXtlxZropIE9nHqTKA65f tU4RS46W4A2Sq26PX6MbeeGaAU0UZP11O1WcJCwfFqVECZ3FZ/f2OJLhFF7IdWinaEYh bVkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JK73HA9FlClT5xM0YEyWS2jmQcS1f9MvElb1iZtc/+E=; b=DGxTxQ+ttbRcEFPniLJu8z2kt1gA5c6w2ZMuU5SEyStHqkUiLKz/Sroxk0IYmwx6Xs 5pc2v0kS3Im9IrjYIbM6N/GnwK6uSvwpxU6yR/Em6d3UAILDhJ7f+KP0S3RRztEk9l+Y tTPNokW7QmEcrLUXOzPBe0yprWLkHr14EFOZrAi93vTVLQEyuLr5kD5jM4rz22BzZYWm r6KJqMzY6N3MwdVLoHLFXJ/Y1DCEaEL/aBYbWk5l4wKvdSen9WzddEb0P4ZFfkd4vp4N b4NLXKIgd6CysQlyiS1OBZuh97nMpL7DNYPWJTZxtxqp8KO30RAdAurjBmWzy+Vw52T5 Wfaw== X-Gm-Message-State: APjAAAUi8ifYq6hk0yz9YlDi+h4Mb3dXazYYy5Zbab/tgBnlFnEzLLx+ DOebE3jB/now0vN+SIH1blM= X-Google-Smtp-Source: APXvYqzOsInHPpIq1DrP0aJrNiQ0aXQn2iASjHGKOiO1WGPq3GyVpKFSX4sfJeYtqzhdmSBnPAFOgQ== X-Received: by 2002:ac8:2598:: with SMTP id e24mr11673247qte.27.1553314839999; Fri, 22 Mar 2019 21:20:39 -0700 (PDT) Received: from linuxonhyperv2.linuxonhyperv.com (ip-107-180-71-197.ip.secureserver.net. [107.180.71.197]) by smtp.gmail.com with ESMTPSA id k12sm6919699qti.38.2019.03.22.21.20.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 21:20:39 -0700 (PDT) From: Dexuan Cui X-Google-Original-From: Dexuan Cui To: vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, linux-nvdimm@lists.01.org, mikelley@microsoft.com Subject: [ndctl PATCH v3 4/5] libndctl: Add a new dimm-op cmd_is_supported() Date: Sat, 23 Mar 2019 04:20:28 +0000 Message-Id: <20190323042028.4310-5-decui@microsoft.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190323042028.4310-1-decui@microsoft.com> References: <20190323042028.4310-1-decui@microsoft.com> MIME-Version: 1.0 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: qi.fuli@fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP A NVDIMM family may need to report that it supports a command, even if the command is not set in dimm->cmd_mask, e.g. a non-NVDIMM_FAMILY_INTEL famimy may support ND_CMD_SMART or some kind of variant of ND_CMD_SMART, while the kernel only sets ND_CMD_SMART in the nvdimm->cmd_mask for NVDIMM_FAMILY_INTEL. Signed-off-by: Dexuan Cui --- ndctl/lib/libndctl.c | 5 +++++ ndctl/lib/private.h | 1 + 2 files changed, 6 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 24b8ad3..4acfb03 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1769,6 +1769,11 @@ NDCTL_EXPORT int ndctl_dimm_failed_map(struct ndctl_dimm *dimm) NDCTL_EXPORT int ndctl_dimm_is_cmd_supported(struct ndctl_dimm *dimm, int cmd) { + struct ndctl_dimm_ops *ops = dimm->ops; + + if (ops && ops->cmd_is_supported) + return ops->cmd_is_supported(dimm, cmd); + return !!(dimm->cmd_mask & (1ULL << cmd)); } diff --git a/ndctl/lib/private.h b/ndctl/lib/private.h index a9d35c5..2ddc1d2 100644 --- a/ndctl/lib/private.h +++ b/ndctl/lib/private.h @@ -292,6 +292,7 @@ struct ndctl_bb { struct ndctl_dimm_ops { const char *(*cmd_desc)(int); + bool (*cmd_is_supported)(struct ndctl_dimm *, 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 *); From patchwork Sat Mar 23 04:26:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 10866763 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 03D61139A for ; Sat, 23 Mar 2019 04:26:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C83582A982 for ; Sat, 23 Mar 2019 04:26:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBD3B2A9F8; Sat, 23 Mar 2019 04:26:48 +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.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 5AD4D2A982 for ; Sat, 23 Mar 2019 04:26:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 40EB3211E9FA4; Fri, 22 Mar 2019 21:26:48 -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=2607:f8b0:4864:20::842; helo=mail-qt1-x842.google.com; envelope-from=dexuan.cui@gmail.com; receiver=linux-nvdimm@lists.01.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id ADE04211E95B2 for ; Fri, 22 Mar 2019 21:26:46 -0700 (PDT) Received: by mail-qt1-x842.google.com with SMTP id h39so4910672qte.2 for ; Fri, 22 Mar 2019 21:26:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RE9NZJml4eNkAwJmDkEJCLS19gaxRsEyFTdR8rayQuY=; b=llTnYCrqpJegH3Ofuk5sAf234dQUa+oyeX3jkRgMcWCL5OvNQ5GlJ55s1MWHREUNGz sZ4WzsiQJaT4ZRafWSxWAMaS4L04EsN55B8k3bjUV7Q1P4L2RgtbN5XsehoVQvMOSe/1 o0wYOh/33TPvyPMViW+BrPJnBK4Do2WPPrGciUuJ5EMPnY2YW+UB+OgghTbuiquuI2Bo x7SDLbM6NWPXWH9mqnpuZl+ZlY81H/pm64YGQOF6+31+z/K9ddPy4smjAyeA3SXvSZ52 f/tS6RjpiFP6RGX2V7z+JdhLzIQyFYDrL6EMvi8HA5p61ehQ4SJOt5VWkc4Bw9xLsXHD lmMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RE9NZJml4eNkAwJmDkEJCLS19gaxRsEyFTdR8rayQuY=; b=LeVaz5QDZg+vvSIP2snG3OesuBokpoJIPrYSHA8arOIcF4Qkh+f2ygYqpigRXpdFtQ fIeFB7ga2KVsxvcFf5FUyFg6E8vZLHIwwNRF2nGUZ+O0S6kijhJrSrux7AJY3yAh8YPG GMBFmbDoFbZiecsGAuCaidhS65cwSMQFYpaP8ZJ1FYom8SZQsJehbJJfAyZn1D44QTW0 lr+yNEiT1Bzz5/gIfo2+IwSZsL69z7+PGEBUVGZrDBLZz8jokC1xosqK7LEDbloFQ0GT xjzPIQqFICdvJhc95XV4m3ApDx2HXOQndFlrlFcui9GPbF1KB7H1fM1SFrElpOqmOfru BCnQ== X-Gm-Message-State: APjAAAUFkOkByb6Zv6Wdfdh2emntfoEwOWuM9MwKc15uZ3F1jdLVqy2s 5iGjaC0pHEm0RrF7VNJocWc= X-Google-Smtp-Source: APXvYqw0YV+ukIJo2lay3bUAMfApd/E5XoUWBGFTsRL6Mqqz0GTyW7nTEcvR1MutYeSPAiWAq6Z89Q== X-Received: by 2002:a0c:b645:: with SMTP id q5mr11299106qvf.194.1553315205809; Fri, 22 Mar 2019 21:26:45 -0700 (PDT) Received: from linuxonhyperv2.linuxonhyperv.com (ip-107-180-71-197.ip.secureserver.net. [107.180.71.197]) by smtp.gmail.com with ESMTPSA id w9sm4913811qkf.94.2019.03.22.21.26.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 21:26:45 -0700 (PDT) From: Dexuan Cui X-Google-Original-From: Dexuan Cui To: vishal.l.verma@intel.com, dan.j.williams@intel.com, dave.jiang@intel.com, linux-nvdimm@lists.01.org, mikelley@microsoft.com Subject: [ndctl PATCH v3 5/5] libndctl: Implement the "cmd_is_supported" dimm-op for Hyper-V Date: Sat, 23 Mar 2019 04:26:37 +0000 Message-Id: <20190323042637.4544-1-decui@microsoft.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 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: qi.fuli@fujitsu.com Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Currently "ndctl monitor" fails for Hyper-V virtual NVDIMM due to "no smart support". According to http://www.uefi.org/RFIC_LIST ("Virtual NVDIMM 0x1901"), Hyper-V doesn't really support ND_CMD_SMART, but it supports "Get Health Information (Function Index 1)" and "Get Unsafe Shutdown Count (Function Index 2)", which is basically a "weak" variant of ND_CMD_SMART. Implement the dimm-ops to allow "ndctl monitor" to work with Hyper-V NVDIMM. Now when an error happens, "ndctl monitor" can show such a line: {"timestamp":"1550547497.431731497","pid":1571,"event": {"dimm-health-state":true},"dimm":{"dev":"nmem1", "id":"04d5-01-1701-01000000","handle":1,"phys_id":0, "health":{"health_state":"fatal","shutdown_count":8}}} Here the meaningful info is: "health":{"health_state":"fatal","shutdown_count":8} Signed-off-by: Dexuan Cui --- ndctl/lib/hyperv.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ndctl/lib/hyperv.c b/ndctl/lib/hyperv.c index efd8b03..9b4fe12 100644 --- a/ndctl/lib/hyperv.c +++ b/ndctl/lib/hyperv.c @@ -9,6 +9,19 @@ #include "private.h" #include "hyperv.h" +static bool hyperv_cmd_is_supported(struct ndctl_dimm *dimm, int cmd) +{ + /* + * "ndctl monitor" requires ND_CMD_SMART, which is not really supported + * by Hyper-V virtual NVDIMM. Nevertheless, ND_CMD_SMART can be emulated + * by ND_HYPERV_CMD_GET_HEALTH_INFO and ND_HYPERV_CMD_GET_SHUTDOWN_INFO. + */ + if (cmd == ND_CMD_SMART ) + return true; + + return !!(dimm->cmd_mask & (1ULL << cmd)); +} + static struct ndctl_cmd *alloc_hyperv_cmd(struct ndctl_dimm *dimm, unsigned int command) { @@ -161,6 +174,7 @@ static int hyperv_cmd_xlat_firmware_status(struct ndctl_cmd *cmd) } struct ndctl_dimm_ops * const hyperv_dimm_ops = &(struct ndctl_dimm_ops) { + .cmd_is_supported = hyperv_cmd_is_supported, .new_smart = hyperv_dimm_cmd_new_smart, .smart_get_flags = hyperv_cmd_get_flags, .smart_get_health = hyperv_cmd_get_health,