From 963a5b7a08729fab81d5f21a4fb223b725953dbe Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 30 Mar 2010 09:03:26 -0400 Subject: [PATCH] Make virsh setmaxmem balloon only when successful. After playing around with virsh setmaxmem for a bit, I ran into some surprising behavior; if a hypervisor does not support the virDomainSetMaxMemory() API, but the value specified for setmaxmem is less than the current amount of memory in the domain, the domain would be ballooned down *before* an error was reported. To make this more consistent, run virDomainSetMaxMemory() before trying to shrink; that way, if an error is thrown, no changes to the running domain are made. Signed-off-by: Chris Lalancette --- tools/virsh.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index b057847021..17c3074403 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2596,17 +2596,17 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd) return FALSE; } - if (kilobytes < info.memory) { - if (virDomainSetMemory(dom, kilobytes) != 0) { - virDomainFree(dom); - vshError(ctl, "%s", _("Unable to shrink current MemorySize")); - return FALSE; - } - } - if (virDomainSetMaxMemory(dom, kilobytes) != 0) { vshError(ctl, "%s", _("Unable to change MaxMemorySize")); - ret = FALSE; + virDomainFree(dom); + return FALSE; + } + + if (kilobytes < info.memory) { + if (virDomainSetMemory(dom, kilobytes) != 0) { + vshError(ctl, "%s", _("Unable to shrink current MemorySize")); + ret = FALSE; + } } virDomainFree(dom);