[libvirt] [PATCH v2] libxl: libxl_get_max_cpus returning a libxl error from 4.4 onward

Starting from commit 2e82c18c in Xen (will be included in Xen 4.4) both libxl_get_max_cpus() and libxl_get_max_ndoes() start returning a proper libxl error code, in case of failure. This patch fixes this in the libxl driver. Note that, although it is now basically impossible for them to return 0, that would, theoretically, still be wrong. Also, checking that the returned value is '<= 0' makes the code correct for both Xen 4.4 and Xen 4.3 (and 4.2), and that is why we go for it (rather than just '< 0'). Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Cc: Jim Fehlig <jfehlig@suse.com> Cc: Ian Jackson <Ian.Jackson@eu.citrix.com> Cc: Martin Kletzander <mkletzan@redhat.com> --- Changes from v1: * taking care of libxl_get_max_nodes() too --- src/libxl/libxl_driver.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 692c3b7..29aa6c7 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1101,9 +1101,11 @@ libxlConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED) cfg = libxlDriverConfigGet(driver); ret = libxl_get_max_cpus(cfg->ctx); - /* libxl_get_max_cpus() will return 0 if there were any failures, - e.g. xc_physinfo() failing */ - if (ret == 0) + /* On failure, libxl_get_max_cpus() will return ERROR_FAIL from Xen 4.4 + * onward, but it ever returning 0 is obviously wrong too (and it is + * what happens, on failure, on Xen 4.3 and earlier). Therefore, a 'less + * or equal' is the catchall we want. */ + if (ret <= 0) ret = -1; virObjectUnref(cfg); @@ -3980,6 +3982,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom, for (i = 0; i < LIBXL_NUMA_NPARAM && i < *nparams; i++) { virMemoryParameterPtr param = ¶ms[i]; + int numnodes; switch (i) { case 0: @@ -3998,8 +4001,12 @@ libxlDomainGetNumaParameters(virDomainPtr dom, /* Node affinity */ /* Let's allocate both libxl and libvirt bitmaps */ + numnodes = libxl_get_max_nodes(priv->ctx); + if (numnodes <= 0) + goto cleanup; + if (libxl_node_bitmap_alloc(priv->ctx, &nodemap, 0) || - !(nodes = virBitmapNew(libxl_get_max_nodes(priv->ctx)))) { + !(nodes = virBitmapNew(numnodes))) { virReportOOMError(); goto cleanup; }

On Wed, Dec 18, 2013 at 03:39:12PM +0100, Dario Faggioli wrote:
Starting from commit 2e82c18c in Xen (will be included in Xen 4.4) both libxl_get_max_cpus() and libxl_get_max_ndoes() start returning
s/ndoes/nodes/
a proper libxl error code, in case of failure. This patch fixes this in the libxl driver.
Note that, although it is now basically impossible for them to return 0, that would, theoretically, still be wrong. Also, checking that the returned value is '<= 0' makes the code correct for both Xen 4.4 and Xen 4.3 (and 4.2), and that is why we go for it (rather than just '< 0').
Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Cc: Jim Fehlig <jfehlig@suse.com> Cc: Ian Jackson <Ian.Jackson@eu.citrix.com> Cc: Martin Kletzander <mkletzan@redhat.com> --- Changes from v1: * taking care of libxl_get_max_nodes() too --- src/libxl/libxl_driver.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
ACK, fixed & pushed. Thanks, Martin

On mer, 2013-12-18 at 17:40 +0100, Martin Kletzander wrote:
On Wed, Dec 18, 2013 at 03:39:12PM +0100, Dario Faggioli wrote:
Starting from commit 2e82c18c in Xen (will be included in Xen 4.4) both libxl_get_max_cpus() and libxl_get_max_ndoes() start returning
s/ndoes/nodes/
Ouch! :-(
--- Changes from v1: * taking care of libxl_get_max_nodes() too --- src/libxl/libxl_driver.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
ACK, fixed & pushed.
Cool. Thanks, Dario -- <<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)
participants (2)
-
Dario Faggioli
-
Martin Kletzander