38f2fd
From 95b3838c5ea2c34dbb400979f69eb50114feb72f Mon Sep 17 00:00:00 2001
38f2fd
Message-Id: <95b3838c5ea2c34dbb400979f69eb50114feb72f@dist-git>
38f2fd
From: Luyao Huang <lhuang@redhat.com>
38f2fd
Date: Thu, 12 Nov 2015 08:40:40 +0100
38f2fd
Subject: [PATCH] qemu: Emit correct audit message for memory hot unplug
38f2fd
38f2fd
https://bugzilla.redhat.com/show_bug.cgi?id=1280420
38f2fd
https://bugzilla.redhat.com/show_bug.cgi?id=1226234#c3
38f2fd
38f2fd
If the qemu monitor fails to remove the memory from the guest for
38f2fd
any reason, the auditlog message will incorrectly use the current
38f2fd
actual memory (via virDomainDefGetMemoryActual) instead of the
38f2fd
value we were attempting to reduce to. The result is the 'new-mem'
38f2fd
and 'old-mem' values for the auditlog message would be identical.
38f2fd
38f2fd
This patch creates a local 'newmem' which accounts for the current
38f2fd
memory size minus the memory which is being removed. NB, for the
38f2fd
success case this results in the same value that would be returned
38f2fd
by virDomainDefGetMemoryActual without the need to do the math. This
38f2fd
follows the existing code which would subtract the size for cur_balloon.
38f2fd
38f2fd
Signed-off-by: Luyao Huang <lhuang@redhat.com>
38f2fd
(cherry picked from commit 8f8031df1998725ac34a9a3138705c4f7cdf0488)
38f2fd
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
38f2fd
---
38f2fd
 src/qemu/qemu_hotplug.c | 23 +++++++++++------------
38f2fd
 1 file changed, 11 insertions(+), 12 deletions(-)
38f2fd
38f2fd
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
38f2fd
index f702c9f..aa1fb31 100644
38f2fd
--- a/src/qemu/qemu_hotplug.c
38f2fd
+++ b/src/qemu/qemu_hotplug.c
38f2fd
@@ -2933,11 +2933,11 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
38f2fd
 {
38f2fd
     qemuDomainObjPrivatePtr priv = vm->privateData;
38f2fd
     unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
38f2fd
+    unsigned long long newmem = oldmem - mem->size;
38f2fd
     virObjectEventPtr event;
38f2fd
     char *backendAlias = NULL;
38f2fd
     int rc;
38f2fd
     int idx;
38f2fd
-    int ret = -1;
38f2fd
 
38f2fd
     VIR_DEBUG("Removing memory device %s from domain %p %s",
38f2fd
               mem->info.alias, vm, vm->def->name);
38f2fd
@@ -2946,12 +2946,18 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
38f2fd
         qemuDomainEventQueue(driver, event);
38f2fd
 
38f2fd
     if (virAsprintf(&backendAlias, "mem%s", mem->info.alias) < 0)
38f2fd
-        goto cleanup;
38f2fd
+        return -1;
38f2fd
 
38f2fd
     qemuDomainObjEnterMonitor(driver, vm);
38f2fd
     rc = qemuMonitorDelObject(priv->mon, backendAlias);
38f2fd
-    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
38f2fd
-        goto cleanup;
38f2fd
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
38f2fd
+        rc = -1;
38f2fd
+
38f2fd
+    VIR_FREE(backendAlias);
38f2fd
+
38f2fd
+    virDomainAuditMemory(vm, oldmem, newmem, "update", rc == 0);
38f2fd
+    if (rc < 0)
38f2fd
+        return -1;
38f2fd
 
38f2fd
     vm->def->mem.cur_balloon -= mem->size;
38f2fd
 
38f2fd
@@ -2959,14 +2965,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
38f2fd
         virDomainMemoryRemove(vm->def, idx);
38f2fd
 
38f2fd
     virDomainMemoryDefFree(mem);
38f2fd
-    ret = 0;
38f2fd
-
38f2fd
- cleanup:
38f2fd
-    virDomainAuditMemory(vm, oldmem, virDomainDefGetMemoryActual(vm->def),
38f2fd
-                         "update", ret == 0);
38f2fd
-
38f2fd
-    VIR_FREE(backendAlias);
38f2fd
-    return ret;
38f2fd
+    return 0;
38f2fd
 }
38f2fd
 
38f2fd
 
38f2fd
-- 
38f2fd
2.6.3
38f2fd