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 {