* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Pull old qemudDomainGetMemoryBalloon() code into a new method called qemuMonitorGetBalloonInfo() * src/qemu/qemu_driver.c: Update to call qemuMonitorGetBalloonInfo() and remove qemudDomainGetMemoryBalloon(). --- src/qemu/qemu_driver.c | 62 ++++++----------------------------------- src/qemu/qemu_monitor_text.c | 42 ++++++++++++++++++++++++++++ src/qemu/qemu_monitor_text.h | 2 + 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 841ab68..8d3c9b6 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2999,53 +2999,6 @@ cleanup: } -/* The reply from QEMU contains 'ballon: actual=421' where value is in MB */ -#define BALLOON_PREFIX "balloon: actual=" - -/* - * Returns: 0 if balloon not supported, +1 if balloon query worked - * or -1 on failure - */ -static int qemudDomainGetMemoryBalloon(virConnectPtr conn, - virDomainObjPtr vm, - unsigned long *currmem) { - char *reply = NULL; - int ret = -1; - char *offset; - - if (!virDomainIsActive(vm)) - return 0; - - if (qemudMonitorCommand(vm, "info balloon", &reply) < 0) { - qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED, - "%s", _("could not query memory balloon allocation")); - goto cleanup; - } - - DEBUG ("%s: balloon reply: '%s'", vm->def->name, reply); - if ((offset = strstr(reply, BALLOON_PREFIX)) != NULL) { - unsigned int memMB; - char *end; - offset += strlen(BALLOON_PREFIX); - if (virStrToLong_ui(offset, &end, 10, &memMB) < 0) { - qemudReportError(conn, dom, NULL, VIR_ERR_OPERATION_FAILED, - "%s", _("could not parse memory balloon allocation")); - goto cleanup; - } - *currmem = memMB * 1024; - ret = 1; - } else { - /* We don't raise an error here, since its to be expected that - * many QEMU's don't support ballooning - */ - ret = 0; - } - -cleanup: - VIR_FREE(reply); - return ret; -} - /* * Returns: 0 if balloon not supported, +1 if balloon query worked * or -1 on failure @@ -3161,7 +3114,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, info->maxMem = vm->def->maxmem; if (virDomainIsActive(vm)) { - err = qemudDomainGetMemoryBalloon(dom->conn, vm, &balloon); + err = qemuMonitorGetBalloonInfo(vm, &balloon); if (err < 0) goto cleanup; @@ -4122,11 +4075,14 @@ static char *qemudDomainDumpXML(virDomainPtr dom, } /* Refresh current memory based on balloon info */ - err = qemudDomainGetMemoryBalloon(dom->conn, vm, &balloon); - if (err < 0) - goto cleanup; - if (err > 0) - vm->def->memory = balloon; + if (virDomainIsActive(vm)) { + err = qemuMonitorGetBalloonInfo(vm, &balloon); + if (err < 0) + goto cleanup; + if (err > 0) + vm->def->memory = balloon; + /* err == 0 indicates no balloon support, so ignore it */ + } ret = virDomainDefFormat(dom->conn, (flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index ec5f670..2a20db3 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -547,6 +547,48 @@ error: } + +/* The reply from QEMU contains 'ballon: actual=421' where value is in MB */ +#define BALLOON_PREFIX "balloon: actual=" + +int qemuMonitorGetBalloonInfo(const virDomainObjPtr vm, + unsigned long *currmem) +{ + char *reply = NULL; + int ret = -1; + char *offset; + + if (qemudMonitorCommand(vm, "info balloon", &reply) < 0) { + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, + "%s", _("could not query memory balloon allocation")); + return -1; + } + + DEBUG ("%s: balloon reply: '%s'", vm->def->name, reply); + if ((offset = strstr(reply, BALLOON_PREFIX)) != NULL) { + unsigned int memMB; + char *end; + offset += strlen(BALLOON_PREFIX); + if (virStrToLong_ui(offset, &end, 10, &memMB) < 0) { + qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, + _("could not parse memory balloon allocation from '%s'"), reply); + goto cleanup; + } + *currmem = memMB * 1024; + ret = 1; + } else { + /* We don't raise an error here, since its to be expected that + * many QEMU's don't support ballooning + */ + ret = 0; + } + +cleanup: + VIR_FREE(reply); + return ret; +} + + int qemuMonitorSetVNCPassword(const virDomainObjPtr vm, const char *password) { diff --git a/src/qemu/qemu_monitor_text.h b/src/qemu/qemu_monitor_text.h index 342a3f3..43b59e2 100644 --- a/src/qemu/qemu_monitor_text.h +++ b/src/qemu/qemu_monitor_text.h @@ -73,6 +73,8 @@ int qemuMonitorSystemPowerdown(const virDomainObjPtr vm); int qemuMonitorGetCPUInfo(const virDomainObjPtr vm, int **pids); +int qemuMonitorGetBalloonInfo(const virDomainObjPtr vm, + unsigned long *currmem); int qemuMonitorSetVNCPassword(const virDomainObjPtr vm, const char *password); -- 1.6.2.5 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list