conf: fix detection of available host CPUs for vcpupin

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>
This commit is contained in:
Pavel Hrdina 2020-08-07 15:48:27 +02:00
parent 4b696beee3
commit bd53831e67
5 changed files with 24 additions and 19 deletions

View File

@ -2090,33 +2090,25 @@ virDomainDefHasVcpuPin(const virDomainDef *def)
* @maplen: length of one cpumap passed from caller (@cpumaps) * @maplen: length of one cpumap passed from caller (@cpumaps)
* @ncpumaps: count of cpumaps of @maplen length in @cpumaps * @ncpumaps: count of cpumaps of @maplen length in @cpumaps
* @cpumaps: array of pinning information bitmaps to be filled * @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 * @autoCpuset: Cpu pinning bitmap used in case of automatic cpu pinning
* *
* Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo API. * Fills the @cpumaps array as documented by the virDomainGetVcpuPinInfo API.
* In case when automatic cpu pinning is supported, the bitmap should be passed * 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 * as @autoCpuset.
* error message).
* *
* Returns number of filled entries or -1 on error. * Returns number of filled entries.
*/ */
int int
virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
int maplen, int maplen,
int ncpumaps, int ncpumaps,
unsigned char *cpumaps, unsigned char *cpumaps,
int hostcpus, virBitmapPtr hostcpus,
virBitmapPtr autoCpuset) virBitmapPtr autoCpuset)
{ {
int maxvcpus = virDomainDefGetVcpusMax(def); int maxvcpus = virDomainDefGetVcpusMax(def);
size_t i; 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++) { for (i = 0; i < maxvcpus && i < ncpumaps; i++) {
virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i); virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
@ -2130,7 +2122,7 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
else if (def->cpumask) else if (def->cpumask)
bitmap = def->cpumask; bitmap = def->cpumask;
else else
bitmap = allcpumap; bitmap = hostcpus;
virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen); virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen);
} }

View File

@ -3741,9 +3741,9 @@ int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
int maplen, int maplen,
int ncpumaps, int ncpumaps,
unsigned char *cpumaps, unsigned char *cpumaps,
int hostcpus, virBitmapPtr hostcpus,
virBitmapPtr autoCpuset) 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); bool virDomainDefHasMemballoon(const virDomainDef *def) ATTRIBUTE_NONNULL(1);

View File

@ -2547,6 +2547,7 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainDefPtr targetDef = NULL; virDomainDefPtr targetDef = NULL;
g_autoptr(virBitmap) hostcpus = NULL;
int ret = -1; int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@ -2568,8 +2569,12 @@ libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
/* Make sure coverity knows targetDef is valid at this point. */ /* Make sure coverity knows targetDef is valid at this point. */
sa_assert(targetDef); sa_assert(targetDef);
if (!(hostcpus = virBitmapNew(libxl_get_max_cpus(cfg->ctx))))
goto cleanup;
virBitmapSetAll(hostcpus);
ret = virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, cpumaps, ret = virDomainDefGetVcpuPinInfoHelper(targetDef, maplen, ncpumaps, cpumaps,
libxl_get_max_cpus(cfg->ctx), NULL); hostcpus, NULL);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);

View File

@ -5288,6 +5288,7 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
virDomainDefPtr def; virDomainDefPtr def;
bool live; bool live;
int ret = -1; int ret = -1;
g_autoptr(virBitmap) hostcpus = NULL;
virBitmapPtr autoCpuset = NULL; virBitmapPtr autoCpuset = NULL;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@ -5302,11 +5303,14 @@ qemuDomainGetVcpuPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDefState(vm, flags, &live))) if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
goto cleanup; goto cleanup;
if (!(hostcpus = virHostCPUGetAvailableCPUsBitmap()))
goto cleanup;
if (live) if (live)
autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset; autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset;
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps, ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
virHostCPUGetCount(), autoCpuset); hostcpus, autoCpuset);
cleanup: cleanup:
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
return ret; return ret;

View File

@ -3072,6 +3072,7 @@ testDomainGetVcpuPinInfo(virDomainPtr dom,
testDriverPtr driver = dom->conn->privateData; testDriverPtr driver = dom->conn->privateData;
virDomainObjPtr privdom; virDomainObjPtr privdom;
virDomainDefPtr def; virDomainDefPtr def;
g_autoptr(virBitmap) hostcpus = NULL;
int ret = -1; int ret = -1;
if (!(privdom = testDomObjFromDomain(dom))) if (!(privdom = testDomObjFromDomain(dom)))
@ -3080,9 +3081,12 @@ testDomainGetVcpuPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDef(privdom, flags))) if (!(def = virDomainObjGetOneDef(privdom, flags)))
goto cleanup; goto cleanup;
if (!(hostcpus = virBitmapNew(VIR_NODEINFO_MAXCPUS(driver->nodeInfo))))
goto cleanup;
virBitmapSetAll(hostcpus);
ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps, ret = virDomainDefGetVcpuPinInfoHelper(def, maplen, ncpumaps, cpumaps,
VIR_NODEINFO_MAXCPUS(driver->nodeInfo), hostcpus, NULL);
NULL);
cleanup: cleanup:
virDomainObjEndAPI(&privdom); virDomainObjEndAPI(&privdom);