[PATCH v2 0/2] qemu: Ignore RESET/SHUTDOWN events during startup

Before we resume the CPUs there was no guest code executed so the events emitted by qemu are purely based on libvirt actions. Ignore them since they are emitted when we are resetting the machine so that it picks up hotplugged disks. Peter Krempa (2): qemu: process: Ignore 'RESET' event during startup qemu: process: Ignore 'SHUTDOWN' event during startup src/qemu/qemu_process.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) -- 2.31.1

In cases when we are adding a <transient/> disk with sharing backend (and thus hotplugging it) we need to re-initialize ACPI tables so that the VM boots from the correct device. This has a side-effect of emitting the RESET event and handling it which in case when the 'on_reset' policy is set leads to an attempt to obtain a domain job lock which is already held and needing to wait for a timeout. Fix this by ignoring RESET events during startup of the VM. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 521fda57da..f8581fa462 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -429,12 +429,24 @@ qemuProcessHandleReset(qemuMonitor *mon G_GNUC_UNUSED, void *opaque) { virQEMUDriver *driver = opaque; - virObjectEvent *event; + virObjectEvent *event = NULL; qemuDomainObjPrivate *priv; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + virDomainState state; + int reason; virObjectLock(vm); + state = virDomainObjGetState(vm, &reason); + + /* ignore reset events on VM startup. Libvirt in certain instances does a + * reset during startup so that the ACPI tables are re-generated */ + if (state == VIR_DOMAIN_PAUSED && + reason == VIR_DOMAIN_PAUSED_STARTING_UP) { + VIR_DEBUG("ignoring reset event during startup"); + goto cleanup; + } + event = virDomainEventRebootNewFromObj(vm); priv = vm->privateData; if (priv->agent) -- 2.31.1

In cases when we are adding a <transient/> disk with sharing backend (and thus hotplugging it) we need to re-initialize ACPI tables so that the VM boots from the correct device. In case of 'aarch64' this has a side-effect of emitting the SHUTDOWN event with a 'host-qmp-system-reset' reason instead of a RESET event which can lead to killing of the qemu process on startup. Fix this by ignoring SHUTDOWN events during startup of the VM. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f8581fa462..ace413fbdf 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -612,14 +612,18 @@ qemuProcessHandleShutdown(qemuMonitor *mon G_GNUC_UNUSED, qemuDomainObjPrivate *priv; virObjectEvent *event = NULL; g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + virDomainState state; + int reason; int detail = 0; VIR_DEBUG("vm=%p", vm); virObjectLock(vm); + state = virDomainObjGetState(vm, &reason); + priv = vm->privateData; - if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_SHUTDOWN) { + if (state == VIR_DOMAIN_SHUTDOWN) { VIR_DEBUG("Ignoring repeated SHUTDOWN event from domain %s", vm->def->name); goto unlock; @@ -627,6 +631,13 @@ qemuProcessHandleShutdown(qemuMonitor *mon G_GNUC_UNUSED, VIR_DEBUG("Ignoring SHUTDOWN event from inactive domain %s", vm->def->name); goto unlock; + } else if (state == VIR_DOMAIN_PAUSED && + reason == VIR_DOMAIN_PAUSED_STARTING_UP) { + /* aarch64 emits a SHUTDOWN instead of a reset when 'system_reset' is + * invoked during startup. In certain cases we force a reset during + * startup so that firmware picks up hotplugged devices */ + VIR_DEBUG("ignoring shutdown event during startup"); + goto unlock; } /* In case of fake reboot qemu shutdown state is transient so don't -- 2.31.1

On a %A in %Y, Peter Krempa wrote:
Before we resume the CPUs there was no guest code executed so the events emitted by qemu are purely based on libvirt actions. Ignore them since they are emitted when we are resetting the machine so that it picks up hotplugged disks.
Peter Krempa (2): qemu: process: Ignore 'RESET' event during startup qemu: process: Ignore 'SHUTDOWN' event during startup
src/qemu/qemu_process.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Jano Tomko
-
Peter Krempa