mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: setvcpus: Extract setting of maximum vcpu count
Setting of the maximum vcpu count is slightly semantically different thus split it into a self-contained func.
This commit is contained in:
parent
c2e12b01ba
commit
f10da2f553
@ -4755,6 +4755,42 @@ qemuDomainSetVcpusAgent(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
|
||||||
|
virDomainDefPtr def,
|
||||||
|
virDomainDefPtr persistentDef,
|
||||||
|
unsigned int nvcpus)
|
||||||
|
{
|
||||||
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (def) {
|
||||||
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||||
|
_("maximum vcpu count of a live domain can't be modified"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virDomainNumaGetCPUCountTotal(persistentDef->numa) > nvcpus) {
|
||||||
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
|
_("Number of CPUs in <numa> exceeds the desired "
|
||||||
|
"maximum vcpu count"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
@ -4799,14 +4835,12 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (def) {
|
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
||||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
ret = qemuDomainSetVcpusMax(driver, def, persistentDef, nvcpus);
|
||||||
_("maximum vcpu count of a live domain can't be "
|
|
||||||
"modified"));
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (def) {
|
||||||
if (nvcpus > virDomainDefGetVcpusMax(def)) {
|
if (nvcpus > virDomainDefGetVcpusMax(def)) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("requested vcpus is greater than max allowable"
|
_("requested vcpus is greater than max allowable"
|
||||||
@ -4817,8 +4851,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
|
if (nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
|
||||||
nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
virReportError(VIR_ERR_INVALID_ARG,
|
||||||
_("requested vcpus is greater than max allowable"
|
_("requested vcpus is greater than max allowable"
|
||||||
" vcpus for the persistent domain: %u > %u"),
|
" vcpus for the persistent domain: %u > %u"),
|
||||||
@ -4862,20 +4895,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (persistentDef) {
|
if (persistentDef) {
|
||||||
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
|
|
||||||
if (virDomainNumaGetCPUCountTotal(persistentDef->numa) > nvcpus) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
||||||
_("Number of CPUs in <numa> exceeds the desired "
|
|
||||||
"maximum vcpu count"));
|
|
||||||
goto endjob;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
|
|
||||||
goto endjob;
|
|
||||||
} else {
|
|
||||||
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
|
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainSaveConfig(cfg->configDir, driver->caps,
|
if (virDomainSaveConfig(cfg->configDir, driver->caps,
|
||||||
persistentDef) < 0)
|
persistentDef) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user