diff mbox

[v2,1/3] libxl: introduce libxl__qmp_query_cpus

Message ID 1465396126-27426-2-git-send-email-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu June 8, 2016, 2:28 p.m. UTC
It interrogates QEMU for CPUs and update the bitmap accordingly.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 tools/libxl/libxl_internal.h |  3 +++
 tools/libxl/libxl_qmp.c      | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

Comments

Dario Faggioli June 9, 2016, 12:12 a.m. UTC | #1
On Wed, 2016-06-08 at 15:28 +0100, Wei Liu wrote:
> It interrogates QEMU for CPUs and update the bitmap accordingly.
> 
> Signed-off-by: Wei Liu <wei.liu2@citrix.com>
>
Reviewed-by: Dario Faggioli <dario.faggioli@citrix.com>

Dario
Anthony PERARD June 13, 2016, 4:52 p.m. UTC | #2
On Wed, Jun 08, 2016 at 03:28:44PM +0100, Wei Liu wrote:
> diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> index 3eb279a..23eac92 100644
> --- a/tools/libxl/libxl_qmp.c
> +++ b/tools/libxl/libxl_qmp.c
> @@ -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.");

rc is still uninitialised at this point.

Also, s/retreive/retrieve/.

> +            goto out;
> +        }
> +
> +        idx = libxl__json_object_get_integer(o);
> +        libxl_bitmap_set(map, idx);
> +    }
> +
> +    rc = 0;
> +out:
> +    GC_FREE;
> +    return rc;
> +}
Wei Liu June 13, 2016, 6:17 p.m. UTC | #3
On Mon, Jun 13, 2016 at 05:52:14PM +0100, Anthony PERARD wrote:
> On Wed, Jun 08, 2016 at 03:28:44PM +0100, Wei Liu wrote:
> > diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
> > index 3eb279a..23eac92 100644
> > --- a/tools/libxl/libxl_qmp.c
> > +++ b/tools/libxl/libxl_qmp.c
> > @@ -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.");
> 
> rc is still uninitialised at this point.
> 
> Also, s/retreive/retrieve/.
> 

Good catch. I will fix both issues.

Wei.
diff mbox

Patch

diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index ae16c25..e9a3cf0 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -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);
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 3eb279a..23eac92 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -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)
 {