From: Haozhong Zhang <haozhong.zhang@intel.com>
To: xen-devel@lists.xen.org
Cc: Haozhong Zhang <haozhong.zhang@intel.com>,
Wei Liu <wei.liu2@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Chao Peng <chao.p.peng@linux.intel.com>,
Dan Williams <dan.j.williams@intel.com>
Subject: [RFC XEN PATCH v3 12/39] tools/xen-ndctl: add NVDIMM management util 'xen-ndctl'
Date: Mon, 11 Sep 2017 12:37:53 +0800 [thread overview]
Message-ID: <20170911043820.14617-13-haozhong.zhang@intel.com> (raw)
In-Reply-To: <20170911043820.14617-1-haozhong.zhang@intel.com>
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 <haozhong.zhang@intel.com>
---
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
---
.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 <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <xenctrl.h>
+
+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 <command> [args]\n\n"
+ "List all supported commands by 'xen-ndctl list-cmds'.\n"
+ "Get help of a command by 'xen-ndctl help <command>'.\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;
+}
--
2.14.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-09-11 4:37 UTC|newest]
Thread overview: 95+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 4:37 [RFC XEN PATCH v3 00/39] Add vNVDIMM support to HVM domains Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 01/39] x86_64/mm: fix the PDX group check in mem_hotadd_check() Haozhong Zhang
2017-10-27 6:49 ` Chao Peng
2017-10-27 7:02 ` Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 02/39] x86_64/mm: drop redundant MFN to page conventions in cleanup_frame_table() Haozhong Zhang
2017-10-27 6:58 ` Chao Peng
2017-10-27 9:24 ` Andrew Cooper
2017-10-30 2:21 ` Chao Peng
2017-09-11 4:37 ` [RFC XEN PATCH v3 03/39] x86_64/mm: avoid cleaning the unmapped frame table Haozhong Zhang
2017-10-27 8:10 ` Chao Peng
2017-09-11 4:37 ` [RFC XEN PATCH v3 04/39] xen/common: add Kconfig item for pmem support Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 05/39] x86/mm: exclude PMEM regions from initial frametable Haozhong Zhang
2017-11-03 5:58 ` Chao Peng
2017-11-03 6:39 ` Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 06/39] acpi: probe valid PMEM regions via NFIT Haozhong Zhang
2017-11-03 6:15 ` Chao Peng
2017-11-03 7:14 ` Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 07/39] xen/pmem: register valid PMEM regions to Xen hypervisor Haozhong Zhang
2017-11-03 6:26 ` Chao Peng
2017-09-11 4:37 ` [RFC XEN PATCH v3 08/39] xen/pmem: hide NFIT and deny access to PMEM from Dom0 Haozhong Zhang
2017-11-03 6:51 ` Chao Peng
2017-11-03 7:24 ` Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 09/39] xen/pmem: add framework for hypercall XEN_SYSCTL_nvdimm_op Haozhong Zhang
2017-11-03 7:40 ` Chao Peng
2017-11-03 8:54 ` Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 10/39] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_get_rgions_nr Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 11/39] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-09-11 4:37 ` Haozhong Zhang [this message]
2017-09-11 5:10 ` [RFC XEN PATCH v3 12/39] tools/xen-ndctl: add NVDIMM management util 'xen-ndctl' Dan Williams
2017-09-11 5:39 ` Haozhong Zhang
2017-09-11 16:35 ` Dan Williams
2017-09-11 21:24 ` Konrad Rzeszutek Wilk
2017-09-13 17:45 ` Dan Williams
2017-09-11 4:37 ` [RFC XEN PATCH v3 13/39] tools/xen-ndctl: add command 'list' Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 14/39] x86_64/mm: refactor memory_add() Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 15/39] x86_64/mm: allow customized location of extended frametable and M2P table Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 16/39] xen/pmem: add XEN_SYSCTL_nvdimm_pmem_setup to setup management PMEM region Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 17/39] tools/xen-ndctl: add command 'setup-mgmt' Haozhong Zhang
2017-09-11 4:37 ` [RFC XEN PATCH v3 18/39] xen/pmem: support PMEM_REGION_TYPE_MGMT for XEN_SYSCTL_nvdimm_pmem_get_regions_nr Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 19/39] xen/pmem: support PMEM_REGION_TYPE_MGMT for XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 20/39] tools/xen-ndctl: add option '--mgmt' to command 'list' Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 21/39] xen/pmem: support setup PMEM region for guest data usage Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 22/39] tools/xen-ndctl: add command 'setup-data' Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 23/39] xen/pmem: support PMEM_REGION_TYPE_DATA for XEN_SYSCTL_nvdimm_pmem_get_regions_nr Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 24/39] xen/pmem: support PMEM_REGION_TYPE_DATA for XEN_SYSCTL_nvdimm_pmem_get_regions Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 25/39] tools/xen-ndctl: add option '--data' to command 'list' Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 26/39] xen/pmem: add function to map PMEM pages to HVM domain Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 27/39] xen/pmem: release PMEM pages on HVM domain destruction Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 28/39] xen: add hypercall XENMEM_populate_pmem_map Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 29/39] tools: reserve guest memory for ACPI from device model Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 30/39] tools/libacpi: expose the minimum alignment used by mem_ops.alloc Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 31/39] tools/libacpi: add callback to translate GPA to GVA Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 32/39] tools/libacpi: add callbacks to access XenStore Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 33/39] tools/libacpi: add a simple AML builder Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 34/39] tools/libacpi: add DM ACPI blacklists Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 35/39] tools/libacpi: load ACPI built by the device model Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 36/39] tools/xl: add xl domain configuration for virtual NVDIMM devices Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 37/39] tools/libxl: allow aborting domain creation on fatal QMP init errors Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 38/39] tools/libxl: initiate PMEM mapping via QMP callback Haozhong Zhang
2017-09-11 4:38 ` [RFC XEN PATCH v3 39/39] tools/libxl: build qemu options from xl vNVDIMM configs Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 00/10] Implement vNVDIMM for Xen HVM guest Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 01/10] nvdimm: do not intiailize nvdimm->label_data if label size is zero Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 02/10] hw/xen-hvm: create the hotplug memory region on Xen Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 03/10] hostmem-xen: add a host memory backend for Xen Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 04/10] nvdimm acpi: do not use fw_cfg on Xen Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 05/10] hw/xen-hvm: initialize DM ACPI Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 06/10] hw/xen-hvm: add function to copy ACPI into guest memory Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 07/10] nvdimm acpi: copy NFIT to Xen guest Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 08/10] nvdimm acpi: copy ACPI namespace device of vNVDIMM " Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 09/10] nvdimm acpi: do not build _FIT method on Xen Haozhong Zhang
2017-09-11 4:41 ` [RFC QEMU PATCH v3 10/10] hw/xen-hvm: enable building DM ACPI if vNVDIMM is enabled Haozhong Zhang
2017-09-11 4:53 ` [Qemu-devel] [RFC QEMU PATCH v3 00/10] Implement vNVDIMM for Xen HVM guest no-reply
2017-09-11 14:08 ` Igor Mammedov
2017-09-11 18:52 ` Stefano Stabellini
2017-09-12 3:15 ` Haozhong Zhang
2017-10-10 16:05 ` Konrad Rzeszutek Wilk
2017-10-12 12:45 ` [Qemu-devel] " Haozhong Zhang
2017-10-12 15:45 ` Paolo Bonzini
2017-10-13 7:53 ` Haozhong Zhang
2017-10-13 8:44 ` Igor Mammedov
2017-10-13 11:13 ` Haozhong Zhang
2017-10-13 12:13 ` Jan Beulich
2017-10-13 22:46 ` Stefano Stabellini
2017-10-15 0:31 ` Michael S. Tsirkin
2017-10-16 14:49 ` Konrad Rzeszutek Wilk
2017-10-17 11:45 ` Paolo Bonzini
2017-10-17 12:16 ` Haozhong Zhang
2017-10-18 8:32 ` Roger Pau Monné
2017-10-18 8:46 ` Paolo Bonzini
2017-10-18 8:55 ` Roger Pau Monné
2017-10-15 0:35 ` Michael S. Tsirkin
2017-10-12 17:39 ` Konrad Rzeszutek Wilk
2017-10-13 8:00 ` Haozhong Zhang
2017-10-27 3:26 ` [RFC XEN PATCH v3 00/39] Add vNVDIMM support to HVM domains Chao Peng
2017-10-27 4:25 ` Haozhong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170911043820.14617-13-haozhong.zhang@intel.com \
--to=haozhong.zhang@intel.com \
--cc=chao.p.peng@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=ian.jackson@eu.citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).