[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v4 3/5] libxl: introduce libxl__qmp_query_cpus
It interrogates QEMU for CPUs and update the bitmap accordingly. Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> Reviewed-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx> Reviewed-by: Anthony PERARD <anthony.perard@xxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx> v3: 1. Initialise rc in error path. 2. Fix comment in header and a typo in log message. --- tools/libxl/libxl_internal.h | 3 +++ tools/libxl/libxl_qmp.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index de77579..e33c710 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 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 3eb279a..63c49c5 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -979,6 +979,44 @@ 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 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) { -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |