int ret = -1;
virBitmapPtr cpumap = NULL;
virBitmapPtr cpumapToSet = NULL;
+ virBitmapPtr hostcpumap = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
if (!vm->pid) {
* 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;
+ }
}
}
cleanup:
virBitmapFree(cpumap);
+ virBitmapFree(hostcpumap);
return ret;
}