libxl: update available vcpus map in retrieve configuration function
cover libxl: update available vcpus map in retrieve configuration function
Wei Liu (3):
libxl: introduce libxl__json_array_count
libxl: introduce libxl__qmp_query_cpus
libxl: update vcpus bitmap in retrieved guest config
tools/libxl/libxl.c | 91 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 4 ++ tools/libxl/libxl_json.c | 11 ++++++ tools/libxl/libxl_qmp.c | 19 +++++++++ 4 files changed, 125 insertions(+)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 1/3 libxl: introduce libxl__json_array_count
It returns the number of elements in a json array.
It will be used later.
--- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_json.c | 11 +++++++++++ 2 files changed, 12 insertions(+)
tools/libxl/libxl_internal.h +1 -0
@@ -1979,6 +1979,7 @@ _hidden int libxl__json_object_append_to(libxl__gc *gc_opt, libxl__yajl_ctx *ctx); _hidden libxl__json_object *libxl__json_array_get(const libxl__json_object *o,int i); +_hidden unsigned int libxl__json_array_count(const libxl__json_object *o);_hidden libxl__json_map_node *libxl__json_map_node_get(const libxl__json_object *o,int i);
tools/libxl/libxl_json.c +11 -0
@@ -546,6 +546,17 @@ void libxl__json_object_free(libxl__gc *gc, libxl__json_object *obj)free (obj); } +unsigned int libxl__json_array_count (const libxl__json_object *o) +{ +flexarray_t *array =NULL ; + +assert (libxl__json_object_is_array (o)); + array =libxl__json_object_get_array (o); +assert (array); + +return array->count; +} +libxl__json_object *libxl__json_array_get (const libxl__json_object *o,int i) {flexarray_t *array =NULL ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 2/3 libxl: introduce libxl__qmp_query_cpus
In reply to Wei LiuIt interrogates QEMU for the number of cpus.
--- tools/libxl/libxl_internal.h | 3 +++ tools/libxl/libxl_qmp.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+)
tools/libxl/libxl_internal.h +3 -0
@@ -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, +unsigned int *count);/* 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 +19 -0
@@ -979,6 +979,25 @@ 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) +{ +unsigned int *count = opaque; +GC_INIT (qmp->ctx); + + *count =libxl__json_array_count (response); + +GC_FREE ; +return 0 ; +} + +int libxl__qmp_query_cpus (libxl__gc *gc,int domid,unsigned int *count) +{ +return qmp_run_command (gc, domid,"query-cpus" ,NULL , + query_cpus_callback, count); +} +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
PATCH 3/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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)
tools/libxl/libxl.c +91 -0
@@ -7222,6 +7222,57 @@ 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) +{ +unsigned int count, i; +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, &count); +if (rc) { +LOG (ERROR ,"fail to get number of cpus for domain %d" , domid); + goto out; + } + +for (i =0 ; i < count; i++) +libxl_bitmap_set (map, i); + + 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 +7321,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
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 29 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.
Reported-by Jan Beulich <[email protected]>Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)tools/libxl/libxl.c +9
-0@@ -7222,6 +7222,57 @@ 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) +{ +unsigned int count, i; +int rc; + +/* For QEMU upstream we always need to return the number +* of cpus present to QEMU whether they are online or not;
tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7243
Quoted 10 lines
tools/libxl/libxl.c +10
-0+* otherwise QEMU won't accept the saved state. +*/ + rc =libxl__qmp_query_cpus (gc, domid, &count); +if (rc) { +LOG (ERROR ,"fail to get number of cpus for domain %d" , domid); + goto out; + } + +for (i =0 ; i < count; i++) +libxl_bitmap_set (map, i);
What if I have cpu 1, 7 and 42 online, but all the other offline?
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 34 lines · Anthony PERARD
Quoted 33 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.
Reported-by Jan Beulich <[email protected]>Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)tools/libxl/libxl.c +13
-0@@ -7222,6 +7222,57 @@ 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) +{ +unsigned int count, i; +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, &count); +if (rc) {
Quoted 9 lines
tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7243
Quoted 6 lines
tools/libxl/libxl.c +6
-0+LOG (ERROR ,"fail to get number of cpus for domain %d" , domid); + goto out; + } + +for (i =0 ; i < count; i++) +libxl_bitmap_set (map, i);What if I have cpu 1, 7 and 42 online, but all the other offline?
I have more or less the same question when I wrote this patch. At that time I thought the avail_vcpus was only used for generating -smp option to QEMU.
In your example, you will have -smp 3,maxvcpus=$Y. I think the migration should still succeed. Furthermore, the cpu-add operation doesn't care, so it probably won't have visible effect.
I agree it would be good to set the exact bits though -- if you can tell me which field to test.
-> { "execute": "query-cpus" }
<- {
"return":[
{
"CPU":0,
"current":true,
"halted":false,
"qom_path":"/machine/unattached/device[0]",
"arch":"x86",
"pc":3227107138,
"thread_id":3134
},
{
"CPU":1,
"current":false,
"halted":true,
"qom_path":"/machine/unattached/device[2]",
"arch":"x86",
"pc":7108165,
"thread_id":3135
}
] }
EQMP
Wei.
Quoted 2 lines
Signature · 1 line
Anthony PERARD
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 44 lines · Wei Liu
Quoted 22 lines · Anthony PERARD
Quoted 21 lines
tools/libxl/libxl.c +0
-0@@ -7222,6 +7222,57 @@ 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_tdomid,
+ unsigned intmax_vcpus, + libxl_bitmap *map)tools/libxl/libxl.c +10
-0+{ + unsigned int count, i; + 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, &count); + if (rc) {Quoted 9 lines
Quoted 7 lines
+ LOG(ERROR, "fail to get number of cpus for domain %d", domid);
+ goto out;
+ }
+
+ for (i = 0; i < count; i++)
+ libxl_bitmap_set(map, i);What if I have cpu 1, 7 and 42 online, but all the other offline?
I have more or less the same question when I wrote this patch. At that
time I thought theavail_vcpuswas only used for generating -smp option
to QEMU.In your example, you will have -smp 3,maxvcpus=$Y. I think the migration
should still succeed. Furthermore, the cpu-add operation doesn't care,
so it probably won't have visible effect.
Quoted 4 lines
I agree it would be good to set the exact bits though -- if you can tell
me which field to test.
Perhaps at least mention something about all this either in a comment or in the changelog?
Regards,
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
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 45 lines · Dario Faggioli
Quoted 44 lines · Wei Liu
Quoted 22 lines · Anthony PERARD
Quoted 21 lines
tools/libxl/libxl.c +0
-0@@ -7222,6 +7222,57 @@ 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_tdomid,
+ unsigned intmax_vcpus, + libxl_bitmap *map)tools/libxl/libxl.c +10
-0+{ + unsigned int count, i; + 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, &count); + if (rc) {Quoted 9 lines
Quoted 7 lines
+ LOG(ERROR, "fail to get number of cpus for domain %d", domid);
+ goto out;
+ }
+
+ for (i = 0; i < count; i++)
+ libxl_bitmap_set(map, i);What if I have cpu 1, 7 and 42 online, but all the other offline?
I have more or less the same question when I wrote this patch. At that
time I thought theavail_vcpuswas only used for generating -smp option
to QEMU.In your example, you will have -smp 3,maxvcpus=$Y. I think the migration
should still succeed. Furthermore, the cpu-add operation doesn't care,
so it probably won't have visible effect.
Quoted 7 lines
Quoted 4 lines
I agree it would be good to set the exact bits though -- if you can tell
me which field to test.Perhaps at least mention something about all this either in a comment or in the changelog?
What would you like to see in a comment? I guess this is now moot because the exact bits will be set.
Wei.
Quoted 8 lines
Regards,
DarioSignature · 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
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 5 lines · Wei Liu
Quoted 5 lines
Quoted 5 lines
I agree it would be good to set the exact bits though -- if you can
tell
me which field to test.
Quoted 7 lines
Quoted 4 lines
Perhaps at least mention something about all this either in a comment
or in the changelog?What would you like to see in a comment? I guess this is now moot because the exact bits will be set.
Well, if the code ends up looking like:
"the most correct thing would be to set the proper bits, but it's hard/cumbersome/unknown how to do so, and setting all up until count it enough for making things work"
Then, exactly that. :-)
If the code does the most correct thing already, as you seem to say, then nothing.
Regards,
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
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
In reply to Wei LiuQuoted 45 lines · Wei Liu
Quoted 34 lines · Anthony PERARD
Quoted 33 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.
Reported-by Jan Beulich <[email protected]>Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)tools/libxl/libxl.c +13
-0@@ -7222,6 +7222,57 @@ 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) +{ +unsigned int count, i; +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, &count); +if (rc) {Quoted 9 lines
tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7243
Quoted 6 lines
tools/libxl/libxl.c +6
-0+LOG (ERROR ,"fail to get number of cpus for domain %d" , domid); + goto out; + } + +for (i =0 ; i < count; i++) +libxl_bitmap_set (map, i);What if I have cpu 1, 7 and 42 online, but all the other offline?
Quoted 3 lines
I have more or less the same question when I wrote this patch. At that time I thought the
avail_vcpuswas only used for generating -smp option to QEMU.
Right, and -smp does not let you set a bitmap... I guess having a count for this purpose is enough.
Quoted 3 lines
In your example, you will have -smp 3,maxvcpus=$Y. I think the migration should still succeed. Furthermore, the cpu-add operation doesn't care, so it probably won't have visible effect.
What does cpu-add not care about?
Quoted 3 lines
I agree it would be good to set the exact bits though -- if you can tell me which field to test.
From the example below, I guess it would be "CPU".
Quoted 25 lines
-> { "execute": "query-cpus" }
<- { "return":[ { "CPU":0, "current":true, "halted":false, "qom_path":"/machine/unattached/device[0]", "arch":"x86", "pc":3227107138, "thread_id":3134 }, { "CPU":1, "current":false, "halted":true, "qom_path":"/machine/unattached/device[2]", "arch":"x86", "pc":7108165, "thread_id":3135 } ]}
EQMP
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 50 lines · Anthony PERARD
Quoted 45 lines · Wei Liu
Quoted 34 lines · Anthony PERARD
Quoted 33 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.
Reported-by Jan Beulich <[email protected]>Signed-off-by Wei Liu <[email protected]>--- tools/libxl/libxl.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+)tools/libxl/libxl.c +13
-0@@ -7222,6 +7222,57 @@ 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) +{ +unsigned int count, i; +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, &count); +if (rc) {Quoted 9 lines
tools/libxl/libxl.c void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src) · line 7243
Quoted 6 lines
tools/libxl/libxl.c +6
-0+LOG (ERROR ,"fail to get number of cpus for domain %d" , domid); + goto out; + } + +for (i =0 ; i < count; i++) +libxl_bitmap_set (map, i);What if I have cpu 1, 7 and 42 online, but all the other offline?
Quoted 3 lines
I have more or less the same question when I wrote this patch. At that time I thought the
avail_vcpuswas only used for generating -smp option to QEMU.
Quoted 9 lines
Right, and -smp does not let you set a bitmap... I guess having a count for this purpose is enough.
Quoted 3 lines
In your example, you will have -smp 3,maxvcpus=$Y. I think the migration should still succeed. Furthermore, the cpu-add operation doesn't care, so it probably won't have visible effect.
What does cpu-add not care about?
Never mind. This is too wrong to explain. I was thinking about some other stuff when writing that.
The libxl API does care about the bitmap, but QEMU parameter doesn't.
Quoted 5 lines
Quoted 3 lines
I agree it would be good to set the exact bits though -- if you can tell me which field to test.
From the example below, I guess it would be "CPU".
Sounds good to me.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
In reply to Wei LiuWei Liu writes ("[PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config"):
Quoted 2 lines
... because the available vcpu bitmap can change during domain life time due to cpu hotplug and unplug.
Is this cpu hotplug something that the guest can cause, or are we just talking about toolstack changes ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config
Quoted 7 lines · Ian Jackson
Wei Liu writes ("[PATCH 3/3] libxl: update vcpus bitmap in retrieved guest config"):
Quoted 2 lines
... because the available vcpu bitmap can change during domain life time due to cpu hotplug and unplug.
Is this cpu hotplug something that the guest can cause, or are we just talking about toolstack changes ?
We're only talking about toolstack side here.
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel