Rather than trying some magic calculations on our side query the monitor for the current size of the memory balloon both on hotplug and hotunplug. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1220702 --- src/qemu/qemu_hotplug.c | 15 ++++++--------- src/qemu/qemu_process.c | 2 +- src/qemu/qemu_process.h | 4 ++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 48bea6a..f77d65a 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -33,6 +33,7 @@ #include "qemu_command.h" #include "qemu_hostdev.h" #include "qemu_interface.h" +#include "qemu_process.h" #include "domain_audit.h" #include "netdev_bandwidth_conf.h" #include "domain_nwfilter.h" @@ -1742,7 +1743,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, const char *backendType; virJSONValuePtr props = NULL; virObjectEventPtr event; - bool fix_balloon = false; int id; int ret = -1; @@ -1757,9 +1757,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0) goto cleanup; - if (vm->def->mem.cur_balloon == virDomainDefGetMemoryActual(vm->def)) - fix_balloon = true; - if (!(devstr = qemuBuildMemoryDeviceStr(mem))) goto cleanup; @@ -1800,9 +1797,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, event = virDomainEventDeviceAddedNewFromObj(vm, objalias); qemuDomainEventQueue(driver, event); - /* fix the balloon size if it was set to maximum */ - if (fix_balloon) - vm->def->mem.cur_balloon += mem->size; + /* fix the balloon size */ + ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB_NONE)); /* mem is consumed by vm->def */ mem = NULL; @@ -2939,13 +2935,14 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver, if (rc < 0) return -1; - vm->def->mem.cur_balloon -= mem->size; - if ((idx = virDomainMemoryFindByDef(vm->def, mem)) >= 0) virDomainMemoryRemove(vm->def, idx); virDomainMemoryDefFree(mem); + /* fix the balloon size */ + ignore_value(qemuProcessRefreshBalloonState(driver, vm, QEMU_ASYNC_JOB_NONE)); + /* decrease the mlock limit after memory unplug if necessary */ ignore_value(qemuDomainAdjustMaxMemLock(vm)); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a8c5139..c7456af 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1923,7 +1923,7 @@ qemuRefreshVirtioChannelState(virQEMUDriverPtr driver, } -static int +int qemuProcessRefreshBalloonState(virQEMUDriverPtr driver, virDomainObjPtr vm, int asyncJob) diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index d5f50f2..98cc9a8 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -193,4 +193,8 @@ int qemuProcessSetupIOThread(virDomainObjPtr vm, int qemuRefreshVirtioChannelState(virQEMUDriverPtr driver, virDomainObjPtr vm); + +int qemuProcessRefreshBalloonState(virQEMUDriverPtr driver, + virDomainObjPtr vm, + int asyncJob); #endif /* __QEMU_PROCESS_H__ */ -- 2.8.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list