From 1021df2815ddbf6cfc54c7dab9a55c826196e9f3 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 10 Feb 2015 16:23:16 +0000 Subject: [PATCH] qemu: do upfront check for vcpupids being null when querying pinning The qemuDomainHelperGetVcpus attempted to report an error when the vcpupids info was NULL. Unfortunately earlier code would clamp the value of 'maxinfo' to 0 when nvcpupids was 0, so the error reporting would end up being skipped. This lead to 'virsh vcpuinfo ' just returning an empty list instead of giving the user a clear error. (cherry picked from commit 9358b63a0dfff6bc5a62698ea45d4fb5db91fa47) --- src/qemu/qemu_driver.c | 43 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bc6aae40e5..82f016a77d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1380,6 +1380,12 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, if ((hostcpus = nodeGetCPUCount()) < 0) return -1; + if (priv->vcpupids == NULL) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cpu affinity is not supported")); + return -1; + } + maxcpu = maplen * 8; if (maxcpu > hostcpus) maxcpu = hostcpus; @@ -1395,8 +1401,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, info[i].number = i; info[i].state = VIR_VCPU_RUNNING; - if (priv->vcpupids != NULL && - qemuGetProcessInfo(&(info[i].cpuTime), + if (qemuGetProcessInfo(&(info[i].cpuTime), &(info[i].cpu), NULL, vm->pid, @@ -1410,28 +1415,22 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, if (cpumaps != NULL) { memset(cpumaps, 0, maplen * maxinfo); - if (priv->vcpupids != NULL) { - for (v = 0; v < maxinfo; v++) { - unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); - virBitmapPtr map = NULL; - unsigned char *tmpmap = NULL; - int tmpmapLen = 0; + for (v = 0; v < maxinfo; v++) { + unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); + virBitmapPtr map = NULL; + unsigned char *tmpmap = NULL; + int tmpmapLen = 0; - if (virProcessGetAffinity(priv->vcpupids[v], - &map, maxcpu) < 0) - return -1; - virBitmapToData(map, &tmpmap, &tmpmapLen); - if (tmpmapLen > maplen) - tmpmapLen = maplen; - memcpy(cpumap, tmpmap, tmpmapLen); + if (virProcessGetAffinity(priv->vcpupids[v], + &map, maxcpu) < 0) + return -1; + virBitmapToData(map, &tmpmap, &tmpmapLen); + if (tmpmapLen > maplen) + tmpmapLen = maplen; + memcpy(cpumap, tmpmap, tmpmapLen); - VIR_FREE(tmpmap); - virBitmapFree(map); - } - } else { - virReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cpu affinity is not available")); - return -1; + VIR_FREE(tmpmap); + virBitmapFree(map); } } }