Setting of the maximum vcpu count is slightly semantically different
thus split it into a self-contained func.
---
src/qemu/qemu_driver.c | 47 +++++++++++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3e37f7e..cd1fb3d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4756,6 +4756,29 @@ qemuDomainSetVcpusAgent(virDomainObjPtr vm,
static int
+qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
+ virQEMUDriverConfigPtr cfg,
+ virDomainDefPtr persistentDef,
+ unsigned int nvcpus)
+{
+ if (virDomainNumaGetCPUCountTotal(persistentDef->numa) > nvcpus) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("Number of CPUs in <numa> exceeds the desired "
+ "maximum vcpu count"));
+ return -1;
+ }
+
+ if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
+ return -1;
+
+ if (virDomainSaveConfig(cfg->configDir, driver->caps, persistentDef) < 0)
+ return -1;
+
+ return 0;
+}
+
+
+static int
qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
unsigned int flags)
{
@@ -4834,8 +4857,12 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
}
if (persistentDef) {
- if (!(flags & VIR_DOMAIN_VCPU_MAXIMUM) &&
- nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
+ if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
+ ret = qemuDomainSetVcpusMax(driver, cfg, persistentDef, nvcpus);
+ goto endjob;
+ }
+
+ if (nvcpus > virDomainDefGetVcpusMax(persistentDef)) {
virReportError(VIR_ERR_INVALID_ARG,
_("requested vcpus is greater than max allowable"
" vcpus for the persistent domain: %d > %d"),
@@ -4862,20 +4889,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
}
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)
- goto endjob;
- }
+ if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
+ goto endjob;
if (virDomainSaveConfig(cfg->configDir, driver->caps,
persistentDef) < 0)
--
2.9.2