qemu: Allow making vcpus hotpluggable with virDomainSetVcpusFlags

Implement support for VIR_DOMAIN_VCPU_HOTPLUGGABLE so that users can
choose to make vcpus added by the API removable.
This commit is contained in:
Peter Krempa 2016-09-21 07:57:43 +02:00
parent 0f95f31c83
commit dfcd164ba9

View File

@ -4915,7 +4915,8 @@ qemuDomainSetVcpusLive(virQEMUDriverPtr driver,
*/ */
static void static void
qemuDomainSetVcpusConfig(virDomainDefPtr def, qemuDomainSetVcpusConfig(virDomainDefPtr def,
unsigned int nvcpus) unsigned int nvcpus,
bool hotpluggable)
{ {
virDomainVcpuDefPtr vcpu; virDomainVcpuDefPtr vcpu;
size_t curvcpus = virDomainDefGetVcpus(def); size_t curvcpus = virDomainDefGetVcpus(def);
@ -4936,7 +4937,12 @@ qemuDomainSetVcpusConfig(virDomainDefPtr def,
continue; continue;
vcpu->online = true; vcpu->online = true;
if (hotpluggable) {
vcpu->hotpluggable = VIR_TRISTATE_BOOL_YES;
def->individualvcpus = true;
} else {
vcpu->hotpluggable = VIR_TRISTATE_BOOL_NO; vcpu->hotpluggable = VIR_TRISTATE_BOOL_NO;
}
if (++curvcpus == nvcpus) if (++curvcpus == nvcpus)
break; break;
@ -4963,7 +4969,8 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDefPtr def, virDomainDefPtr def,
virDomainDefPtr persistentDef, virDomainDefPtr persistentDef,
unsigned int nvcpus) unsigned int nvcpus,
bool hotpluggable)
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1; int ret = -1;
@ -4988,7 +4995,7 @@ qemuDomainSetVcpusInternal(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
if (persistentDef) { if (persistentDef) {
qemuDomainSetVcpusConfig(persistentDef, nvcpus); qemuDomainSetVcpusConfig(persistentDef, nvcpus, hotpluggable);
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0) if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
goto cleanup; goto cleanup;
@ -5011,12 +5018,14 @@ qemuDomainSetVcpusFlags(virDomainPtr dom,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainDefPtr def; virDomainDefPtr def;
virDomainDefPtr persistentDef; virDomainDefPtr persistentDef;
bool hotpluggable = !!(flags & VIR_DOMAIN_VCPU_HOTPLUGGABLE);
int ret = -1; int ret = -1;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_CONFIG |
VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_MAXIMUM |
VIR_DOMAIN_VCPU_GUEST, -1); VIR_DOMAIN_VCPU_GUEST |
VIR_DOMAIN_VCPU_HOTPLUGGABLE, -1);
if (!(vm = qemuDomObjFromDomain(dom))) if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
@ -5035,7 +5044,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom,
else if (flags & VIR_DOMAIN_VCPU_MAXIMUM) else if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus); ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
else else
ret = qemuDomainSetVcpusInternal(driver, vm, def, persistentDef, nvcpus); ret = qemuDomainSetVcpusInternal(driver, vm, def, persistentDef,
nvcpus, hotpluggable);
endjob: endjob:
qemuDomainObjEndJob(driver, vm); qemuDomainObjEndJob(driver, vm);