]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Fix balloon size handling with memory hot(un)plug
authorPeter Krempa <pkrempa@redhat.com>
Thu, 30 Apr 2015 16:03:41 +0000 (18:03 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 11 May 2015 06:50:36 +0000 (08:50 +0200)
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.

src/qemu/qemu_driver.c
src/qemu/qemu_hotplug.c

index 8099d6049fbf9dc9bcf4aae5e46931ff2bf27766..33c1cfd4cd3e10a9d732a9ad544b4f8884030317 100644 (file)
@@ -8373,6 +8373,9 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
             return -1;
         }
 
+        if (vmdef->mem.cur_balloon == virDomainDefGetMemoryActual(vmdef))
+            vmdef->mem.cur_balloon += dev->data.memory->size;
+
         if (virDomainMemoryInsert(vmdef, dev->data.memory) < 0)
             return -1;
         dev->data.memory = NULL;
index 095ed88adb62459a584713c2285227e1beb241b8..fc45de1a5b67a6a9f7e19390f0b9a46ac81d3deb 100644 (file)
@@ -1726,6 +1726,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
     const char *backendType;
     virJSONValuePtr props = NULL;
     virObjectEventPtr event;
+    bool fix_balloon = false;
     int id;
     int ret = -1;
 
@@ -1741,6 +1742,9 @@ 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, vm->def, priv->qemuCaps)))
         goto cleanup;
 
@@ -1779,6 +1783,10 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
     if (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 = NULL;
 
@@ -2896,6 +2904,8 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
     if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
         goto error;
 
+    vm->def->mem.cur_balloon -= mem->size;
+
     if ((idx = virDomainMemoryFindByDef(vm->def, mem)) >= 0)
         virDomainMemoryRemove(vm->def, idx);