All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: <xen-devel@lists.xenproject.org>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Wei Liu <wl@xen.org>
Subject: [Xen-devel] [PATCH 34/35] libxl: libxl_retrieve_domain_configuration now uses ev_qmp
Date: Fri, 2 Aug 2019 16:36:05 +0100	[thread overview]
Message-ID: <20190802153606.32061-35-anthony.perard@citrix.com> (raw)
In-Reply-To: <20190802153606.32061-1-anthony.perard@citrix.com>

This was the last user of libxl__qmp_query_cpus which can now be
removed.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
 tools/libxl/libxl_domain.c   | 163 ++++++++++++++++++++++++++++-------
 tools/libxl/libxl_internal.h |   3 -
 tools/libxl/libxl_qmp.c      |  38 --------
 3 files changed, 131 insertions(+), 73 deletions(-)

diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
index b97e874a9c..6a8ffe10f0 100644
--- a/tools/libxl/libxl_domain.c
+++ b/tools/libxl/libxl_domain.c
@@ -1800,27 +1800,6 @@ uint32_t libxl_vm_get_start_time(libxl_ctx *ctx, uint32_t domid)
     return ret;
 }
 
-/* For QEMU upstream we always need to provide the number of cpus present to
- * QEMU whether they are online or not; otherwise QEMU won't accept the saved
- * state. See implementation of libxl__qmp_query_cpus.
- */
-static int libxl__update_avail_vcpus_qmp(libxl__gc *gc, uint32_t domid,
-                                         unsigned int max_vcpus,
-                                         libxl_bitmap *map)
-{
-    int rc;
-
-    rc = libxl__qmp_query_cpus(gc, domid, map);
-    if (rc) {
-        LOGD(ERROR, domid, "Fail to get number of cpus");
-        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)
@@ -1849,13 +1828,61 @@ static int libxl__update_avail_vcpus_xenstore(libxl__gc *gc, uint32_t domid,
     return rc;
 }
 
+typedef struct {
+    libxl__ev_qmp qmp;
+    libxl__ev_time timeout;
+    libxl_domain_config *d_config; /* user pointer */
+    libxl__ev_lock ev_lock;
+    libxl_bitmap qemuu_cpus;
+} retrieve_domain_configuration_state;
+
+static void retrieve_domain_configuration_lock_acquired(
+    libxl__egc *egc, libxl__ev_lock *, int rc);
+static void retrieve_domain_configuration_cpu_queried(
+    libxl__egc *egc, libxl__ev_qmp *qmp,
+    const libxl__json_object *response, int rc);
+static void retrieve_domain_configuration_timeout(libxl__egc *egc,
+    libxl__ev_time *ev, const struct timeval *requested_abs, int rc);
+static void retrieve_domain_configuration_end(libxl__egc *egc,
+    retrieve_domain_configuration_state *rdcs, int rc);
+
 int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
                                         libxl_domain_config *d_config,
                                         const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    int rc;
+    retrieve_domain_configuration_state *rdcs;
+
+    GCNEW(rdcs);
+    libxl__ev_qmp_init(&rdcs->qmp);
+    rdcs->qmp.ao = ao;
+    rdcs->qmp.domid = domid;
+    rdcs->qmp.payload_fd = -1;
+    libxl__ev_time_init(&rdcs->timeout);
+    rdcs->d_config = d_config;
+    libxl_bitmap_init(&rdcs->qemuu_cpus);
+    libxl__ev_lock_init(&rdcs->ev_lock);
+    rdcs->ev_lock.ao = ao;
+    rdcs->ev_lock.domid = domid;
+    rdcs->ev_lock.callback = retrieve_domain_configuration_lock_acquired;
+    libxl__ev_lock_get(egc, &rdcs->ev_lock);
+    return AO_INPROGRESS;
+}
+
+static void retrieve_domain_configuration_lock_acquired(
+    libxl__egc *egc, libxl__ev_lock *ev_lock, int rc)
+{
+    retrieve_domain_configuration_state *rdcs =
+        CONTAINER_OF(ev_lock, *rdcs, ev_lock);
+    STATE_AO_GC(rdcs->qmp.ao);
     libxl__domain_userdata_lock *lock = NULL;
+    bool has_callback = false;
+
+    /* Convenience aliases */
+    libxl_domid domid = rdcs->qmp.domid;
+    libxl_domain_config *const d_config = rdcs->d_config;
+
+    if (rc) goto out;
 
     lock = libxl__lock_domain_userdata(gc, domid);
     if (!lock) {
@@ -1870,10 +1897,81 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
         goto out;
     }
 
+    libxl__unlock_domain_userdata(lock);
+    lock = NULL;
+
+    /* We start by querying QEMU, if it is running, for its cpumap as this
+     * is a long operation. */
+    if (d_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM &&
+        libxl__device_model_version_running(gc, domid) ==
+            LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
+        /* For QEMU upstream we always need to provide the number
+         * of cpus present to QEMU whether they are online or not;
+         * otherwise QEMU won't accept the saved state.
+         */
+        rc = libxl__ev_time_register_rel(ao, &rdcs->timeout,
+            retrieve_domain_configuration_timeout,
+            LIBXL_QMP_CMD_TIMEOUT * 1000);
+        if (rc) goto out;
+        libxl_bitmap_alloc(CTX, &rdcs->qemuu_cpus,
+                           d_config->b_info.max_vcpus);
+        rdcs->qmp.callback = retrieve_domain_configuration_cpu_queried;
+        rc = libxl__ev_qmp_send(gc, &rdcs->qmp, "query-cpus", NULL);
+        if (rc) goto out;
+        has_callback = true;
+    }
+
+out:
+    if (lock) libxl__unlock_domain_userdata(lock);
+    if (!has_callback)
+        retrieve_domain_configuration_end(egc, rdcs, rc);
+}
+
+static void retrieve_domain_configuration_cpu_queried(
+    libxl__egc *egc, libxl__ev_qmp *qmp,
+    const libxl__json_object *response, int rc)
+{
+    EGC_GC;
+    retrieve_domain_configuration_state *rdcs =
+        CONTAINER_OF(qmp, *rdcs, qmp);
+
+    if (rc) goto out;
+
+    rc = qmp_parse_query_cpus(gc, qmp->domid, response, &rdcs->qemuu_cpus);
+
+out:
+    retrieve_domain_configuration_end(egc, rdcs, rc);
+}
+
+static void retrieve_domain_configuration_timeout(libxl__egc *egc,
+    libxl__ev_time *ev, const struct timeval *requested_abs, int rc)
+{
+    retrieve_domain_configuration_state *rdcs =
+        CONTAINER_OF(ev, *rdcs, timeout);
+
+    retrieve_domain_configuration_end(egc, rdcs, rc);
+}
+
+static void retrieve_domain_configuration_end(libxl__egc *egc,
+    retrieve_domain_configuration_state *rdcs, int rc)
+{
+    STATE_AO_GC(rdcs->qmp.ao);
+    libxl__domain_userdata_lock *lock;
+
+    /* Convenience aliases */
+    libxl_domain_config *const d_config = rdcs->d_config;
+    libxl_domid domid = rdcs->qmp.domid;
+
+    lock = libxl__lock_domain_userdata(gc, domid);
+    if (!lock) {
+        rc = ERROR_LOCK_FAIL;
+        goto out;
+    }
+
     /* Domain name */
     {
         char *domname;
-        domname = libxl_domid_to_name(ctx, domid);
+        domname = libxl_domid_to_name(CTX, domid);
         if (!domname) {
             LOGD(ERROR, domid, "Fail to get domain name");
             goto out;
@@ -1886,13 +1984,13 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
     {
         libxl_dominfo info;
         libxl_dominfo_init(&info);
-        rc = libxl_domain_info(ctx, &info, domid);
+        rc = libxl_domain_info(CTX, &info, domid);
         if (rc) {
             LOGD(ERROR, domid, "Fail to get domain info");
             libxl_dominfo_dispose(&info);
             goto out;
         }
-        libxl_uuid_copy(ctx, &d_config->c_info.uuid, &info.uuid);
+        libxl_uuid_copy(CTX, &d_config->c_info.uuid, &info.uuid);
         libxl_dominfo_dispose(&info);
     }
 
@@ -1913,8 +2011,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
             assert(version != LIBXL_DEVICE_MODEL_VERSION_UNKNOWN);
             switch (version) {
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
-                rc = libxl__update_avail_vcpus_qmp(gc, domid,
-                                                   max_vcpus, map);
+                libxl_bitmap_copy(CTX, map, &rdcs->qemuu_cpus);
                 break;
             case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
                 rc = libxl__update_avail_vcpus_xenstore(gc, domid,
@@ -1939,6 +2036,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
         }
     }
 
+
     /* Memory limits:
      *
      * Currently there are three memory limits:
@@ -1972,7 +2070,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
     /* Scheduler params */
     {
         libxl_domain_sched_params_dispose(&d_config->b_info.sched_params);
-        rc = libxl_domain_sched_params_get(ctx, domid,
+        rc = libxl_domain_sched_params_get(CTX, domid,
                                            &d_config->b_info.sched_params);
         if (rc) {
             LOGD(ERROR, domid, "Fail to get scheduler parameters");
@@ -2034,7 +2132,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
 
                 if (j < num) {         /* found in xenstore */
                     if (dt->merge)
-                        dt->merge(ctx, p + dt->dev_elem_size * j, q);
+                        dt->merge(CTX, p + dt->dev_elem_size * j, q);
                 } else {                /* not found in xenstore */
                     LOGD(WARN, domid,
                          "Device present in JSON but not in xenstore, ignored");
@@ -2062,11 +2160,12 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
     }
 
 out:
+    libxl__ev_unlock(gc, &rdcs->ev_lock);
     if (lock) libxl__unlock_domain_userdata(lock);
-    if (rc)
-        return AO_CREATE_FAIL(rc);
+    libxl_bitmap_dispose(&rdcs->qemuu_cpus);
+    libxl__ev_qmp_dispose(gc, &rdcs->qmp);
+    libxl__ev_time_deregister(gc, &rdcs->timeout);
     libxl__ao_complete(egc, ao, rc);
-    return AO_INPROGRESS;
 }
 
 /*
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 03e99b23f5..9144bc202d 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1987,9 +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);
-/* Query the bitmap of CPUs */
-_hidden int libxl__qmp_query_cpus(libxl__gc *gc, int domid,
-                                  libxl_bitmap *map);
 /* Start NBD server */
 _hidden int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid,
                                         const char *host, const char *port);
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 27183bc6c4..9639d491d9 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -767,44 +767,6 @@ int libxl__qmp_resume(libxl__gc *gc, int domid)
     return qmp_run_command(gc, domid, "cont", NULL, NULL, NULL);
 }
 
-static int query_cpus_callback(libxl__qmp_handler *qmp,
-                               const libxl__json_object *response,
-                               void *opaque)
-{
-    libxl_bitmap *map = opaque;
-    unsigned int i;
-    const libxl__json_object *cpu = NULL;
-    int rc;
-    GC_INIT(qmp->ctx);
-
-    libxl_bitmap_set_none(map);
-    for (i = 0; (cpu = libxl__json_array_get(response, i)); i++) {
-        unsigned int idx;
-        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_FAIL;
-            goto out;
-        }
-
-        idx = libxl__json_object_get_integer(o);
-        libxl_bitmap_set(map, idx);
-    }
-
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
-}
-
-int libxl__qmp_query_cpus(libxl__gc *gc, int domid, libxl_bitmap *map)
-{
-    return qmp_run_command(gc, domid, "query-cpus", NULL,
-                           query_cpus_callback, map);
-}
-
 int libxl__qmp_nbd_server_start(libxl__gc *gc, int domid,
                                 const char *host, const char *port)
 {
-- 
Anthony PERARD


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-08-02 15:57 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02 15:35 [Xen-devel] [PATCH 00/35] libxl refactoring to use ev_qmp (with API changes) Anthony PERARD
2019-08-02 15:35 ` [Xen-devel] [PATCH 01/35] libxl: Make libxl_domain_unpause async Anthony PERARD
2019-09-17 16:50   ` Ian Jackson
2019-09-18 14:05     ` Anthony PERARD
2019-09-18 15:44       ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 02/35] libxl: Make libxl_send_trigger async Anthony PERARD
2019-09-17 16:50   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 03/35] libxl: Make libxl_set_vcpuonline async Anthony PERARD
2019-09-17 16:50   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 04/35] libxl: Make libxl_retrieve_domain_configuration async Anthony PERARD
2019-09-17 16:50   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 05/35] libxl: Make libxl_qemu_monitor_command async Anthony PERARD
2019-09-17 16:50   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 06/35] libxl: Use ev_qmp for switch_qemu_xen_logdirty Anthony PERARD
2019-09-17 16:52   ` Ian Jackson
2019-09-17 16:53     ` Ian Jackson
2019-09-17 17:10     ` Ian Jackson
2019-09-19 12:58     ` Anthony PERARD
2019-09-19 13:03       ` Ian Jackson
2019-09-19 13:21         ` Anthony PERARD
2019-08-02 15:35 ` [Xen-devel] [PATCH 07/35] libxl: Move "qmp_initializations" to libxl_dm Anthony PERARD
2019-09-17 16:54   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 08/35] libxl: Replace libxl__qmp_initializations by ev_qmp calls Anthony PERARD
2019-09-17 17:02   ` Ian Jackson
2019-09-18 14:20     ` Anthony PERARD
2019-09-18 16:49     ` Anthony PERARD
2019-09-18 16:56       ` Ian Jackson
2019-09-18 17:08   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 09/35] libxl: Deprecate libxl__domain_{unpause, resume} Anthony PERARD
2019-09-17 17:02   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 10/35] libxl: Re-introduce libxl__domain_resume Anthony PERARD
2019-09-17 17:04   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 11/35] libxl_domain: Convert libxl_domain_resume to use libxl__domain_resume Anthony PERARD
2019-09-17 17:04   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 12/35] libxl: Re-introduce libxl__domain_unpause Anthony PERARD
2019-09-17 17:05   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 13/35] libxl_dm: Update libxl__spawn_stub_dm to use libxl__domain_unpause Anthony PERARD
2019-09-17 17:05   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 14/35] libxl_domain: Convert libxl_domain_unpause " Anthony PERARD
2019-09-17 17:05   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 15/35] libxl: Inline do_usbdev_add into libxl__device_usbdev_add Anthony PERARD
2019-09-17 17:05   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 16/35] libxl: Inline do_usbdev_remove into libxl__device_usbdev_remove Anthony PERARD
2019-09-17 17:06   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 17/35] libxl: Add libxl__ev_qmp to libxl__ao_device Anthony PERARD
2019-09-17 17:07   ` Ian Jackson
2019-09-19 15:43     ` Anthony PERARD
2019-09-19 16:17       ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 18/35] libxl: Add device_{config, type} " Anthony PERARD
2019-09-17 17:07   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 19/35] libxl_usb: Make libxl__device_usbctrl_add uses ev_qmp Anthony PERARD
2019-09-17 17:08   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 20/35] libxl_usb: Make libxl__initiate_device_usbctrl_remove " Anthony PERARD
2019-09-17 17:10   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 21/35] libxl_usb: Make libxl__device_usbdev_add " Anthony PERARD
2019-09-17 17:10   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 22/35] libxl: Use aodev for libxl__device_usbdev_remove Anthony PERARD
2019-09-17 17:12   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 23/35] libxl: libxl__initiate_device_usbdev_remove now use ev_qmp Anthony PERARD
2019-09-17 17:14   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 24/35] libxl: Remove libxl__qmp_run_command_flexarray Anthony PERARD
2019-09-17 17:14   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 25/35] libxl_pci: Coding style of do_pci_add Anthony PERARD
2019-09-17 17:15   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 26/35] libxl_pci: Only check if qemu-dm is running in qemu-trad case Anthony PERARD
2019-09-17 17:16   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 27/35] libxl_pci: Use libxl__ao_device with libxl__device_pci_add Anthony PERARD
2019-09-17 17:16   ` Ian Jackson
2019-08-02 15:35 ` [Xen-devel] [PATCH 28/35] libxl_pci: Use ev_qmp in do_pci_add Anthony PERARD
2019-09-17 17:19   ` Ian Jackson
2019-09-18 14:23     ` Anthony PERARD
2019-09-18 17:22       ` Anthony PERARD
2019-09-19 11:18   ` Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 29/35] libxl_pci: Use libxl__ao_device with pci_remove Anthony PERARD
2019-09-17 17:20   ` Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 30/35] libxl_pci: Use ev_qmp for pci_remove Anthony PERARD
2019-09-17 17:27   ` Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 31/35] libxl: Use ev_qmp for libxl_send_trigger Anthony PERARD
2019-09-17 17:27   ` Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 32/35] libxl: Use ev_qmp in libxl_set_vcpuonline Anthony PERARD
2019-09-17 17:41   ` Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 33/35] libxl: Extract qmp_parse_query_cpus Anthony PERARD
2019-09-17 17:42   ` Ian Jackson
2019-09-19 14:46     ` Anthony PERARD
2019-09-19 16:17       ` Ian Jackson
2019-08-02 15:36 ` Anthony PERARD [this message]
2019-09-17 17:43   ` [Xen-devel] [PATCH 34/35] libxl: libxl_retrieve_domain_configuration now uses ev_qmp Ian Jackson
2019-08-02 15:36 ` [Xen-devel] [PATCH 35/35] libxl: libxl_qemu_monitor_command " Anthony PERARD
2019-09-17 17:43   ` Ian Jackson
2019-09-17 17:44 ` [Xen-devel] [PATCH 00/35] libxl refactoring to use ev_qmp (with API changes) Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190802153606.32061-35-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.