From patchwork Mon Sep 11 04:37:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946607 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 93357603F4 for ; Mon, 11 Sep 2017 04:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8953021C9A for ; Mon, 11 Sep 2017 04:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E48E27F2B; Mon, 11 Sep 2017 04:42:05 +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 2404C27D0C for ; Mon, 11 Sep 2017 04:42:05 +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 1drGV9-0001TZ-SR; Mon, 11 Sep 2017 04:39:15 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGV8-0001Li-Mn for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:14 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 97/3B-03454-27316B95; Mon, 11 Sep 2017 04:39:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrHLMWRWlGSWpSXmKPExsXS1tYholsgvC3 SYM98VYslHxezODB6HN39mymAMYo1My8pvyKBNePI0oeMBRMkKyadjmlg7BbuYuTiEBKYziix 7PAvpi5GTg4JAV6JI8tmsELYARK/P30Ds4UEehklltyTAbHZBPQlVjw+CBYXEZCWuPb5MiOIz Szwh1Hi3idZEFtYwFXi5cbJQDM5OFgEVCW+vqgECfMK2ElsP9vKDDFeXmJX20WwMZxA8YMv3z FDrLKVWHB6AesERt4FjAyrGDWKU4vKUot0jcz1kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r 1kvNzNzECQ4EBCHYwLl4beIhRkoNJSZT33fEtkUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeM8I bosUEixKTU+tSMvMAQYlTFqCg0dJhHcRSJq3uCAxtzgzHSJ1itGY49imy3+YODpu3v3DJMSSl 5+XKiXOuxmkVACkNKM0D24QLFouMcpKCfMyAp0mxFOQWpSbWYIq/4pRnINRSZhXRghoCk9mXg ncvldApzABncJzaQvIKSWJCCmpBkb3SfeMuv3+ued0hez8sqcqtEGvjq3vZdKSWwcvZDlPuO+ w9v/zIKFXT9RnXtbkcPiy3DezvcBxwnejmR+/WzI+PrAl7uwkpciTVa8ct/k77muT2dO/1fkd S0PzXUG7BdnhPz41HjIOnCZTU748/evcsLZXbOVej2O/NL/bfrfrrFiMisXd8yZKLMUZiYZaz EXFiQDgEopYkQIAAA== X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!8 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 48024 invoked from network); 11 Sep 2017 04:39:12 -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:12 -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:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078397" 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:10 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:37:54 +0800 Message-Id: <20170911043820.14617-14-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 13/39] tools/xen-ndctl: add command 'list' 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 Two options are supported by command 'list'. '--raw' indicates to list all PMEM regions detected by Xen hypervisor, which can be later configured for future usages. '--all' indicates all other options (i.e. --raw and future options). Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu --- tools/misc/xen-ndctl.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/tools/misc/xen-ndctl.c b/tools/misc/xen-ndctl.c index de40e29ff6..6277a1eda2 100644 --- a/tools/misc/xen-ndctl.c +++ b/tools/misc/xen-ndctl.c @@ -27,12 +27,14 @@ #include #include +#include #include #include static xc_interface *xch; static int handle_help(int argc, char *argv[]); +static int handle_list(int argc, char *argv[]); static int handle_list_cmds(int argc, char *argv[]); static const struct xen_ndctl_cmd @@ -52,6 +54,15 @@ static const struct xen_ndctl_cmd .handler = handle_help, }, + { + .name = "list", + .syntax = "[--all | --raw ]", + .help = "--all: the default option, list all PMEM regions of following types.\n" + "--raw: list all PMEM regions detected by Xen hypervisor.\n", + .handler = handle_list, + .need_xc = true, + }, + { .name = "list-cmds", .syntax = "", @@ -109,6 +120,70 @@ static int handle_help(int argc, char *argv[]) return 0; } +static int handle_list_raw(void) +{ + int rc; + unsigned int nr = 0, i; + xen_sysctl_nvdimm_pmem_raw_region_t *raw_list; + + rc = xc_nvdimm_pmem_get_regions_nr(xch, PMEM_REGION_TYPE_RAW, &nr); + if ( rc ) + { + fprintf(stderr, "Cannot get the number of PMEM regions: %s.\n", + strerror(-rc)); + return rc; + } + + raw_list = malloc(nr * sizeof(*raw_list)); + if ( !raw_list ) + return -ENOMEM; + + rc = xc_nvdimm_pmem_get_regions(xch, PMEM_REGION_TYPE_RAW, raw_list, &nr); + if ( rc ) + goto out; + + printf("Raw PMEM regions:\n"); + for ( i = 0; i < nr; i++ ) + printf(" %u: MFN 0x%lx - 0x%lx, PXM %u\n", + i, raw_list[i].smfn, raw_list[i].emfn, raw_list[i].pxm); + + out: + free(raw_list); + + return rc; +} + +static const struct list_handlers { + const char *option; + int (*handler)(void); +} list_hndrs[] = +{ + { "--raw", handle_list_raw }, +}; + +static const unsigned int nr_list_hndrs = + sizeof(list_hndrs) / sizeof(list_hndrs[0]); + +static int handle_list(int argc, char *argv[]) +{ + bool list_all = argc <= 1 || !strcmp(argv[1], "--all"); + unsigned int i; + bool handled = false; + int rc = 0; + + for ( i = 0; i < nr_list_hndrs && !rc; i++) + if ( list_all || !strcmp(argv[1], list_hndrs[i].option) ) + { + rc = list_hndrs[i].handler(); + handled = true; + } + + if ( !handled ) + return handle_unrecognized_argument(argv[0], argv[1]); + + return rc; +} + static int handle_list_cmds(int argc, char *argv[]) { unsigned int i;