The output of vcpupin and emulatorpin for a domain with vcpu
placement='static' is based on a default bitmap that contains
all possible CPUs in the host, regardless of the CPUs being offline
or not. E.g. for a Linux host with this CPU setup (from lscpu):
On-line CPU(s) list: 0,8,16,24,32,40,(...),184
Off-line CPU(s) list: 1-7,9-15,17-23,25-31,(...),185-191
And a domain with this configuration:
<vcpu placement='static'>1</vcpu>
'virsh vcpupin' will return the following:
$ sudo ./run tools/virsh vcpupin vcpupin_test
VCPU CPU Affinity
----------------------
0 0-191
This is benign by its own, but can make the user believe that all
CPUs from the 0-191 range are eligible for pinning. Which can lead
to situations like this:
$ sudo ./run tools/virsh vcpupin vcpupin_test 0 1
error: Invalid value '1' for 'cpuset.cpus': Invalid argument
This is exarcebated by the fact that 'virsh vcpuinfo' considers only
available host CPUs in the 'CPU Affinity' field:
$ sudo ./run tools/virsh vcpuinfo vcpupin_test
(...)
CPU Affinity: y-------y-------y-------(...)
This patch changes the default bitmap of vcpupin and emulatorpin, in
the case of domains with static vcpu placement, to all available CPUs
instead of all possible CPUs. Aside from making it consistent with
the behavior of 'vcpuinfo', users will now have one less incentive to
try to pin a vcpu in an offline CPU.
https://bugzilla.redhat.com/show_bug.cgi?id=1434276
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/conf/domain_conf.c | 4 +---
src/qemu/qemu_driver.c | 7 +------
2 files changed, 2 insertions(+), 9 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 31ba78b950..6f95023aaf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2089,11 +2089,9 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
if (hostcpus < 0)
return -1;
- if (!(allcpumap = virBitmapNew(hostcpus)))
+ if (!(allcpumap = virHostCPUGetAvailableCPUsBitmap()))
return -1;
- virBitmapSetAll(allcpumap);
-
for (i = 0; i < maxvcpus && i < ncpumaps; i++) {
virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i);
virBitmapPtr bitmap = NULL;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d486ce5278..22f0313394 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5425,7 +5425,6 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
virDomainDefPtr def;
bool live;
int ret = -1;
- int hostcpus;
virBitmapPtr cpumask = NULL;
g_autoptr(virBitmap) bitmap = NULL;
virBitmapPtr autoCpuset = NULL;
@@ -5442,9 +5441,6 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
if (!(def = virDomainObjGetOneDefState(vm, flags, &live)))
goto cleanup;
- if ((hostcpus = virHostCPUGetCount()) < 0)
- goto cleanup;
-
if (live)
autoCpuset = QEMU_DOMAIN_PRIVATE(vm)->autoCpuset;
@@ -5456,9 +5452,8 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
autoCpuset) {
cpumask = autoCpuset;
} else {
- if (!(bitmap = virBitmapNew(hostcpus)))
+ if (!(bitmap = virHostCPUGetAvailableCPUsBitmap()))
goto cleanup;
- virBitmapSetAll(bitmap);
cpumask = bitmap;
}
--
2.26.2