mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-26 23:55:23 +00:00
qemu: Fix coldplug of vcpus
virDomainDefSetVcpus was not designed to handle coldplug of vcpus now that we can set state of vcpus individually. Introduce qemuDomainSetVcpusConfig that properly handles state changes of vcpus when coldplugging so that invalid configurations are not created. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1375939
This commit is contained in:
parent
6ff3e65012
commit
80ea1cf6be
@ -4901,6 +4901,58 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* qemuDomainSetVcpusConfig:
|
||||||
|
* @def: config/offline definition of a domain
|
||||||
|
* @nvcpus: target vcpu count
|
||||||
|
*
|
||||||
|
* Properly handle cold(un)plug of vcpus:
|
||||||
|
* - plug in inactive vcpus/uplug active rather than rewriting state
|
||||||
|
* - fix hotpluggable state
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
qemuDomainSetVcpusConfig(virDomainDefPtr def,
|
||||||
|
unsigned int nvcpus)
|
||||||
|
{
|
||||||
|
virDomainVcpuDefPtr vcpu;
|
||||||
|
size_t curvcpus = virDomainDefGetVcpus(def);
|
||||||
|
size_t maxvcpus = virDomainDefGetVcpusMax(def);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
|
||||||
|
if (curvcpus == nvcpus)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (curvcpus < nvcpus) {
|
||||||
|
for (i = 0; i < maxvcpus; i++) {
|
||||||
|
vcpu = virDomainDefGetVcpu(def, i);
|
||||||
|
|
||||||
|
if (!vcpu || vcpu->online)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vcpu->online = true;
|
||||||
|
vcpu->hotpluggable = VIR_TRISTATE_BOOL_NO;
|
||||||
|
|
||||||
|
if (++curvcpus == nvcpus)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = maxvcpus; i != 0; i--) {
|
||||||
|
vcpu = virDomainDefGetVcpu(def, i - 1);
|
||||||
|
|
||||||
|
if (!vcpu || !vcpu->online)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vcpu->online = false;
|
||||||
|
vcpu->hotpluggable = VIR_TRISTATE_BOOL_YES;
|
||||||
|
|
||||||
|
if (--curvcpus == nvcpus)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
|
qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -4931,8 +4983,7 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
|
qemuDomainSetVcpusConfig(persistentDef, nvcpus);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
Reference in New Issue
Block a user