From patchwork Wed Jun 8 14:28:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9164951 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 3C5E9604DB for ; Wed, 8 Jun 2016 14:52:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2970C27BE5 for ; Wed, 8 Jun 2016 14:52:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E20328303; Wed, 8 Jun 2016 14:52:56 +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 9F56327BE5 for ; Wed, 8 Jun 2016 14:52:55 +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 1bAeoR-0003uk-Cn; Wed, 08 Jun 2016 14:50:31 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAeoQ-0003uS-74 for xen-devel@lists.xenproject.org; Wed, 08 Jun 2016 14:50:30 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id A1/DF-06230-5B038575; Wed, 08 Jun 2016 14:50:29 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrohUnerQUS 4waNbHBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0bnvO+MBf9lK35f/MbewNgr0sXIwSEh4C9x +7NtFyMnB5uAssTPzl42EFtEQE+i6cBzRhCbWaBcYv68NnYQW1jAR6JjWzMriM0ioCKxf/56J hCbV8BZ4sL232C2hICcxPnjP5lBbE4BF4nFC5+AxYWAaiY+P8IGYStIdEw/BtUrKHFy5hMWiF 0SEgdfvGCGOI1b4m+3/QRGvllIqmYhqVrAyLSKUb04tagstUjXWC+pKDM9oyQ3MTNH19DATC8 3tbg4MT01JzGpWC85P3cTIzCcGIBgB2PHP6dDjJIcTEqivIru4eFCfEn5KZUZicUZ8UWlOanF hxhlODiUJHhD9CPChQSLUtNTK9Iyc4CBDZOW4OBREuEtAEnzFhck5hZnpkOkTjEqSonzJoMkB EASGaV5cG2waLrEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYV53kCk8mXklcNNfAS1mAlq8/E g4yOKSRISUVAOjzBXTgIMxqy7/dV6wc0Z3LWvg8iZfkxlRLnkvb6n91db38WSfWL7xze/G7/m Bs7v+vr9SwL75gteObWe5j2Z9SrBRmbf6wKsH0+svcmw+OCE3qDXy/+ok3d1HmDJeX3W7nrwt 9PbnrRa17lMLTM+ZLQvY7i8ZWCaXK2TwY909v6nVf3f+rHURVWIpzkg01GIuKk4EAM8eJXihA gAA X-Env-Sender: prvs=960e31256=wei.liu2@citrix.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1465397427!18075056!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21280 invoked from network); 8 Jun 2016 14:50:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 8 Jun 2016 14:50:28 -0000 X-IronPort-AV: E=Sophos;i="5.26,439,1459814400"; d="scan'208";a="359171472" From: Wei Liu To: Xen-devel Date: Wed, 8 Jun 2016 15:28:45 +0100 Message-ID: <1465396126-27426-3-git-send-email-wei.liu2@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465396126-27426-1-git-send-email-wei.liu2@citrix.com> References: <1465396126-27426-1-git-send-email-wei.liu2@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Anthony PERARD , Wei Liu , Ian Jackson Subject: [Xen-devel] [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ... because the available vcpu bitmap can change during domain life time due to cpu hotplug and unplug. For QEMU upstream, we interrogate QEMU for the number of vcpus. For others, we look directly into xenstore for information. Reported-by: Jan Beulich Signed-off-by: Wei Liu Reviewed-by: Dario Faggioli --- tools/libxl/libxl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 006b83f..02706ab 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -7222,6 +7222,53 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) (*dst)[i] = (*src)[i]; } +static int libxl__update_avail_vcpus_qmp(libxl__gc *gc, uint32_t domid, + unsigned int max_vcpus, + libxl_bitmap *map) +{ + int rc; + + /* For QEMU upstream we always need to return the number + * of cpus present to QEMU whether they are online or not; + * otherwise QEMU won't accept the saved state. + */ + rc = libxl__qmp_query_cpus(gc, domid, map); + if (rc) { + LOG(ERROR, "fail to get number of cpus for domain %d", domid); + goto out; + } + + rc = 0; +out: + return rc; +} + +static int libxl__update_avail_vcpus_xenstore(libxl__gc *gc, uint32_t domid, + unsigned int max_vcpus, + libxl_bitmap *map) +{ + int rc; + unsigned int i; + const char *dompath; + + dompath = libxl__xs_get_dompath(gc, domid); + if (!dompath) { + rc = ERROR_FAIL; + goto out; + } + + for (i = 0; i < max_vcpus; i++) { + const char *path = GCSPRINTF("%s/cpu/%u/availability", dompath, i); + const char *content = libxl__xs_read(gc, XBT_NULL, path); + if (!strncmp(content, "online", strlen("online"))) + libxl_bitmap_set(map, i); + } + + rc = 0; +out: + return rc; +} + int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, libxl_domain_config *d_config) { @@ -7270,6 +7317,46 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, libxl_dominfo_dispose(&info); } + /* VCPUs */ + { + libxl_bitmap *map = &d_config->b_info.avail_vcpus; + unsigned int max_vcpus = d_config->b_info.max_vcpus; + + libxl_bitmap_dispose(map); + libxl_bitmap_init(map); + libxl_bitmap_alloc(CTX, map, max_vcpus); + libxl_bitmap_set_none(map); + + switch (d_config->b_info.type) { + case LIBXL_DOMAIN_TYPE_HVM: + switch (d_config->b_info.device_model_version) { + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: + rc = libxl__update_avail_vcpus_qmp(gc, domid, + max_vcpus, map); + break; + case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: + case LIBXL_DEVICE_MODEL_VERSION_NONE: + rc = libxl__update_avail_vcpus_xenstore(gc, domid, + max_vcpus, map); + break; + default: + abort(); + } + break; + case LIBXL_DOMAIN_TYPE_PV: + rc = libxl__update_avail_vcpus_xenstore(gc, domid, + max_vcpus, map); + break; + default: + abort(); + } + + if (rc) { + LOG(ERROR, "fail to update available cpu map for domain %d", domid); + goto out; + } + } + /* Memory limits: * * Currently there are three memory limits: