qemu: Fix balloon size handling with memory hot(un)plug

Since libvirt doesn't call to update the new balloon size in qemu add
code that will handle tweaking of the size of the current balloon
statistic until qemu reports the new size using the event.
This commit is contained in:
Peter Krempa 2015-04-30 18:03:41 +02:00
parent de03b1ddde
commit 2f37362e44
2 changed files with 13 additions and 0 deletions

View File

@ -8373,6 +8373,9 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
return -1; return -1;
} }
if (vmdef->mem.cur_balloon == virDomainDefGetMemoryActual(vmdef))
vmdef->mem.cur_balloon += dev->data.memory->size;
if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0) if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
return -1; return -1;
dev->data.memory = NULL; dev->data.memory = NULL;

View File

@ -1726,6 +1726,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
const char *backendType; const char *backendType;
virJSONValuePtr props = NULL; virJSONValuePtr props = NULL;
virObjectEventPtr event; virObjectEventPtr event;
bool fix_balloon = false;
int id; int id;
int ret = -1; int ret = -1;
@ -1741,6 +1742,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0) if (virAsprintf(&objalias, "mem%s", mem->info.alias) < 0)
goto cleanup; goto cleanup;
if (vm->def->mem.cur_balloon == virDomainDefGetMemoryActual(vm->def))
fix_balloon = true;
if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps))) if (!(devstr = qemuBuildMemoryDeviceStr(mem, vm->def, priv->qemuCaps)))
goto cleanup; goto cleanup;
@ -1779,6 +1783,10 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
if (event) if (event)
qemuDomainEventQueue(driver, event); qemuDomainEventQueue(driver, event);
/* fix the balloon size if it was set to maximum */
if (fix_balloon)
vm->def->mem.cur_balloon += mem->size;
/* mem is consumed by vm->def */ /* mem is consumed by vm->def */
mem = NULL; mem = NULL;
@ -2896,6 +2904,8 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
goto error; goto error;
vm->def->mem.cur_balloon -= mem->size;
if ((idx = virDomainMemoryFindByDef(vm->def, mem)) >= 0) if ((idx = virDomainMemoryFindByDef(vm->def, mem)) >= 0)
virDomainMemoryRemove(vm->def, idx); virDomainMemoryRemove(vm->def, idx);