From patchwork Fri Aug 2 15:36:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 11073803 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2300E1395 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10AAE28872 for ; Fri, 2 Aug 2019 15:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 046E72887A; Fri, 2 Aug 2019 15:59:27 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4EF4728872 for ; Fri, 2 Aug 2019 15:59:26 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwj-0006Dg-MN; Fri, 02 Aug 2019 15:58:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htZwg-00067y-MM for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 15:58:18 +0000 X-Inumbo-ID: 56d67ab0-b53e-11e9-a82f-d74d7edca8ec Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 56d67ab0-b53e-11e9-a82f-d74d7edca8ec; Fri, 02 Aug 2019 15:58:16 +0000 (UTC) Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=anthony.perard@citrix.com; spf=Pass smtp.mailfrom=anthony.perard@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of anthony.perard@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa2.hc3370-68.iphmx.com: domain of anthony.perard@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="anthony.perard@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa2.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa2.hc3370-68.iphmx.com; envelope-from="anthony.perard@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: pbKiToo7/G4gAxD0gP+aXCl+MK+IX1CGSK/RyALmc+QmVjRvxCRVrnuL9hivfiWvcDF6kqvrVZ FRLHzXTmBDzPYbQtYZDiGNC30bXicw6NXwlgznegJ9G1ujlZgxZ9uhK8ZB4uz5Z0Z8Dl4rzbVY z9EQW+hswiJkCv1/+hQafrsDGYZsXD3P+2xtcdlFYpW3eMALtMu62CzYJcY0snYb83aBdTSeMv E9c5Wd9QTsDNyESpYHyfrqFqt9/vvCeGAVeWq1okAjoRNMuvBWIK8mvkxtsS9NA585XYUyI3+/ mW8= X-SBRS: 2.7 X-MesageID: 3787823 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3787823" From: Anthony PERARD To: Date: Fri, 2 Aug 2019 16:36:03 +0100 Message-ID: <20190802153606.32061-33-anthony.perard@citrix.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com> References: <20190802153606.32061-1-anthony.perard@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 32/35] libxl: Use ev_qmp in libxl_set_vcpuonline X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Removed libxl__qmp_cpu_add since it's not used anymore. `cpumap' arg of libxl__set_vcpuonline_xenstore is constified. Signed-off-by: Anthony PERARD Acked-by: Ian Jackson --- tools/libxl/libxl_domain.c | 205 ++++++++++++++++++++++++++--------- tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_qmp.c | 9 -- 3 files changed, 153 insertions(+), 63 deletions(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index 08d3fc9fbc..4726e27d20 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -1432,8 +1432,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid, } static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid, - libxl_bitmap *cpumap, - const libxl_dominfo *info) + const libxl_bitmap *cpumap, + const libxl_dominfo *info) { char *dompath; xs_transaction_t t; @@ -1457,43 +1457,27 @@ static int libxl__set_vcpuonline_xenstore(libxl__gc *gc, uint32_t domid, return rc; } -static int libxl__set_vcpuonline_qmp(libxl__gc *gc, uint32_t domid, - libxl_bitmap *cpumap, - const libxl_dominfo *info) -{ - 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) { - LOGD(ERROR, domid, "Failed to query cpus"); - goto out; - } - - libxl_bitmap_copy_alloc(CTX, &final_map, cpumap); - - 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) { - LOGD(ERROR, domid, "Failed to add cpu %d", i); - goto out; - } - } - - rc = 0; -out: - libxl_bitmap_dispose(¤t_map); - libxl_bitmap_dispose(&final_map); - return rc; -} +typedef struct set_vcpuonline_state { + libxl__ev_qmp qmp; + libxl__ev_time timeout; + const libxl_bitmap *cpumap; + libxl_dominfo info; + libxl_bitmap final_map; + int index; /* for loop on final_map */ +} set_vcpuonline_state; + +static void set_vcpuonline_qmp_cpus_queried(libxl__egc *, libxl__ev_qmp *, + const libxl__json_object *, + int rc); +static void set_vcpuonline_qmp_add_cpu(libxl__egc *, libxl__ev_qmp *, + const libxl__json_object *response, + int rc); +static void set_vcpuonline_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc); +static void set_vcpuonline_done(libxl__egc *egc, + set_vcpuonline_state *svos, + int rc); int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap, @@ -1501,11 +1485,22 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, { AO_CREATE(ctx, domid, ao_how); int rc, maxcpus; - libxl_dominfo info; + set_vcpuonline_state *svos; - libxl_dominfo_init(&info); + GCNEW(svos); + libxl__ev_qmp_init(&svos->qmp); + svos->qmp.ao = ao; + svos->qmp.domid = domid; + svos->qmp.payload_fd = -1; + libxl__ev_time_init(&svos->timeout); + libxl_dominfo_init(&svos->info); + libxl_bitmap_init(&svos->final_map); - rc = libxl_domain_info(CTX, &info, domid); + /* Convenience aliases */ + libxl_dominfo *info = &svos->info; + libxl__ev_qmp *qmp = &svos->qmp; + + rc = libxl_domain_info(CTX, info, domid); if (rc < 0) { LOGED(ERROR, domid, "Getting domain info list"); goto out; @@ -1518,10 +1513,10 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, rc = ERROR_FAIL; goto out; } - if (maxcpus > info.vcpu_max_id + 1) + if (maxcpus > info->vcpu_max_id + 1) { LOGED(ERROR, domid, "Requested %d VCPUs, however maxcpus is %d!", - maxcpus, info.vcpu_max_id + 1); + maxcpus, info->vcpu_max_id + 1); rc = ERROR_FAIL; goto out; } @@ -1532,8 +1527,14 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: break; case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: - rc = libxl__set_vcpuonline_qmp(gc, domid, cpumap, &info); - break; + rc = libxl__ev_time_register_rel(ao, &svos->timeout, + set_vcpuonline_timeout, + LIBXL_QMP_CMD_TIMEOUT * 1000); + if (rc) goto out; + qmp->callback = set_vcpuonline_qmp_cpus_queried; + rc = libxl__ev_qmp_send(gc, qmp, "query-cpus", NULL); + if (rc) goto out; + return AO_INPROGRESS; default: rc = ERROR_INVAL; } @@ -1545,15 +1546,115 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, rc = ERROR_INVAL; } - if (!rc) - rc = libxl__set_vcpuonline_xenstore(gc, domid, cpumap, &info); +out: + set_vcpuonline_done(egc, svos, rc); /* must be last */ + return AO_INPROGRESS; +} + +static void set_vcpuonline_qmp_cpus_queried(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + EGC_GC; + set_vcpuonline_state *svos = CONTAINER_OF(qmp, *svos, qmp); + const libxl__json_object *cpu; + int i; + libxl_bitmap current_map; + + /* Convenience aliases */ + libxl_bitmap *final_map = &svos->final_map; + + libxl_bitmap_init(¤t_map); + + if (rc) goto out; + + libxl_bitmap_alloc(CTX, ¤t_map, svos->info.vcpu_max_id + 1); + libxl_bitmap_set_none(¤t_map); + + for (i = 0; (cpu = libxl__json_array_get(response, i)); i++) { + unsigned int cpu_index; + const libxl__json_object *o; + + o = libxl__json_map_get("CPU", cpu, JSON_INTEGER); + if (!o) { + LOGD(ERROR, qmp->domid, "Failed to retrieve CPU index."); + rc = ERROR_QEMU_API; + goto out; + } + + cpu_index = libxl__json_object_get_integer(o); + libxl_bitmap_set(¤t_map, cpu_index); + } + + + libxl_bitmap_copy_alloc(CTX, final_map, svos->cpumap); + + libxl_for_each_set_bit(i, current_map) { + libxl_bitmap_reset(final_map, i); + } out: - libxl_dominfo_dispose(&info); - if (rc) - return AO_CREATE_FAIL(rc); + libxl_bitmap_dispose(¤t_map); + svos->index = -1; + set_vcpuonline_qmp_add_cpu(egc, qmp, NULL, rc); /* must be last */ +} + +static void set_vcpuonline_qmp_add_cpu(libxl__egc *egc, + libxl__ev_qmp *qmp, const libxl__json_object *response, int rc) +{ + STATE_AO_GC(qmp->ao); + set_vcpuonline_state *svos = CONTAINER_OF(qmp, *svos, qmp); + libxl__json_object *args = NULL; + + /* Convenience aliases */ + libxl_bitmap *map = &svos->final_map; + + if (rc) goto out; + + while (libxl_bitmap_cpu_valid(map, ++svos->index)) { + if (libxl_bitmap_test(map, svos->index)) { + qmp->callback = set_vcpuonline_qmp_add_cpu; + libxl__qmp_param_add_integer(gc, &args, "id", svos->index); + rc = libxl__ev_qmp_send(gc, qmp, "cpu-add", args); + if (rc) goto out; + return; + } + } + +out: + set_vcpuonline_done(egc, svos, rc); +} + +static void set_vcpuonline_timeout(libxl__egc *egc, libxl__ev_time *ev, + const struct timeval *requested_abs, + int rc) +{ + EGC_GC; + set_vcpuonline_state *svos = CONTAINER_OF(ev, *svos, timeout); + + if (rc == ERROR_TIMEDOUT) + LOGD(ERROR, svos->qmp.domid, + "Setting CPU online in QEMU timed out"); + + set_vcpuonline_done(egc, svos, rc); +} + +static void set_vcpuonline_done(libxl__egc *egc, + set_vcpuonline_state *svos, + int rc) +{ + STATE_AO_GC(svos->qmp.ao); + + /* Convenience aliases */ + libxl_domid domid = svos->qmp.domid; + + if (!rc) + rc = libxl__set_vcpuonline_xenstore(gc, domid, svos->cpumap, + &svos->info); + + libxl_bitmap_dispose(&svos->final_map); + libxl_dominfo_dispose(&svos->info); + libxl__ev_qmp_dispose(gc, &svos->qmp); libxl__ao_complete(egc, ao, rc); - return AO_INPROGRESS; } static void domain_s3_resume_done(libxl__egc *egc, libxl__ev_qmp *qmp, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index c6b9655af2..03e99b23f5 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1987,8 +1987,6 @@ _hidden libxl__qmp_handler *libxl__qmp_initialize(libxl__gc *gc, _hidden int libxl__qmp_resume(libxl__gc *gc, int domid); /* Load current QEMU state from file. */ _hidden int libxl__qmp_restore(libxl__gc *gc, int domid, const char *filename); -/* Add a virtual CPU */ -_hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index); /* Query the bitmap of CPUs */ _hidden int libxl__qmp_query_cpus(libxl__gc *gc, int domid, libxl_bitmap *map); diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 40043a0a45..27183bc6c4 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -767,15 +767,6 @@ int libxl__qmp_resume(libxl__gc *gc, int domid) return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL); } -int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) -{ - libxl__json_object *args = NULL; - - libxl__qmp_param_add_integer(gc, &args, "id", idx); - - return qmp_run_command(gc, domid, "cpu-add", args, NULL, NULL); -} - static int query_cpus_callback(libxl__qmp_handler *qmp, const libxl__json_object *response, void *opaque)