Extract the call to qemuDomainSelectHotplugVcpuEntities outside of qemuDomainSetVcpusLive and decide whether to hotplug or unplug the entities specified by the cpumap using a boolean flag. This will allow to use qemuDomainSetVcpusLive in cases where we prepare the list of vcpus to enable or disable by other means. --- src/qemu/qemu_driver.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 842de0a..af8f458 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4776,6 +4776,7 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver, * * @def: domain definition * @nvcpus: target vcpu count + * @enable: set to true if vcpus should be enabled * * Tries to find which vcpu entities need to be enabled or disabled to reach * @nvcpus. This function works in order of the legacy hotplug but is able to @@ -4785,7 +4786,8 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver, */ static virBitmapPtr qemuDomainSelectHotplugVcpuEntities(virDomainDefPtr def, - unsigned int nvcpus) + unsigned int nvcpus, + bool *enable) { virBitmapPtr ret = NULL; virDomainVcpuDefPtr vcpu; @@ -4798,6 +4800,8 @@ qemuDomainSelectHotplugVcpuEntities(virDomainDefPtr def, return NULL; if (nvcpus > curvcpus) { + *enable = true; + for (i = 0; i < maxvcpus && curvcpus < nvcpus; i++) { vcpu = virDomainDefGetVcpu(def, i); vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu); @@ -4820,6 +4824,8 @@ qemuDomainSelectHotplugVcpuEntities(virDomainDefPtr def, ignore_value(virBitmapSetBit(ret, i)); } } else { + *enable = false; + for (i = maxvcpus - 1; i >= 0 && curvcpus > nvcpus; i--) { vcpu = virDomainDefGetVcpu(def, i); vcpupriv = QEMU_DOMAIN_VCPU_PRIVATE(vcpu); @@ -4865,22 +4871,19 @@ static int qemuDomainSetVcpusLive(virQEMUDriverPtr driver, virQEMUDriverConfigPtr cfg, virDomainObjPtr vm, - unsigned int nvcpus) + virBitmapPtr vcpumap, + bool enable) { qemuDomainObjPrivatePtr priv = vm->privateData; qemuCgroupEmulatorAllNodesDataPtr emulatorCgroup = NULL; - virBitmapPtr vcpumap = NULL; ssize_t nextvcpu = -1; int rc = 0; int ret = -1; - if (!(vcpumap = qemuDomainSelectHotplugVcpuEntities(vm->def, nvcpus))) - goto cleanup; - if (qemuCgroupEmulatorAllNodesAllow(priv->cgroup, &emulatorCgroup) < 0) goto cleanup; - if (nvcpus > virDomainDefGetVcpus(vm->def)) { + if (enable) { while ((nextvcpu = virBitmapNextSetBit(vcpumap, nextvcpu)) != -1) { if ((rc = qemuDomainHotplugAddVcpu(driver, vm, nextvcpu)) < 0) break; @@ -4907,7 +4910,6 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver, cleanup: qemuCgroupEmulatorAllNodesRestore(emulatorCgroup); - virBitmapFree(vcpumap); return ret; } @@ -4982,6 +4984,8 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver, bool hotpluggable) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + virBitmapPtr vcpumap = NULL; + bool enable; int ret = -1; if (def && nvcpus > virDomainDefGetVcpusMax(def)) { @@ -5000,8 +5004,14 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver, goto cleanup; } - if (def && qemuDomainSetVcpusLive(driver, cfg, vm, nvcpus) < 0) - goto cleanup; + if (def) { + if (!(vcpumap = qemuDomainSelectHotplugVcpuEntities(vm->def, nvcpus, + &enable))) + goto cleanup; + + if (qemuDomainSetVcpusLive(driver, cfg, vm, vcpumap, enable) < 0) + goto cleanup; + } if (persistentDef) { qemuDomainSetVcpusConfig(persistentDef, nvcpus, hotpluggable); @@ -5013,6 +5023,7 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver, ret = 0; cleanup: + virBitmapFree(vcpumap); virObjectUnref(cfg); return ret; } -- 2.10.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list