Skip to contentSkip to conversation

libxl: libxl: update available vcpus map in retrieve configuration function

PATCH Superseded Wei Liu 5 participants 18 messages Jun 8, 2016 – Jun 14, 2016

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

v2 cover libxl: libxl: update available vcpus map in retrieve configuration function

Patch 3 is not really related to the bug, but something we can fix when after having first patch.

Wei Liu (3):
libxl: introduce libxl__qmp_query_cpus
libxl: update vcpus bitmap in retrieved guest config
libxl: only issue cpu-add call to QEMU for not present CPU

 tools/libxl/libxl.c          | 126 +++++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl_internal.h |   3 ++
 tools/libxl/libxl_qmp.c      |  37 +++++++++++++
 3 files changed, 156 insertions(+), 10 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#1 lore raw

PATCH v2 1/3 libxl: introduce libxl__qmp_query_cpus

It interrogates QEMU for CPUs and update the bitmap accordingly.

---
 tools/libxl/libxl_internal.h |  3 +++
 tools/libxl/libxl_qmp.c      | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
tools/libxl/libxl_internal.h +3 -0
index ae16c25..e9a3cf0 100644
@@ -1794,6 +1794,9 @@ _hidden int libxl__qmp_set_global_dirty_log(libxl__gc *gc, int domid, bool enabl
 _hidden int libxl__qmp_insert_cdrom(libxl__gc *gc, int domid, const libxl_device_disk *disk);
 /* Add a virtual CPU */
 _hidden int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int index);
+/* Query the number 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);
tools/libxl/libxl_qmp.c +37 -0
index 3eb279a..23eac92 100644
@@ -979,6 +979,43 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int 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)
+{
+    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) {
+            LOG(ERROR, "Failed to retreive CPU index.");
+            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)
 {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] libxl: introduce libxl__qmp_query_cpus

Quoted 4 lines · Wei Liu

It interrogates QEMU for CPUs and update the bitmap accordingly.

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v2 1/3] libxl: introduce libxl__qmp_query_cpus

In reply to Wei Liu
Quoted 16 lines · Wei Liu
tools/libxl/libxl_qmp.c +8 -0
index 3eb279a..23eac92 100644
@@ -979,6 +979,43 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int 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)
+{
+    libxl_bitmap *map = opaque;
+    unsigned int i;
+    const libxl__json_object *cpu = NULL;
+    int rc;

tools/libxl/libxl_qmp.c int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) · line 999

Quoted 10 lines
tools/libxl/libxl_qmp.c +10 -0
+    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) {
+            LOG(ERROR, "Failed to retreive CPU index.");

rc is still uninitialised at this point.

Also, s/retreive/retrieve/.

Quoted 12 lines
tools/libxl/libxl_qmp.c +12 -0
+            goto out;
+        }
+
+        idx = libxl__json_object_get_integer(o);
+        libxl_bitmap_set(map, idx);
+    }
+
+    rc = 0;
+out:
+    GC_FREE;
+    return rc;
+}
Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#4 lore raw

Re: [PATCH v2 1/3] libxl: introduce libxl__qmp_query_cpus

Quoted 30 lines · Anthony PERARD
Quoted 16 lines · Wei Liu
tools/libxl/libxl_qmp.c +8 -0
index 3eb279a..23eac92 100644
@@ -979,6 +979,43 @@ int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int 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)
+{
+    libxl_bitmap *map = opaque;
+    unsigned int i;
+    const libxl__json_object *cpu = NULL;
+    int rc;

tools/libxl/libxl_qmp.c int libxl__qmp_cpu_add(libxl__gc *gc, int domid, int idx) · line 999

Quoted 10 lines
tools/libxl/libxl_qmp.c +10 -0
+    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) {
+            LOG(ERROR, "Failed to retreive CPU index.");

rc is still uninitialised at this point.

Quoted 2 lines

Also, s/retreive/retrieve/.

Good catch. I will fix both issues.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#5 lore raw

PATCH v2 2/3 libxl: update vcpus bitmap in retrieved guest config

In reply to Wei Liu

... 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.

---
 tools/libxl/libxl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
tools/libxl/libxl.c +87 -0
index 006b83f..02706ab 100644
@@ -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:
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 2/3
#6 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

Quoted 10 lines · Wei Liu

... 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.

Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

In reply to Wei Liu
Quoted 5 lines · Wei Liu

... 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.

I tried to migrate a guest, and libxl abort in libxl_retrieve_domain_configuration within the switch (device_model_version).

Quoted 21 lines
---
 tools/libxl/libxl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
tools/libxl/libxl.c +7 -0
index 006b83f..02706ab 100644
@@ -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

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7241

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+     * 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;

The value should already be 0 at this point.

Quoted 12 lines
tools/libxl/libxl.c +12 -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;
+

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7263

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+    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")))

I don't think strncmp is usefull here as one of the argument is a plain string. One could just use strcmp?

Quoted 29 lines
tools/libxl/libxl.c +22 -0
+            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:

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+                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();

Missing indentation for abort.

Also, that is where xl abort on migration.

Quoted 19 lines
tools/libxl/libxl.c +16 -0
+            }
+            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:
Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#8 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

Quoted 37 lines · Anthony PERARD
Quoted 5 lines · Wei Liu

... 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.

I tried to migrate a guest, and libxl abort in libxl_retrieve_domain_configuration within the switch (device_model_version).

Quoted 25 lines
---
 tools/libxl/libxl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
tools/libxl/libxl.c +11 -0
index 006b83f..02706ab 100644
@@ -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);
Quoted 9 lines

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7241

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (rc) {
+        LOG(ERROR, "fail to get number of cpus for domain %d", domid);
+        goto out;
+    }
+
+    rc = 0;

The value should already be 0 at this point.

I would like to keep this as-is because this is an idiom that is safer against further modification of this function.

Quoted 17 lines
Quoted 17 lines
tools/libxl/libxl.c +17 -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;
+    }
Quoted 9 lines

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7263

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+
+    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")))

I don't think strncmp is usefull here as one of the argument is a plain string. One could just use strcmp?

Fine by me of course.

Quoted 33 lines
Quoted 33 lines
tools/libxl/libxl.c +26 -0
+            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:
Quoted 9 lines

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                rc = libxl__update_avail_vcpus_xenstore(gc, domid,
+                                                        max_vcpus, map);
+                break;
+            default:
+            abort();

Missing indentation for abort.

Will fix.

Quoted 2 lines

Also, that is where xl abort on migration.

Hmm... This means the device model version is not valid (unknown?).

Can you paste in your guest config?

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

Quoted 123 lines · Wei Liu
Quoted 37 lines · Anthony PERARD
Quoted 5 lines · Wei Liu

... 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.

I tried to migrate a guest, and libxl abort in libxl_retrieve_domain_configuration within the switch (device_model_version).

Quoted 25 lines
---
 tools/libxl/libxl.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
tools/libxl/libxl.c +11 -0
index 006b83f..02706ab 100644
@@ -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);
Quoted 9 lines

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7241

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+    if (rc) {
+        LOG(ERROR, "fail to get number of cpus for domain %d", domid);
+        goto out;
+    }
+
+    rc = 0;

The value should already be 0 at this point.

I would like to keep this as-is because this is an idiom that is safer against further modification of this function.

Quoted 17 lines
Quoted 17 lines
tools/libxl/libxl.c +17 -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;
+    }
Quoted 9 lines

tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7263

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+
+    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")))

I don't think strncmp is usefull here as one of the argument is a plain string. One could just use strcmp?

Fine by me of course.

Quoted 33 lines
Quoted 33 lines
tools/libxl/libxl.c +26 -0
+            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:
Quoted 9 lines

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                rc = libxl__update_avail_vcpus_xenstore(gc, domid,
+                                                        max_vcpus, map);
+                break;
+            default:
+            abort();

Missing indentation for abort.

Quoted 8 lines

Will fix.

Quoted 2 lines

Also, that is where xl abort on migration.

Hmm... This means the device model version is not valid (unknown?).

Can you paste in your guest config?

With all commented line removed:

builder = 'hvm'
memory = 500
vcpus = 2
maxvcpus = 6
name = "arch"
vif = [ 'type=ioemu,mac=00:16:3e:XX:XX:XX' ]
disk = [
'phy:/dev/vg42/guest_arch64,hda,w',
'file:/root/vm/iso/archlinux-2014.04.01-dual.iso,hdc:cdrom,r',
]
device_model_args_hvm = [
]
usbdevice='tablet'
boot="cd"
serial='pty'
sdl = 0
vnc = 1
vnclisten = '0.0.0.0'
vncunused = 1
spice=0
uuid = "XXXX"

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#10 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

On Tue, Jun 14, 2016 at 11:47:57AM +0100, Anthony PERARD wrote:
[...]

Quoted 60 lines
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
tools/libxl/libxl.c +19 -0
+
 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:
Quoted 9 lines

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                rc = libxl__update_avail_vcpus_xenstore(gc, domid,
+                                                        max_vcpus, map);
+                break;
+            default:
+            abort();

Missing indentation for abort.

Quoted 8 lines

Will fix.

Quoted 2 lines

Also, that is where xl abort on migration.

Hmm... This means the device model version is not valid (unknown?).

Can you paste in your guest config?

With all commented line removed:

builder = 'hvm'
memory = 500
vcpus = 2
maxvcpus = 6
name = "arch"
vif = [ 'type=ioemu,mac=00:16:3e:XX:XX:XX' ]
disk = [
'phy:/dev/vg42/guest_arch64,hda,w',
'file:/root/vm/iso/archlinux-2014.04.01-dual.iso,hdc:cdrom,r',
]
device_model_args_hvm = [
]
usbdevice='tablet'

Quoted 9 lines

boot="cd"
serial='pty'
sdl = 0
vnc = 1
vnclisten = '0.0.0.0'
vncunused = 1
spice=0
uuid = "XXXX"

This means your device model version is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN so it should be covered by the correct case.

I'm confused.

Wei.

Quoted 3 lines
Signature · 2 lines
-- 
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

Quoted 72 lines · Wei Liu

On Tue, Jun 14, 2016 at 11:47:57AM +0100, Anthony PERARD wrote:
[...]

Quoted 60 lines
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
tools/libxl/libxl.c +19 -0
+
 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:
Quoted 9 lines

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                rc = libxl__update_avail_vcpus_xenstore(gc, domid,
+                                                        max_vcpus, map);
+                break;
+            default:
+            abort();

Missing indentation for abort.

Quoted 8 lines

Will fix.

Quoted 2 lines

Also, that is where xl abort on migration.

Hmm... This means the device model version is not valid (unknown?).

Can you paste in your guest config?

With all commented line removed:

builder = 'hvm'
memory = 500
vcpus = 2
maxvcpus = 6
name = "arch"
vif = [ 'type=ioemu,mac=00:16:3e:XX:XX:XX' ]
disk = [
'phy:/dev/vg42/guest_arch64,hda,w',
'file:/root/vm/iso/archlinux-2014.04.01-dual.iso,hdc:cdrom,r',
]
device_model_args_hvm = [
]
usbdevice='tablet'

Quoted 9 lines

boot="cd"
serial='pty'
sdl = 0
vnc = 1
vnclisten = '0.0.0.0'
vncunused = 1
spice=0
uuid = "XXXX"

Quoted 4 lines

This means your device model version is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN so it should be covered by the correct case.

I'm confused.

If it works for you, I'll properly install Xen with your patch in, I may miss something...
I did:
LD_LIBRARY_PATH=pwd ./xl -vvv migrate arch localhost

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#12 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

On Tue, Jun 14, 2016 at 11:58:58AM +0100, Anthony PERARD wrote:
[...]

Quoted 8 lines
Quoted 5 lines

This means your device model version is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN so it should be covered by the correct case.

I'm confused.

If it works for you, I'll properly install Xen with your patch in, I may miss something...

Yes, it did work for me.

Quoted 3 lines

I did:
LD_LIBRARY_PATH=pwd ./xl -vvv migrate arch localhost

Never tried this so I'm not sure what might go wrong...

Wei.

Quoted 2 lines
Signature · 1 line
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

Wei Liu writes ("Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config"):

Quoted 5 lines · Anthony PERARD
Quoted 2 lines

I did:
LD_LIBRARY_PATH=pwd ./xl -vvv migrate arch localhost

Never tried this so I'm not sure what might go wrong...

That is how I do most of my ad-hoc testing.

If you have a newer xenstore etc. too you may need something like
LD_LIBRARY_PATH=../xenstore:.

I find that relative paths work well with xl (because libxl is not entitled to chdir, and xl doesn't).

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v2 2/3] libxl: update vcpus bitmap in retrieved guest config

In reply to Anthony PERARD
Quoted 76 lines · Anthony PERARD
Quoted 75 lines · Wei Liu

On Tue, Jun 14, 2016 at 11:47:57AM +0100, Anthony PERARD wrote:
[...]

Quoted 60 lines
Quoted 36 lines
Quoted 26 lines
Quoted 26 lines
tools/libxl/libxl.c +19 -0
+
 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:
Quoted 9 lines

tools/libxl/libxl.c int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, · line 7343

Quoted 6 lines
tools/libxl/libxl.c +6 -0
+            case LIBXL_DEVICE_MODEL_VERSION_NONE:
+                rc = libxl__update_avail_vcpus_xenstore(gc, domid,
+                                                        max_vcpus, map);
+                break;
+            default:
+            abort();

Missing indentation for abort.

Quoted 8 lines

Will fix.

Quoted 2 lines

Also, that is where xl abort on migration.

Hmm... This means the device model version is not valid (unknown?).

Can you paste in your guest config?

With all commented line removed:

builder = 'hvm'
memory = 500
vcpus = 2
maxvcpus = 6
name = "arch"
vif = [ 'type=ioemu,mac=00:16:3e:XX:XX:XX' ]
disk = [
'phy:/dev/vg42/guest_arch64,hda,w',
'file:/root/vm/iso/archlinux-2014.04.01-dual.iso,hdc:cdrom,r',
]
device_model_args_hvm = [
]
usbdevice='tablet'

Quoted 9 lines

boot="cd"
serial='pty'
sdl = 0
vnc = 1
vnclisten = '0.0.0.0'
vncunused = 1
spice=0
uuid = "XXXX"

This means your device model version is LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN so it should be covered by the correct case.

Quoted 6 lines
Quoted 1 line

I'm confused.

If it works for you, I'll properly install Xen with your patch in, I may miss something...
I did:
LD_LIBRARY_PATH=pwd ./xl -vvv migrate arch localhost

I tried again, this time Xen properly installed with your patch series.

sh$ xl create arch.hvm
sh$ xl list
Name ID Mem VCPUs State Time(s)

Domain-0                                     0  4000     8     r-----      25.3
arch                                         1   500     2     -b----       5.4
sh$ xl vcpu-set arch 5
sh$ xl list
Name                                        ID   Mem VCPUs	State	Time(s)
Domain-0                                     0  4000     8     r-----      25.8
arch                                         1   500     5     -b----       6.4

# All fine up to here.

sh$ xl migrate arch localhost
Aborted (core dumped)
sh$ xl save arch savefile
Aborted (core dumped)
sh$ xl save arch savefile ~/arch.hvm
Saving to savefile new xl format (info 0x3/0x0/1540)
xc: info: Saving domain 1, type x86 HVM
xc: Frames: 1044482/1044482 100%
xc: End of stream: 0/0 0%

# So there is only one way to migrate or save the guest.

sh$ xl restore savefile
[...]
libxl: error: libxl_dm.c:2187:device_model_spawn_outcome: domain 2 device model: spawn failed (rc=-3) [...]

# So restore still fail with this in QEMU log:
qemu-system-i386: Unknown savevm section or instance 'cpu_common' 2
qemu-system-i386: load of migration failed: Invalid argument

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#15 lore raw

PATCH v2 3/3 libxl: only issue cpu-add call to QEMU for not present CPU

In reply to Wei Liu

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.

---
 tools/libxl/libxl.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
tools/libxl/libxl.c +29 -10
index 02706ab..62a7ade 100644
@@ -5740,19 +5740,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(&current_map);
+    libxl_bitmap_init(&final_map);
+
+    libxl_bitmap_alloc(CTX, &current_map, info->vcpu_max_id + 1);
+    libxl_bitmap_set_none(&current_map);
+    rc = libxl__qmp_query_cpus(gc, domid, &current_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(&current_map);
+    libxl_bitmap_dispose(&final_map);
+    return rc;
 }
 
 int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#16 lore raw

Re: [PATCH v2 3/3] libxl: only issue cpu-add call to QEMU for not present CPU

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 08.06.16 at 16:28, <[email protected]> wrote:

Calculate the final bitmap for CPUs to add to avoid having annoying error messages complaining those CPUs are already present.

Ah, nice - I had noticed these odd errors too, but didn't dare to complain about such a cosmetic issue at the same time.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 3/3
#17 lore raw

Re: [PATCH v2 3/3] libxl: only issue cpu-add call to QEMU for not present CPU

In reply to Wei Liu
Quoted 6 lines · Wei Liu

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.

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel