
On Wed, Mar 02, 2011 at 05:13:09PM +0900, Taku Izumi wrote:
This patch implements the code to address the new API in the qemu driver.
Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com> --- src/qemu/qemu_driver.c | 64 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 13 deletions(-)
Index: libvirt-git/src/qemu/qemu_driver.c =================================================================== --- libvirt-git.orig/src/qemu/qemu_driver.c +++ libvirt-git/src/qemu/qemu_driver.c @@ -1569,12 +1569,22 @@ cleanup: return ret; }
-static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { +static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem, + unsigned int flags) { struct qemud_driver *driver = dom->conn->privateData; qemuDomainObjPrivatePtr priv; virDomainObjPtr vm; + virDomainDefPtr persistentDef; int ret = -1, r;
+ virCheckFlags(VIR_DOMAIN_MEM_LIVE | + VIR_DOMAIN_MEM_CONFIG, -1); + + if ((flags & (VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG)) == 0) { + qemuReportError(VIR_ERR_INVALID_ARG, + _("invalid flag combination: (0x%x)"), flags); + }
I think you forgot a 'return -1' statement just here.
+ qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); qemuDriverUnlock(driver); @@ -1595,27 +1605,51 @@ static int qemudDomainSetMemory(virDomai if (qemuDomainObjBeginJob(vm) < 0) goto cleanup;
- if (!virDomainObjIsActive(vm)) { + if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_MEM_LIVE)) { qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", _("domain is not running")); goto endjob; }
- priv = vm->privateData; - qemuDomainObjEnterMonitor(vm); - r = qemuMonitorSetBalloon(priv->mon, newmem); - qemuDomainObjExitMonitor(vm); - if (r < 0) + if (!vm->persistent && (flags & VIR_DOMAIN_MEM_CONFIG)) { + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot change persistent config of a transient domain")); goto endjob; + }
- /* Lack of balloon support is a fatal error */ - if (r == 0) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("cannot set memory of an active domain")); + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) goto endjob; + + switch (flags) { + case VIR_DOMAIN_MEM_CONFIG: + persistentDef->mem.cur_balloon = newmem; + ret = 0; + break; + + case VIR_DOMAIN_MEM_LIVE: + case VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG: + priv = vm->privateData; + qemuDomainObjEnterMonitor(vm); + r = qemuMonitorSetBalloon(priv->mon, newmem); + qemuDomainObjExitMonitor(vm); + if (r < 0) + goto endjob; + /* Lack of balloon support is a fatal error */ + if (r == 0) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot set memory of an active domain")); + goto endjob; + } + if (flags & VIR_DOMAIN_MEM_CONFIG) + persistentDef->mem.cur_balloon = newmem; + ret = 0; + break; }
I think it is a little wierd to use a 'switch' statement for processing this. I'd just have a pair of 'if' statements eg if (flags & VIR_DOMAIN_MEM_LIVE) { .....do monitor stuff.... } if (flags & VIR_DOMAIN_MEM_CONFIG) { persistentDef->mem.cur_balloon = newmem; ret = virDomainSaveConfig(driver->configDir, persistentDef); } Regards, 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 :|