https://bugzilla.redhat.com/show_bug.cgi?id=1038363
If a domain has a different maximum for persistent and live maxmem
or max vcpus, then it is possible to hit cases where libvirt
refuses to adjust the current values or gets halfway through
the adjustment before failing. Better is to determine up front
if the change is possible for all requested flags.
* src/qemu/qemu_driver.c (qemuDomainSetMemoryFlags): Compute
correct maximum if both live and config are being set.
(qemuDomainSetVcpusFlags): Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/qemu/qemu_driver.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a0b3ce3..288b98b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2242,8 +2242,16 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long
newmem,
} else {
/* resize the current memory */
+ unsigned long oldmax = 0;
- if (newmem > vm->def->mem.max_balloon) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE)
+ oldmax = vm->def->mem.max_balloon;
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ if (!oldmax || oldmax > persistentDef->mem.max_balloon)
+ oldmax = persistentDef->mem.max_balloon;
+ }
+
+ if (newmem > oldmax) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("cannot set memory higher than max memory"));
goto endjob;
@@ -4121,6 +4129,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
virDomainDefPtr persistentDef;
int ret = -1;
bool maximum;
+ unsigned int maxvcpus = 0;
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
qemuAgentCPUInfoPtr cpuinfo = NULL;
@@ -4168,11 +4177,17 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
goto endjob;
}
- if (!maximum && nvcpus > vm->def->maxvcpus) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE)
+ maxvcpus = vm->def->maxvcpus;
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ if (!maxvcpus || maxvcpus > persistentDef->maxvcpus)
+ maxvcpus = persistentDef->maxvcpus;
+ }
+ if (!maximum && nvcpus > maxvcpus) {
virReportError(VIR_ERR_INVALID_ARG,
_("requested vcpus is greater than max allowable"
" vcpus for the domain: %d > %d"),
- nvcpus, vm->def->maxvcpus);
+ nvcpus, maxvcpus);
goto endjob;
}
--
1.8.5.3