This is an incomplete patch starting to support the memory balloon device in QEMU guests. This requires the VirtIO Balloon driver be present in the guest. In much the same way as with Xen guests, this lets you adjust the memory allocation of the guest on the fly, ceiling limited by the initial memory allocation when booted. The missing bit is to use 'info balloon' to fetch the current allocation for the virDomainGetInfo() API call. Regards, Daniel diff -r 2662c220efc8 src/qemu_driver.c --- a/src/qemu_driver.c Thu Feb 26 15:31:11 2009 +0000 +++ b/src/qemu_driver.c Thu Feb 26 15:31:23 2009 +0000 @@ -2223,6 +2223,46 @@ cleanup: return ret; } + +static int qemudDomainSetMemoryBalloon(virConnectPtr conn, + virDomainObjPtr vm, + unsigned long newmem) { + char *cmd; + char *reply; + + /* + * 'newmem' is in KB, QEMU monitor works in MB, and we all wish + * we just worked in bytes with unsigned long long everywhere. + */ + if (virAsprintf(&cmd, "balloon %lu", (newmem / 1024)) < 0) { + virReportOOMError(conn); + return -1; + } + + if (qemudMonitorCommand(vm, cmd, &reply) < 0) { + qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + "%s", _("could not balloon memory allocation")); + VIR_FREE(cmd); + return -1; + } + VIR_FREE(cmd); + + /* If the command failed qemu prints: + * device not found, device is locked ... + * No message is printed on success it seems */ + DEBUG ("balloon reply: %s", reply); + if (strstr(reply, "\nunknown command:")) { + qemudReportError (conn, dom, NULL, VIR_ERR_OPERATION_FAILED, + _("memory ballooning is not supported %s"), reply); + VIR_FREE(reply); + return -1; + } + VIR_FREE(reply); + + return 0; +} + + static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { struct qemud_driver *driver = dom->conn->privateData; virDomainObjPtr vm; @@ -2240,20 +2280,18 @@ static int qemudDomainSetMemory(virDomai goto cleanup; } + if (newmem > vm->def->maxmem) { + qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG, + "%s", _("cannot set memory higher than max memory")); + goto cleanup; + } + if (virDomainIsActive(vm)) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, - "%s", _("cannot set memory of an active domain")); - goto cleanup; - } - - if (newmem > vm->def->maxmem) { - qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG, - "%s", _("cannot set memory higher than max memory")); - goto cleanup; - } - - vm->def->memory = newmem; - ret = 0; + ret = qemudDomainSetMemoryBalloon(dom->conn, vm, newmem); + } else { + vm->def->memory = newmem; + ret = 0; + } cleanup: if (vm) -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list