diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e5b77d63769a06f16dc815c9fa995783a7d65d86..3871034818b119b340db22ccd7eb2a3eff7c1ffa 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2195,6 +2195,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) int ret = -1; virBitmapPtr cpumap = NULL; virBitmapPtr cpumapToSet = NULL; + virBitmapPtr hostcpumap = NULL; qemuDomainObjPrivatePtr priv = vm->privateData; if (!vm->pid) { @@ -2217,20 +2218,34 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) * its config file */ int hostcpus; - /* setaffinity fails if you set bits for CPUs which - * aren't present, so we have to limit ourselves */ - if ((hostcpus = virHostCPUGetCount()) < 0) + if (virHostCPUHasBitmap()) { + hostcpumap = virHostCPUGetOnlineBitmap(); + cpumap = virProcessGetAffinity(vm->pid); + } + + if (hostcpumap && cpumap && virBitmapEqual(hostcpumap, cpumap)) { + /* we're using all available CPUs, no reason to set + * mask. If libvirtd is running without explicit + * affinity, we can use hotplugged CPUs for this VM */ + ret = 0; goto cleanup; + } else { + /* setaffinity fails if you set bits for CPUs which + * aren't present, so we have to limit ourselves */ + if ((hostcpus = virHostCPUGetCount()) < 0) + goto cleanup; - if (hostcpus > QEMUD_CPUMASK_LEN) - hostcpus = QEMUD_CPUMASK_LEN; + if (hostcpus > QEMUD_CPUMASK_LEN) + hostcpus = QEMUD_CPUMASK_LEN; - if (!(cpumap = virBitmapNew(hostcpus))) - goto cleanup; + virBitmapFree(cpumap); + if (!(cpumap = virBitmapNew(hostcpus))) + goto cleanup; - virBitmapSetAll(cpumap); + virBitmapSetAll(cpumap); - cpumapToSet = cpumap; + cpumapToSet = cpumap; + } } } @@ -2241,6 +2256,7 @@ qemuProcessInitCpuAffinity(virDomainObjPtr vm) cleanup: virBitmapFree(cpumap); + virBitmapFree(hostcpumap); return ret; }