mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
qemu: Emit correct audit message for memory hot plug
https://bugzilla.redhat.com/show_bug.cgi?id=1226234#c3 Prior to this patch, after successfully hot plugging memory the audit log indicated that the update failed, e.g.: type=VIRT_RESOURCE ... old-mem=1024000 new-mem=1548288 \ exe="/usr/sbin/libvirtd" hostname=? addr=? terminal=pts/2 res=failed This patch will adjust where virDomainAuditMemory is called to ensure the proper 'ret' value is used based on success or failure. Additionally, the audit message should include the size of the memory we were attempting to change to rather than the current actual size. On failure to add, the message showed the same value for old-mem and new-mem. In order to do this, introduce a 'newmem' local which will compute the new size based on the oldmem size plus the size of memory we are about to add. NB: This would be the same as calling the virDomainDefGetMemoryActual again on success, but avoids the overhead of recalculating. Plus cur_balloon is already adjusted by the same value, so this follows that. Signed-off-by: Luyao Huang <lhuang@redhat.com>
This commit is contained in:
parent
6f2a0198e9
commit
cb1fbda4a1
@ -1756,6 +1756,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
|
unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
|
||||||
|
unsigned long long newmem = oldmem + mem->size;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
char *objalias = NULL;
|
char *objalias = NULL;
|
||||||
const char *backendType;
|
const char *backendType;
|
||||||
@ -1811,7 +1812,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
||||||
/* we shouldn't touch mem now, as the def might be freed */
|
/* we shouldn't touch mem now, as the def might be freed */
|
||||||
mem = NULL;
|
mem = NULL;
|
||||||
goto cleanup;
|
goto audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
event = virDomainEventDeviceAddedNewFromObj(vm, objalias);
|
event = virDomainEventDeviceAddedNewFromObj(vm, objalias);
|
||||||
@ -1822,9 +1823,6 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
if (fix_balloon)
|
if (fix_balloon)
|
||||||
vm->def->mem.cur_balloon += mem->size;
|
vm->def->mem.cur_balloon += mem->size;
|
||||||
|
|
||||||
virDomainAuditMemory(vm, oldmem, virDomainDefGetMemoryActual(vm->def),
|
|
||||||
"update", ret == 0);
|
|
||||||
|
|
||||||
/* mem is consumed by vm->def */
|
/* mem is consumed by vm->def */
|
||||||
mem = NULL;
|
mem = NULL;
|
||||||
|
|
||||||
@ -1834,6 +1832,8 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
audit:
|
||||||
|
virDomainAuditMemory(vm, oldmem, newmem, "update", ret == 0);
|
||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
@ -1844,7 +1844,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
removedef:
|
removedef:
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
|
||||||
mem = NULL;
|
mem = NULL;
|
||||||
goto cleanup;
|
goto audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((id = virDomainMemoryFindByDef(vm->def, mem)) >= 0)
|
if ((id = virDomainMemoryFindByDef(vm->def, mem)) >= 0)
|
||||||
@ -1852,7 +1852,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
|
|||||||
else
|
else
|
||||||
mem = NULL;
|
mem = NULL;
|
||||||
|
|
||||||
goto cleanup;
|
goto audit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user