Commit <
2020c6af8a8e4bb04acb629d089142be984484c8> fixed an issue with
QEMU driver by reporting offline CPUs as well. However, doing so it
introduced a regression into libxl and test drivers by completely
ignoring the passed `hostcpus` variable.
Move the virHostCPUGetAvailableCPUsBitmap() out of the helper into QEMU
driver so it will not affect other drivers which gets the number of host
CPUs differently.
This was uncovered by running libvirt-dbus test suite which counts on
the fact that test driver has hard-coded host definition and must not
depend on the host at all.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* @maplen: length of one cpumap passed from caller (@cpumaps)
* @ncpumaps: count of cpumaps of @maplen length in @cpumaps
* @cpumaps: array of pinning information bitmaps to be filled
- * @hostcpus: number of cpus in the host
+ * @hostcpus: default CPU pinning bitmap based on host CPUs
* @autoCpuset: Cpu pinning bitmap used in case of automatic cpu pinning
*
* Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo API.
* In case when automatic cpu pinning is supported, the bitmap should be passed
- * as @autoCpuset. If @hostcpus is < 0 no error is reported (to pass through
- * error message).
+ * as @autoCpuset.
*
- * Returns number of filled entries or -1 on error.
+ * Returns number of filled entries.
*/
int
virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
int maplen,
int ncpumaps,
unsigned char *cpumaps,
- int hostcpus,
+ virBitmapPtr hostcpus,
virBitmapPtr autoCpuset)
{
int maxvcpus = virDomainDefGetVcpusMax(def);
size_t i;
- g_autoptr(virBitmap) allcpumap = NULL;
-
- if (hostcpus < 0)
- return -1;
-
- if (!(allcpumap = virHostCPUGetAvailableCPUsBitmap()))
- return -1;
for (i = 0; i < maxvcpus && i < ncpumaps; i++) {
virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
else if (def->cpumask)
bitmap = def->cpumask;
else
- bitmap = allcpumap;
+ bitmap = hostcpus;
virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
}
int maplen,
int ncpumaps,
unsigned char *cpumaps,
- int hostcpus,
+ virBitmapPtr hostcpus,
virBitmapPtr autoCpuset)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) G_GNUC_WARN_UNUSED_RESULT;
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) G_GNUC_WARN_UNUSED_RESULT;
bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL;
virDomainDefPtr targetDef = NULL;
+ g_autoptr(virBitmap) hostcpus = NULL;
int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
/* Make sure coverity knows targetDef is valid at this point. */
sa_assert(targetDef);
+ if (!(hostcpus = virBitmapNew(libxl_get_max_cpus(cfg->ctx))))
+ goto cleanup;
+ virBitmapSetAll(hostcpus);
+
ret = virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, cpumaps,
- libxl_get_max_cpus(cfg->ctx), NULL);
+ hostcpus, NULL);
cleanup:
virDomainObjEndAPI(&vm);
virDomainDefPtr def;
bool live;
int ret = -1;
+ g_autoptr(virBitmap) hostcpus = NULL;
virBitmapPtr autoCpuset = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
goto cleanup;
+ if (!(hostcpus = virHostCPUGetAvailableCPUsBitmap()))
+ goto cleanup;
+
if (live)
autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset;
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
- virHostCPUGetCount(), autoCpuset);
+ hostcpus, autoCpuset);
cleanup:
virDomainObjEndAPI(&vm);
return ret;
testDriverPtr driver = dom->conn->privateData;
virDomainObjPtr privdom;
virDomainDefPtr def;
+ g_autoptr(virBitmap) hostcpus = NULL;
int ret = -1;
if (!(privdom = testDomObjFromDomain(dom)))
if (!(def = virDomainObjGetOneDef(privdom, flags)))
goto cleanup;
+ if (!(hostcpus = virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo))))
+ goto cleanup;
+ virBitmapSetAll(hostcpus);
+
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
- VIR_NODEINFO_MAXCPUS(driver->nodeInfo),
- NULL);
+ hostcpus, NULL);
cleanup:
virDomainObjEndAPI(&privdom);