mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 23:25:24 +00:00
qemu: Emit correct audit message for memory hot unplug
https://bugzilla.redhat.com/show_bug.cgi?id=1226234#c3
If the qemu monitor fails to remove the memory from the guest for
any reason, the auditlog message will incorrectly use the current
actual memory (via virDomainDefGetMemoryActual) instead of the
value we were attempting to reduce to. The result is the 'new-mem'
and 'old-mem' values for the auditlog message would be identical.
This patch creates a local 'newmem' which accounts for the current
memory size minus the memory which is being removed. NB, for the
success case this results in the same value that would be returned
by virDomainDefGetMemoryActual without the need to do the math. This
follows the existing code which would subtract the size for cur_balloon.
Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit 8f8031df19
)
This commit is contained in:
parent
fec2c786e7
commit
affa75e640
@ -2912,11 +2912,11 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
|
|||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
|
unsigned long long oldmem = virDomainDefGetMemoryActual(vm->def);
|
||||||
|
unsigned long long newmem = oldmem - mem->size;
|
||||||
virObjectEventPtr event;
|
virObjectEventPtr event;
|
||||||
char *backendAlias = NULL;
|
char *backendAlias = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
int idx;
|
int idx;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
VIR_DEBUG("Removing memory device %s from domain %p %s",
|
VIR_DEBUG("Removing memory device %s from domain %p %s",
|
||||||
mem->info.alias, vm, vm->def->name);
|
mem->info.alias, vm, vm->def->name);
|
||||||
@ -2925,12 +2925,18 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
|
|||||||
qemuDomainEventQueue(driver, event);
|
qemuDomainEventQueue(driver, event);
|
||||||
|
|
||||||
if (virAsprintf(&backendAlias, "mem%s", mem->info.alias) < 0)
|
if (virAsprintf(&backendAlias, "mem%s", mem->info.alias) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
rc = qemuMonitorDelObject(priv->mon, backendAlias);
|
rc = qemuMonitorDelObject(priv->mon, backendAlias);
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto cleanup;
|
rc = -1;
|
||||||
|
|
||||||
|
VIR_FREE(backendAlias);
|
||||||
|
|
||||||
|
virDomainAuditMemory(vm, oldmem, newmem, "update", rc == 0);
|
||||||
|
if (rc < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
vm->def->mem.cur_balloon -= mem->size;
|
vm->def->mem.cur_balloon -= mem->size;
|
||||||
|
|
||||||
@ -2938,14 +2944,7 @@ qemuDomainRemoveMemoryDevice(virQEMUDriverPtr driver,
|
|||||||
virDomainMemoryRemove(vm->def, idx);
|
virDomainMemoryRemove(vm->def, idx);
|
||||||
|
|
||||||
virDomainMemoryDefFree(mem);
|
virDomainMemoryDefFree(mem);
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virDomainAuditMemory(vm, oldmem, virDomainDefGetMemoryActual(vm->def),
|
|
||||||
"update", ret == 0);
|
|
||||||
|
|
||||||
VIR_FREE(backendAlias);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user