From patchwork Mon Sep 11 04:38:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9946563 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 66C076035D for ; Mon, 11 Sep 2017 04:41:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D1CB289DE for ; Mon, 11 Sep 2017 04:41:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5233828AD7; Mon, 11 Sep 2017 04:41:24 +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 E823F289DE for ; Mon, 11 Sep 2017 04:41:23 +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 1drGVO-0001sJ-QP; Mon, 11 Sep 2017 04:39:30 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drGVN-0001aR-A2 for xen-devel@lists.xen.org; Mon, 11 Sep 2017 04:39:29 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 11/1B-03093-18316B95; Mon, 11 Sep 2017 04:39:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpgkeJIrShJLcpLzFFi42Jpa+sQ0W0Q3hZ psOmWksWSj4tZHBg9ju7+zRTAGMWamZeUX5HAmvF6fmLBfcGK7oXtLA2Ma3i7GLk4hASmM0os n/6TqYuRk0NCgFfiyLIZrBB2gMSBV7fYIYp6GSVaTi8CK2IT0JdY8fggWJGIgLTEtc+XGUFsZ oE/jBL3PsmC2MICERKNbzeB1bMIqEqsaZzGBmLzCthJrP77ixFigbzErraLYHM4geIHX75jBr GFBGwlFpxewDqBkXcBI8MqRo3i1KKy1CJdI3O9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK 95PzcTYzAcGAAgh2Mi9cGHmKU5GBSEuV9d3xLpBBfUn5KZUZicUZ8UWlOavEhRhkODiUJXhWh bZFCgkWp6akVaZk5wMCESUtw8CiJ8EaBpHmLCxJzizPTIVKnGI05jm26/IeJo+Pm3T9MQix5+ XmpUuK8ciClAiClGaV5cINgEXOJUVZKmJcR6DQhnoLUotzMElT5V4ziHIxKwrwRIFN4MvNK4P a9AjqFCegUnktbQE4pSURISTUwsp3ddOLiHN/55noPvNqfOZ+fzhP1QpyxRjDo/unuCwceyOw xOat/LvNq2UOvb1kzuAOjL0l8OvSXV6ZFQst2evBPrh/zlBMCS5p8XvKutM4WT3ud+bCSI49B cqJz6SzRkkvMq7c6aDpG6DecMLF5zn/2Y2/3lqJmT5HLTz59+btMZE7AhWPNSizFGYmGWsxFx YkAQJp41JMCAAA= X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1505104735!56506342!15 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 49745 invoked from network); 11 Sep 2017 04:39:28 -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:28 -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:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.42,376,1500966000"; d="scan'208"; a="1217078450" 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:25 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 11 Sep 2017 12:38:01 +0800 Message-Id: <20170911043820.14617-21-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 20/39] tools/xen-ndctl: add option '--mgmt' to 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 If the option '--mgmt' is present, the command 'list' will list all PMEM regions for management usage. Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu --- tools/misc/xen-ndctl.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tools/misc/xen-ndctl.c b/tools/misc/xen-ndctl.c index 1289a83dbe..058f8ccaf5 100644 --- a/tools/misc/xen-ndctl.c +++ b/tools/misc/xen-ndctl.c @@ -57,9 +57,10 @@ static const struct xen_ndctl_cmd { .name = "list", - .syntax = "[--all | --raw ]", + .syntax = "[--all | --raw | --mgmt]", .help = "--all: the default option, list all PMEM regions of following types.\n" - "--raw: list all PMEM regions detected by Xen hypervisor.\n", + "--raw: list all PMEM regions detected by Xen hypervisor.\n" + "--mgmt: list all PMEM regions for management usage.\n", .handler = handle_list, .need_xc = true, }, @@ -162,12 +163,46 @@ static int handle_list_raw(void) return rc; } +static int handle_list_mgmt(void) +{ + int rc; + unsigned int nr = 0, i; + xen_sysctl_nvdimm_pmem_mgmt_region_t *mgmt_list; + + rc = xc_nvdimm_pmem_get_regions_nr(xch, PMEM_REGION_TYPE_MGMT, &nr); + if ( rc ) + { + fprintf(stderr, "Cannot get the number of PMEM regions: %s.\n", + strerror(-rc)); + return rc; + } + + mgmt_list = malloc(nr * sizeof(*mgmt_list)); + if ( !mgmt_list ) + return -ENOMEM; + + rc = xc_nvdimm_pmem_get_regions(xch, PMEM_REGION_TYPE_MGMT, mgmt_list, &nr); + if ( rc ) + goto out; + + printf("Management PMEM regions:\n"); + for ( i = 0; i < nr; i++ ) + printf(" %u: MFN 0x%lx - 0x%lx, used 0x%lx\n", + i, mgmt_list[i].smfn, mgmt_list[i].emfn, mgmt_list[i].used_mfns); + + out: + free(mgmt_list); + + return rc; +} + static const struct list_handlers { const char *option; int (*handler)(void); } list_hndrs[] = { { "--raw", handle_list_raw }, + { "--mgmt", handle_list_mgmt }, }; static const unsigned int nr_list_hndrs =