From patchwork Wed Jun 15 09:31:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9177923 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 B24ED60573 for ; Wed, 15 Jun 2016 09:34:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A344C27EED for ; Wed, 15 Jun 2016 09:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 982C92818B; Wed, 15 Jun 2016 09:34:18 +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 72B6327F3E for ; Wed, 15 Jun 2016 09:34:17 +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 1bD7Ax-0001sv-Bd; Wed, 15 Jun 2016 09:31:55 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bD7Aw-0001sc-Fi for xen-devel@lists.xenproject.org; Wed, 15 Jun 2016 09:31:54 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 2E/D9-20705-98021675; Wed, 15 Jun 2016 09:31:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrohUrdTITH cYMtrYYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePBugvMBduVKjZMesnewLhdvIuRk0NCwF/i 7YkzLCA2m4CyxM/OXjYQW0RAT6LpwHNGEJtZoFyic+tnVhBbWMBHYt7Xy2D1LAKqEk8uXmcHs XkFnCVWHJnBCjFTTuL88Z/MIDangIvE7BsvgWZycAgB1RxaJwsSFhJQkOiYfowJolVQ4uTMJy wQqyQkDr54wQwxhlvi9umpzBMY+WYhKZuFpGwBI9MqRvXi1KKy1CJdC72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMCAYgCCHYwX2p0PMUpyMCmJ8nrIJYYL8SXlp1RmJBZnxBeV 5qQWH2KU4eBQkuCdIA+UEyxKTU+tSMvMAYY2TFqCg0dJhFcDJM1bXJCYW5yZDpE6xagoJc57G iQhAJLIKM2Da4PF0yVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ8z4BmcKTmVcCN/0V0GImoM U20+NBFpckIqSkGhjXfZhjtei+2Nd/K96nxJ16MtNJf78BS/Y2lhcXf79/FMv+lu/6yZzQDTc m/JdX3rZSgGXXJlGtpuRXJ6JZKvmvrY8p36WZrqXd7qr/RcqWoWZedWbC/xv9tyOY7y5sDj6v 3CJluOTovgVq/y1Yj600CwrkZtl6yUB7ybMbt+IWzuhQN1t4T1pViaU4I9FQi7moOBEAHafUj KICAAA= X-Env-Sender: prvs=967af9503=wei.liu2@citrix.com X-Msg-Ref: server-13.tower-31.messagelabs.com!1465983109!44898839!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 39956 invoked from network); 15 Jun 2016 09:31:52 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-13.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 15 Jun 2016 09:31:52 -0000 X-IronPort-AV: E=Sophos;i="5.26,475,1459814400"; d="scan'208";a="360542356" From: Wei Liu To: Xen-devel Date: Wed, 15 Jun 2016 10:31:41 +0100 Message-ID: <1465983102-19308-5-git-send-email-wei.liu2@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1465983102-19308-1-git-send-email-wei.liu2@citrix.com> References: <1465983102-19308-1-git-send-email-wei.liu2@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Anthony PERARD , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v3 4/5] 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: Anthony PERARD --- Cc: Ian Jackson Cc: Anthony PERARD v3: 1. Fix indentation of abort. 2. Use strcmp instead of strncmp. --- tools/libxl/libxl.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 65af9ee..b748bf1 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -7246,6 +7246,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 (!strcmp(content, "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) { @@ -7294,6 +7341,55 @@ 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_device_model_version version; + + libxl_bitmap_dispose(map); + libxl_bitmap_init(map); + libxl_bitmap_alloc(CTX, map, max_vcpus); + libxl_bitmap_set_none(map); + + /* If the user did not explicitly specify a device model + * version, we need to use the same logic used during domain + * creation to derive the device model version. + */ + version = d_config->b_info.device_model_version; + if (version == LIBXL_DEVICE_MODEL_VERSION_UNKNOWN) + version = libxl__get_device_model_version(gc, &d_config->b_info); + + switch (d_config->b_info.type) { + case LIBXL_DOMAIN_TYPE_HVM: + switch (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: