From patchwork Mon Mar 20 00:09:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 9632881 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 C37DD6020B for ; Mon, 20 Mar 2017 00:15:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B74DF27F8C for ; Mon, 20 Mar 2017 00:15:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC33A27FBC; Mon, 20 Mar 2017 00:15:51 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 3D9C527F8C for ; Mon, 20 Mar 2017 00:15:51 +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 1cpkx6-00077e-0k; Mon, 20 Mar 2017 00:13:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpkx4-00073u-8B for xen-devel@lists.xen.org; Mon, 20 Mar 2017 00:13:34 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 7D/8E-20914-DAE1FC85; Mon, 20 Mar 2017 00:13:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsVywNykWHeN3Pk Ig5m7jC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ox5nfuZC07pVbx/uJClgbFdqYuRi4NF4BaT RG/rI0YQR0hgOqPEudcLWbsYOTkkBHgljiybAWX7SVyc/owdxBYS6GWUuLBcBMRmE9CXWPH4I FiNiIC0xLXPl8EGMQucZZSYvqYVrEFYIFTiz8v7YEUsAqoSh/8eYQGxeQXsJGbfWc4MsUBe4s LVU2BxTqD4mku3oZbZSuy/NY1tAiPfAkaGVYwaxalFZalFuoYmeklFmekZJbmJmTm6hgbGerm pxcWJ6ak5iUnFesn5uZsYgaHCAAQ7GFds9zzEKMnBpCTKW/7jRIQQX1J+SmVGYnFGfFFpTmrx IUYZDg4lCd4jSicjhASLUtNTK9Iyc4BBC5OW4OBREuHNBUnzFhck5hZnpkOkTjEqSonzXgBJC IAkMkrz4NpgkXKJUVZKmJcR6BAhnoLUotzMElT5V4ziHIxKwrybQabwZOaVwE1/BbSYCWjx2w 8nQBaXJCKkpBoYw28I+52f8Ozy3s7Z0/d6uAQqvN7qOW13mOSdVoOHW00/mJ3u3u5vFm61lG3 jC4//diJP26t/tl9eLC5gqpl/OOb3PnWprQnXjGv2Ks0M62F6Wee+RfKN89dlNaULkm/u2h18 92Wy18YArduqu+rOz9G0deqbyrV2C6shr2rIhgMvef8v2tG8UImlOCPRUIu5qDgRAL5JANSPA gAA X-Env-Sender: haozhong.zhang@intel.com X-Msg-Ref: server-8.tower-31.messagelabs.com!1489968802!91050058!5 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 57511 invoked from network); 20 Mar 2017 00:13:32 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-8.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2017 00:13:32 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1489968812; x=1521504812; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=uQI9yQ7UitA1Y9w9Cee0m6IC0HCDWD9q72RSvKb1Zxo=; b=Isc+DNAJdhUUCkQHPxQYeprzPZTASqCjSpLkCB+f0dHPR/rlRSGyHVXT DLhSVr0kpaKjQRv/b2m3mOefWCHTVw==; Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Mar 2017 17:13:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,191,1486454400"; d="scan'208";a="78799242" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.159.153]) by fmsmga006.fm.intel.com with ESMTP; 19 Mar 2017 17:13:30 -0700 From: Haozhong Zhang To: xen-devel@lists.xen.org Date: Mon, 20 Mar 2017 08:09:48 +0800 Message-Id: <20170320000949.24675-15-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170320000949.24675-1-haozhong.zhang@intel.com> References: <20170320000949.24675-1-haozhong.zhang@intel.com> Cc: Konrad Rzeszutek Wilk , Dan Williams , Ian Jackson , Wei Liu , Haozhong Zhang Subject: [Xen-devel] [RFC XEN PATCH v2 14/15] tools/libxl: initiate pmem mapping via qmp callback 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 Get the backend device, the guest SPA and the size of each vNVDIMM device via QMP commands "query-memory-device devtype=nvdimm" and "qom-get", and pass them to libxl to map each backend device to guest. Signed-off-by: Haozhong Zhang --- Cc: Ian Jackson Cc: Wei Liu Changes in v2: * Fail the domain creation if QMP initialization for NVDIMM fails. Other failures in QMP initialization do not fail the domain creation as before. --- tools/libxl/libxl_create.c | 4 +- tools/libxl/libxl_qmp.c | 116 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index e741b9a39a..b8c867d0fa 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1510,7 +1510,9 @@ static void domcreate_devmodel_started(libxl__egc *egc, if (dcs->sdss.dm.guest_domid) { if (d_config->b_info.device_model_version == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) { - libxl__qmp_initializations(gc, domid, d_config); + ret = libxl__qmp_initializations(gc, domid, d_config); + if (ret == ERROR_BADFAIL) + goto error_out; } } diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index a91643a4f9..244d4bee5a 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -26,6 +26,7 @@ #include "_libxl_list.h" #include "libxl_internal.h" +#include "libxl_nvdimm.h" /* #define DEBUG_RECEIVED */ @@ -1146,6 +1147,111 @@ out: return rc; } +static int qmp_nvdimm_get_mempath(libxl__qmp_handler *qmp, + const libxl__json_object *o, + void *opaque) +{ + const char **output = opaque; + const char *mem_path; + int rc = 0; + GC_INIT(qmp->ctx); + + if (!o) { + rc = ERROR_FAIL; + goto out; + } + + mem_path = libxl__json_object_get_string(o); + if (!mem_path) { + rc = ERROR_FAIL; + goto out; + } + *output = libxl__strdup(NOGC, mem_path); + + out: + GC_FREE; + return 0; +} + +static int qmp_register_nvdimm_callback(libxl__qmp_handler *qmp, + const libxl__json_object *o, + void *unused) +{ + GC_INIT(qmp->ctx); + const libxl__json_object *obj, *sub_obj, *sub_map; + libxl__json_object *args = NULL; + unsigned int i = 0; + const char *mem_path = NULL, *memdev; + uint64_t slot, spa, size; + int rc = 0; + + for (i = 0; (obj = libxl__json_array_get(o, i)); i++) { + if (!libxl__json_object_is_map(obj)) + continue; + + sub_map = libxl__json_map_get("data", obj, JSON_MAP); + if (!sub_map) + continue; + + sub_obj = libxl__json_map_get("slot", sub_map, JSON_INTEGER); + slot = libxl__json_object_get_integer(sub_obj); + + sub_obj = libxl__json_map_get("memdev", sub_map, JSON_STRING); + memdev = libxl__json_object_get_string(sub_obj); + if (!memdev) { + LOG(ERROR, "Cannot get backend memdev of NVDIMM #%" PRId64, slot); + rc = ERROR_FAIL; + goto out; + } + qmp_parameters_add_string(gc, &args, "path", memdev); + qmp_parameters_add_string(gc, &args, "property", "mem-path"); + rc = qmp_synchronous_send(qmp, "qom-get", args, qmp_nvdimm_get_mempath, + &mem_path, qmp->timeout); + if (rc) { + LOG(ERROR, "Cannot get the backend device of NVDIMM #%" PRId64, slot); + goto out; + } + + sub_obj = libxl__json_map_get("addr", sub_map, JSON_INTEGER); + spa = libxl__json_object_get_integer(sub_obj); + + sub_obj = libxl__json_map_get("size", sub_map, JSON_INTEGER); + size = libxl__json_object_get_integer(sub_obj); + + LOG(DEBUG, + "vNVDIMM #%" PRId64 ": %s, spa 0x%" PRIx64 ", size 0x%" PRIx64, + slot, mem_path, spa, size); + + rc = libxl_nvdimm_add_device(gc, qmp->domid, mem_path, spa, size); + if (rc) { + LOG(ERROR, + "Failed to add NVDIMM #%" PRId64 + "(mem_path %s, spa 0x%" PRIx64 ", size 0x%" PRIx64 ") " + "to domain %d (err = %d)", + slot, mem_path, spa, size, qmp->domid, rc); + goto out; + } + } + + out: + GC_FREE; + return rc; +} + +static int libxl__qmp_query_nvdimms(libxl__qmp_handler *qmp) +{ + libxl__json_object *args = NULL; + int rc; + GC_INIT(qmp->ctx); + + qmp_parameters_add_string(gc, &args, "devtype", "nvdimm"); + rc = qmp_synchronous_send(qmp, "query-memory-devices", args, + qmp_register_nvdimm_callback, NULL, qmp->timeout); + + GC_FREE; + return rc; +} + int libxl__qmp_hmp(libxl__gc *gc, int domid, const char *command_line, char **output) { @@ -1174,11 +1280,12 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, { const libxl_vnc_info *vnc = libxl__dm_vnc(guest_config); libxl__qmp_handler *qmp = NULL; + bool ignore_error = true; int ret = 0; qmp = libxl__qmp_initialize(gc, domid); if (!qmp) - return -1; + return ERROR_FAIL; ret = libxl__qmp_query_serial(qmp); if (!ret && vnc && vnc->passwd) { ret = qmp_change(gc, qmp, "vnc", "password", vnc->passwd); @@ -1187,8 +1294,13 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid, if (!ret) { ret = qmp_query_vnc(qmp); } + if (!ret && guest_config->num_vnvdimms) { + ret = libxl__qmp_query_nvdimms(qmp); + ignore_error = false; + } libxl__qmp_close(qmp); - return ret; + + return ret ? (ignore_error ? ERROR_FAIL : ERROR_BADFAIL) : 0; } /*