Blame SOURCES/libvirt-qemu-process-Improve-update-of-maximum-balloon-state-at-startup.patch

7a3408
From e2860c4cd200424d09be581bc5c0b206dcffb629 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <e2860c4cd200424d09be581bc5c0b206dcffb629@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Tue, 14 Jul 2015 15:02:58 +0200
7a3408
Subject: [PATCH] qemu: process: Improve update of maximum balloon state at
7a3408
 startup
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1242940
7a3408
7a3408
In commit 641a145d73fdc3dd9350fd57b3d3247abf101c05 I've added code that
7a3408
resets the balloon memory value to full size prior to resuming the vCPUs
7a3408
since the size certainly was not reduced at that point.
7a3408
7a3408
Since qemuProcessStart is used also in code paths with already booted
7a3408
up guests (migration, save/restore) the assumption is not entirely true
7a3408
since the guest might already been running before.
7a3408
7a3408
This patch adds a function that queries the monitor rather than using
7a3408
the full size since a balloon event would not be reissued in case we are
7a3408
recovering a saved migration state.
7a3408
7a3408
Additionally the new function is used also when reconnecting to a VM
7a3408
after libvirtd restart since we might have missed a few balloon events
7a3408
while libvirtd was not running.
7a3408
7a3408
(cherry picked from commit c212e0c77986b0592f63e02d9ecd816aaf7aac18)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_process.c | 40 ++++++++++++++++++++++++++++++++++++++--
7a3408
 1 file changed, 38 insertions(+), 2 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
7a3408
index e05be54..35b6513 100644
7a3408
--- a/src/qemu/qemu_process.c
7a3408
+++ b/src/qemu/qemu_process.c
7a3408
@@ -2116,6 +2116,38 @@ qemuProcessReconnectRefreshChannelVirtioState(virQEMUDriverPtr driver,
7a3408
 
7a3408
 
7a3408
 static int
7a3408
+qemuProcessRefreshBalloonState(virQEMUDriverPtr driver,
7a3408
+                               virDomainObjPtr vm,
7a3408
+                               int asyncJob)
7a3408
+{
7a3408
+    unsigned long long balloon;
7a3408
+    int rc;
7a3408
+
7a3408
+    /* if no ballooning is available, the current size equals to the current
7a3408
+     * full memory size */
7a3408
+    if (!vm->def->memballoon ||
7a3408
+        vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) {
7a3408
+        vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def);
7a3408
+        return 0;
7a3408
+    }
7a3408
+
7a3408
+    if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
7a3408
+        return -1;
7a3408
+
7a3408
+    rc = qemuMonitorGetBalloonInfo(qemuDomainGetMonitor(vm), &balloon);
7a3408
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
7a3408
+        rc = -1;
7a3408
+
7a3408
+    if (rc < 0)
7a3408
+        return -1;
7a3408
+
7a3408
+    vm->def->mem.cur_balloon = balloon;
7a3408
+
7a3408
+    return 0;
7a3408
+}
7a3408
+
7a3408
+
7a3408
+static int
7a3408
 qemuProcessWaitForMonitor(virQEMUDriverPtr driver,
7a3408
                           virDomainObjPtr vm,
7a3408
                           int asyncJob,
7a3408
@@ -3830,6 +3862,9 @@ qemuProcessReconnect(void *opaque)
7a3408
     if (qemuProcessReconnectRefreshChannelVirtioState(driver, obj) < 0)
7a3408
         goto error;
7a3408
 
7a3408
+    if (qemuProcessRefreshBalloonState(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
7a3408
+        goto error;
7a3408
+
7a3408
     if (qemuProcessRecoverJob(driver, obj, conn, &oldjob) < 0)
7a3408
         goto error;
7a3408
 
7a3408
@@ -4970,10 +5005,11 @@ int qemuProcessStart(virConnectPtr conn,
7a3408
             goto cleanup;
7a3408
     }
7a3408
 
7a3408
-    /* Since CPUs were not started yet, the ballon could not return the memory
7a3408
+    /* Since CPUs were not started yet, the balloon could not return the memory
7a3408
      * to the host and thus cur_balloon needs to be updated so that GetXMLdesc
7a3408
      * and friends return the correct size in case they can't grab the job */
7a3408
-    vm->def->mem.cur_balloon = virDomainDefGetMemoryActual(vm->def);
7a3408
+    if (qemuProcessRefreshBalloonState(driver, vm, asyncJob) < 0)
7a3408
+        goto cleanup;
7a3408
 
7a3408
     VIR_DEBUG("Detecting actual memory size for video device");
7a3408
     if (qemuProcessUpdateVideoRamSize(driver, vm, asyncJob) < 0)
7a3408
-- 
7a3408
2.5.0
7a3408