From patchwork Mon Sep 11 04:37:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946583 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 D4642603F4 for ; Mon, 11 Sep 2017 04:41:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA071289DE for ; Mon, 11 Sep 2017 04:41:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEFD228AD8; Mon, 11 Sep 2017 04:41:43 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3666328ABE for ; Mon, 11 Sep 2017 04:41:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGV7-0001Qu-Kg; Mon, 11 Sep 2017 04:39:13 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGV6-0001Of-CE for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:12 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 9E/CA-03093-F6316B95; Mon, 11 Sep 2017 04:39:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+sQ0c0T3hZ psPK3ocWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmjFrnn3BZOOKm097mRsY56t2MXJxCAlMZ5Ro OzOPtYuRk0NCgFfiyLIZUHaAxJ853YwQRb2MEu2vtrKAJNgE9CVWPD4IViQiIC1x7fNlRhCbW eAPo8S9T7IgtrBApMTlbf/YQGwWAVWJnX2HwWxeATuJ78fOskAskJfY1XYRbA4nUPzgy3fMIL aQgK3EgtMLWCcw8i5gZFjFqFGcWlSWWqRrZK6XVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKy XnJ+7iREYDgxAsINx8drAQ4ySHExKorzvjm+JFOJLyk+pzEgszogvKs1JLT7EKMPBoSTBe0Zw W6SQYFFqempFWmYOMDBh0hIcPEoivItA0rzFBYm5xZnpEKlTjMYcxzZd/sPE0XHz7h8mIZa8/ LxUKXHezSClAiClGaV5cINgEXOJUVZKmJcR6DQhnoLUotzMElT5V4ziHIxKwrwyQkBTeDLzSu D2vQI6hQnoFJ5LW0BOKUlESEk1MIptN7Ey6p5wXDLYIG1/q+RZp1lzi+4wbZ9iVFr/6M/EdTs Ox62yPjrTd4Xe/7PhQpzpUbPU2bOqPFcsidqn1PM8hudfTXTpixkLZDevY0j/rxD0c4uXvGbH HZ/eS9zy2gGZwccL/Gb9WzpN/1fb1H8Lny5dG8P35qfw3+rMM1tDFGzfNL+N/KzEUpyRaKjFX FScCAA+rpQ1kwIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!7 X-Originating-IP: [134.134.136.20] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTM0LjEzNC4xMzYuMjAgPT4gMzU1MzU4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 47930 invoked from network); 11 Sep 2017 04:39:10 -0000 Received: from mga02.intel.com (HELO mga02.intel.com) (134.134.136.20) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Sep 2017 04:39:10 -0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2017 21:39:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078387" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.142]) by fmsmga002.fm.intel.com with ESMTP; 10 Sep 2017 21:39:08 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:37:53 +0800 Message-Id: <20170911043820.14617-13-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com> References: <20170911043820.14617-1-haozhong.zhang@intel.com> Cc: Haozhong Zhang , Wei Liu , Ian Jackson , Chao Peng , Dan Williams Subject: [Xen-devel] [RFC XEN PATCH v3 12/39] tools/xen-ndctl: add NVDIMM management util 'xen-ndctl' X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The kernel NVDIMM driver and the traditional NVDIMM management utilities in Dom0 does not work now. 'xen-ndctl' is added as an alternatively, which manages NVDIMM via Xen hypercalls. Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu --- .gitignore | 1 + tools/misc/Makefile | 4 ++ tools/misc/xen-ndctl.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 tools/misc/xen-ndctl.c diff --git a/.gitignore b/.gitignore index ecb198f914..30655673f7 100644 --- a/.gitignore +++ b/.gitignore @@ -216,6 +216,7 @@ tools/misc/xen-hvmctx tools/misc/xenlockprof tools/misc/lowmemd tools/misc/xencov +tools/misc/xen-ndctl tools/pkg-config/* tools/qemu-xen-build tools/xentrace/xenalyze diff --git a/tools/misc/Makefile b/tools/misc/Makefile index eaa28793ef..124775b7f4 100644 --- a/tools/misc/Makefile +++ b/tools/misc/Makefile @@ -32,6 +32,7 @@ INSTALL_SBIN += xenpm INSTALL_SBIN += xenwatchdogd INSTALL_SBIN += xen-livepatch INSTALL_SBIN += xen-diag +INSTALL_SBIN += xen-ndctl INSTALL_SBIN += $(INSTALL_SBIN-y) # Everything to be installed in a private bin/ @@ -118,4 +119,7 @@ xen-lowmemd: xen-lowmemd.o xencov: xencov.o $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) +xen-ndctl: xen-ndctl.o + $(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS) + -include $(DEPS_INCLUDE) diff --git a/tools/misc/xen-ndctl.c b/tools/misc/xen-ndctl.c new file mode 100644 index 0000000000..de40e29ff6 --- /dev/null +++ b/tools/misc/xen-ndctl.c @@ -0,0 +1,172 @@ +/* + * xen-ndctl.c + * + * Xen NVDIMM management tool + * + * Copyright (C) 2017, Intel Corporation + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include + +static xc_interface *xch; + +static int handle_help(int argc, char *argv[]); +static int handle_list_cmds(int argc, char *argv[]); + +static const struct xen_ndctl_cmd +{ + const char *name; + const char *syntax; + const char *help; + int (*handler)(int argc, char **argv); + bool need_xc; +} cmds[] = +{ + { + .name = "help", + .syntax = "[command]", + .help = "Show this message or the help message of 'command'.\n" + "Use command 'list-cmds' to list all supported commands.\n", + .handler = handle_help, + }, + + { + .name = "list-cmds", + .syntax = "", + .help = "List all supported commands.\n", + .handler = handle_list_cmds, + }, +}; + +static const unsigned int nr_cmds = sizeof(cmds) / sizeof(cmds[0]); + +static void show_help(const char *cmd) +{ + unsigned int i; + + if ( !cmd ) + { + fprintf(stderr, + "Usage: xen-ndctl [args]\n\n" + "List all supported commands by 'xen-ndctl list-cmds'.\n" + "Get help of a command by 'xen-ndctl help '.\n"); + return; + } + + for ( i = 0; i < nr_cmds; i++ ) + if ( !strcmp(cmd, cmds[i].name) ) + { + fprintf(stderr, "Usage: xen-ndctl %s %s\n\n%s", + cmds[i].name, cmds[i].syntax, cmds[i].help); + break; + } + + if ( i == nr_cmds ) + fprintf(stderr, "Unsupported command '%s'.\n" + "List all supported commands by 'xen-ndctl list-cmds'.\n", + cmd); +} + +static int handle_unrecognized_argument(const char *cmd, const char *argv) +{ + fprintf(stderr, "Unrecognized argument: %s.\n\n", argv); + show_help(cmd); + + return -EINVAL; +} + +static int handle_help(int argc, char *argv[]) +{ + if ( argc == 1 ) + show_help(NULL); + else if ( argc == 2 ) + show_help(argv[1]); + else + return handle_unrecognized_argument(argv[0], argv[2]); + + return 0; +} + +static int handle_list_cmds(int argc, char *argv[]) +{ + unsigned int i; + + if ( argc > 1 ) + return handle_unrecognized_argument(argv[0], argv[1]); + + for ( i = 0; i < nr_cmds; i++ ) + fprintf(stderr, "%s\n", cmds[i].name); + + return 0; +} + +int main(int argc, char *argv[]) +{ + unsigned int i; + int rc = 0; + const char *cmd; + + if ( argc <= 1 ) + { + show_help(NULL); + return 0; + } + + cmd = argv[1]; + + for ( i = 0; i < nr_cmds; i++ ) + if ( !strcmp(cmd, cmds[i].name) ) + { + if ( cmds[i].need_xc ) + { + xch = xc_interface_open(0, 0, 0); + if ( !xch ) + { + rc = -errno; + fprintf(stderr, "Cannot get xc handler: %s\n", + strerror(errno)); + break; + } + } + rc = cmds[i].handler(argc - 1, &argv[1]); + if ( rc ) + fprintf(stderr, "\n'%s' failed: %s\n", + cmds[i].name, strerror(-rc)); + break; + } + + if ( i == nr_cmds ) + { + fprintf(stderr, "Unsupported command '%s'. " + "List all supported commands by 'xen-ndctl list-cmds'.\n", + cmd); + rc = -ENOSYS; + } + + if ( xch ) + xc_interface_close(xch); + + return rc; +}