38f2fd
From 5d51d05823e8cb75b452f86c854d0d404d21503e Mon Sep 17 00:00:00 2001
38f2fd
Message-Id: <5d51d05823e8cb75b452f86c854d0d404d21503e@dist-git>
38f2fd
From: Luyao Huang <lhuang@redhat.com>
38f2fd
Date: Thu, 12 Nov 2015 08:40:41 +0100
38f2fd
Subject: [PATCH] qemu: Emit correct audit message for memory hot plug
38f2fd
38f2fd
https://bugzilla.redhat.com/show_bug.cgi?id=1280420
38f2fd
https://bugzilla.redhat.com/show_bug.cgi?id=1226234#c3
38f2fd
38f2fd
Prior to this patch, after successfully hot plugging memory
38f2fd
the audit log indicated that the update failed, e.g.:
38f2fd
38f2fd
type=VIRT_RESOURCE ... old-mem=1024000 new-mem=1548288 \
38f2fd
exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=pts/2 res=failed
38f2fd
38f2fd
This patch will adjust where virDomainAuditMemory is called to
38f2fd
ensure the proper 'ret' value is used based on success or failure.
38f2fd
38f2fd
Additionally, the audit message should include the size of the
38f2fd
memory we were attempting to change to rather than the current
38f2fd
actual size. On failure to add, the message showed the same value
38f2fd
for old-mem and new-mem.
38f2fd
38f2fd
In order to do this, introduce a 'newmem' local which will compute
38f2fd
the new size based on the oldmem size plus the size of memory we
38f2fd
are about to add. NB: This would be the same as calling the
38f2fd
virDomainDefGetMemoryActual again on success, but avoids the
38f2fd
overhead of recalculating. Plus cur_balloon is already adjusted
38f2fd
by the same value, so this follows that.
38f2fd
38f2fd
Signed-off-by: Luyao Huang <lhuang@redhat.com>
38f2fd
(cherry picked from commit cb1fbda4a1b23581ed9e305a48b0376633d5ff4a)
38f2fd
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
38f2fd
---
38f2fd
 src/qemu/qemu_hotplug.c | 12 ++++++------
38f2fd
 1 file changed, 6 insertions(+), 6 deletions(-)
38f2fd
38f2fd
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
38f2fd
index aa1fb31..bd96abf 100644
38f2fd
--- a/src/qemu/qemu_hotplug.c
38f2fd
+++ b/src/qemu/qemu_hotplug.c
38f2fd
@@ -1774,6 +1774,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
     qemuDomainObjPrivatePtr priv = vm->privateData;
38f2fd
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
38f2fd
     unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
38f2fd
+    unsigned long long newmem = oldmem + mem->size;
38f2fd
     char *devstr = NULL;
38f2fd
     char *objalias = NULL;
38f2fd
     const char *backendType;
38f2fd
@@ -1829,7 +1830,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
38f2fd
         /* we shouldn't touch mem now, as the def might be freed */
38f2fd
         mem = NULL;
38f2fd
-        goto cleanup;
38f2fd
+        goto audit;
38f2fd
     }
38f2fd
 
38f2fd
     event = virDomainEventDeviceAddedNewFromObj(vm, objalias);
38f2fd
@@ -1840,9 +1841,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
     if (fix_balloon)
38f2fd
         vm->def->mem.cur_balloon += mem->size;
38f2fd
 
38f2fd
-    virDomainAuditMemory(vm, oldmem, virDomainDefGetMemoryActual(vm->def),
38f2fd
-                         "update", ret == 0);
38f2fd
-
38f2fd
     /* mem is consumed by vm->def */
38f2fd
     mem = NULL;
38f2fd
 
38f2fd
@@ -1852,6 +1850,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
 
38f2fd
     ret = 0;
38f2fd
 
38f2fd
+ audit:
38f2fd
+    virDomainAuditMemory(vm, oldmem, newmem, "update", ret == 0);
38f2fd
  cleanup:
38f2fd
     virObjectUnref(cfg);
38f2fd
     VIR_FREE(devstr);
38f2fd
@@ -1862,7 +1862,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
  removedef:
38f2fd
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
38f2fd
         mem = NULL;
38f2fd
-        goto cleanup;
38f2fd
+        goto audit;
38f2fd
     }
38f2fd
 
38f2fd
     if ((id = virDomainMemoryFindByDef(vm->def, mem)) >= 0)
38f2fd
@@ -1870,7 +1870,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
38f2fd
     else
38f2fd
         mem = NULL;
38f2fd
 
38f2fd
-    goto cleanup;
38f2fd
+    goto audit;
38f2fd
 }
38f2fd
 
38f2fd
 
38f2fd
-- 
38f2fd
2.6.3
38f2fd