[libvirt] [PATCH] qemu: adjust maxmem/maxvcpu computation

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@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

On 01/29/2014 12:04 PM, Eric Blake wrote:
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.
ping. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Wed, Jan 29, 2014 at 12:04:32PM -0700, Eric Blake wrote:
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@redhat.com> --- src/qemu/qemu_driver.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
ACK Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 02/20/2014 10:38 AM, Daniel P. Berrange wrote:
On Wed, Jan 29, 2014 at 12:04:32PM -0700, Eric Blake wrote:
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@redhat.com> --- src/qemu/qemu_driver.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
ACK
Thanks; pushed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Daniel P. Berrange
-
Eric Blake