No QMP poweroff if QMP not available.

This commit is contained in:
Michael Lipp 2025-03-12 20:59:36 +01:00
parent fae75dafa9
commit 36877666f3

View file

@ -199,7 +199,11 @@ public class QemuMonitor extends QemuConnector {
@Handler(priority = 100) @Handler(priority = 100)
@SuppressWarnings("PMD.AvoidSynchronizedStatement") @SuppressWarnings("PMD.AvoidSynchronizedStatement")
public void onStop(Stop event) { public void onStop(Stop event) {
if (qemuChannel() != null) { if (!monitorReady) {
logger.fine(() -> "No QMP connection,"
+ " cannot send powerdown command");
return;
}
// We have a connection to Qemu, attempt ACPI shutdown. // We have a connection to Qemu, attempt ACPI shutdown.
event.suspendHandling(); event.suspendHandling();
suspendedStop = event; suspendedStop = event;
@ -208,7 +212,7 @@ public class QemuMonitor extends QemuConnector {
// "hanging" qemu process. // "hanging" qemu process.
powerdownTimer = Components.schedule(t -> { powerdownTimer = Components.schedule(t -> {
// Powerdown not confirmed // Powerdown not confirmed
logger.fine(() -> "QMP powerdown command has not effect."); logger.fine(() -> "QMP powerdown command not confirmed");
synchronized (this) { synchronized (this) {
powerdownTimer = null; powerdownTimer = null;
if (suspendedStop != null) { if (suspendedStop != null) {
@ -221,7 +225,6 @@ public class QemuMonitor extends QemuConnector {
powerdownStartedAt = Instant.now(); powerdownStartedAt = Instant.now();
fire(new MonitorCommand(new QmpPowerdown())); fire(new MonitorCommand(new QmpPowerdown()));
} }
}
/** /**
* On powerdown event. * On powerdown event.
@ -238,7 +241,9 @@ public class QemuMonitor extends QemuConnector {
} }
// (Re-)schedule timer as fallback // (Re-)schedule timer as fallback
logger.fine(() -> "QMP powerdown confirmed, waiting..."); var waitUntil = powerdownStartedAt.plusSeconds(powerdownTimeout);
logger.fine(() -> "QMP powerdown confirmed, waiting for"
+ " termination until " + waitUntil);
powerdownTimer = Components.schedule(t -> { powerdownTimer = Components.schedule(t -> {
logger.fine(() -> "Powerdown timeout reached."); logger.fine(() -> "Powerdown timeout reached.");
synchronized (this) { synchronized (this) {
@ -247,7 +252,7 @@ public class QemuMonitor extends QemuConnector {
suspendedStop = null; suspendedStop = null;
} }
} }
}, powerdownStartedAt.plusSeconds(powerdownTimeout)); }, waitUntil);
powerdownConfirmed = true; powerdownConfirmed = true;
} }
} }