From patchwork Wed Jun 15 09:31:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9177917 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 599B460831 for ; Wed, 15 Jun 2016 09:34:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AE3E27F3E for ; Wed, 15 Jun 2016 09:34:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FDD72818B; Wed, 15 Jun 2016 09:34:17 +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 EA8B928345 for ; Wed, 15 Jun 2016 09:34:16 +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 1bD7Au-0001rk-Et; Wed, 15 Jun 2016 09:31:52 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bD7At-0001rb-5j for xen-devel@lists.xenproject.org; Wed, 15 Jun 2016 09:31:51 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id BA/60-02783-68021675; Wed, 15 Jun 2016 09:31:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHSDvW6zQmK 4wa+1Jhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a9JVuZCmYKVXx/No+tgfExbxcjJ4eEgL/E hbNvmEBsNgFliZ+dvWwgtoiAnkTTgeeMIDazQLlE59bPrCC2sECQxJy918HiLAKqErdOLAKze QWcJV7+nMgIMVNO4vzxn8wgNqeAi8TsGy+BZnJwCAHVHFonCxIWElCQ6Jh+jAmiVVDi5MwnLB CrJCQOvnjBDDGGW+L26anMExj5ZiEpm4WkbAEj0ypGjeLUorLUIl1DQ72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMCQYgCCHYyrfzsdYpTkYFIS5fWQSwwX4kvKT6nMSCzOiC8q zUktPsQow8GhJME7QR4oJ1iUmp5akZaZAwxumLQEB4+SCK8GSJq3uCAxtzgzHSJ1ilFRSpw3B SQhAJLIKM2Da4NF1CVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ864AmcKTmVcCN/0V0GImoM U20+NBFpckIqSkGhgncjPYSNyKZFB7rSvq+KNSV6d4WU7RJs1ZRUuXCfg486QprpycujxUTlm jRUlsoocT4+llZwq7uc5+/fbQaKKOaBbDlV3zo+4ZCN2e+uNuR/99lY3RsivmSV9ZuOrw7ckn nZ/7a3k7M76sfuvcFPzG54K5p6X1ptYQjeQP8Z92PlF0cOx5uFWJpTgj0VCLuag4EQCAzU45o wIAAA== X-Env-Sender: prvs=967af9503=wei.liu2@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1465983104!19238295!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3079 invoked from network); 15 Jun 2016 09:31:47 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 15 Jun 2016 09:31:47 -0000 X-IronPort-AV: E=Sophos;i="5.26,475,1459814400"; d="scan'208";a="367406689" From: Wei Liu To: Xen-devel Date: Wed, 15 Jun 2016 10:31:42 +0100 Message-ID: <1465983102-19308-6-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 5/5] libxl: only issue cpu-add call to QEMU for not present CPU 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 Calculate the final bitmap for CPUs to add to avoid having annoying error messages complaining those CPUs are already present. We can also properly handle error from QMP now. Signed-off-by: Wei Liu Reviewed-by: Anthony PERARD --- Cc: Ian Jackson Cc: Anthony PERARD v3: 1. Add Anthony's Reviewed-by tag. --- tools/libxl/libxl.c | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index b748bf1..0e2c15a 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -5753,19 +5753,38 @@ static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid, libxl_bitmap *cpumap, const libxl_dominfo *info) { - int i; + int i, rc; + libxl_bitmap current_map, final_map; + + libxl_bitmap_init(¤t_map); + libxl_bitmap_init(&final_map); + + libxl_bitmap_alloc(CTX, ¤t_map, info->vcpu_max_id + 1); + libxl_bitmap_set_none(¤t_map); + rc = libxl__qmp_query_cpus(gc, domid, ¤t_map); + if (rc) { + LOG(ERROR, "failed to query cpus for domain %d", domid); + goto out; + } + + libxl_bitmap_copy_alloc(CTX, &final_map, cpumap); - for (i = 0; i <= info->vcpu_max_id; i++) { - if (libxl_bitmap_test(cpumap, i)) { - /* Return value is ignore because it does not tell anything useful - * on the completion of the command. - * (For instance, "CPU already plugged-in" give the same return - * value as "command not supported".) - */ - libxl__qmp_cpu_add(gc, domid, i); + libxl_for_each_set_bit(i, current_map) + libxl_bitmap_reset(&final_map, i); + + libxl_for_each_set_bit(i, final_map) { + rc = libxl__qmp_cpu_add(gc, domid, i); + if (rc) { + LOG(ERROR, "failed to add cpu %d to domain %d", i, domid); + goto out; } } - return 0; + + rc = 0; +out: + libxl_bitmap_dispose(¤t_map); + libxl_bitmap_dispose(&final_map); + return rc; } int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)