From 1aecb82843fa4430013075e0c0e840f009b9e161 Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Sat, 16 Sep 2023 13:20:42 +0200 Subject: [PATCH] Delay QEMU configuration until QMP is configured. Fixes #4. --- .../vmoperator/runner/qemu/Runner.java | 12 ++++--- .../runner/qemu/events/MonitorResult.java | 4 +++ .../runner/qemu/events/QmpConfigured.java | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/QmpConfigured.java diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java index 6ca3b2c..3ace2e5 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java @@ -52,7 +52,7 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont; import org.jdrupes.vmoperator.runner.qemu.events.MonitorCommand; -import org.jdrupes.vmoperator.runner.qemu.events.MonitorReady; +import org.jdrupes.vmoperator.runner.qemu.events.QmpConfigured; import org.jdrupes.vmoperator.runner.qemu.events.RunnerConfigurationUpdate; import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange; import org.jdrupes.vmoperator.runner.qemu.events.RunnerStateChange.State; @@ -111,7 +111,8 @@ import org.jgrapes.util.events.WatchFile; * state "Start swtpm" as swtpm * state "Start qemu" as qemu * state "Open monitor" as monitor - * state "Configure" as configure + * state "Configure QMP" as waitForConfigured + * state "Configure QEMU" as configure * state success <> * state error <> * @@ -125,8 +126,11 @@ import org.jgrapes.util.events.WatchFile; * qemu --> monitor : FileChanged[monitor socket created] * * monitor: entry/fire OpenSocketConnection - * monitor --> configure: ClientConnected[for monitor] + * monitor --> waitForConfigured: ClientConnected[for monitor] * monitor -> error: ConnectError[for monitor] + * + * waitForConfigured: entry/fire QmpCapabilities + * waitForConfigured --> configure: QmpConfigured * * configure: entry/fire RunnerConfigurationUpdate * configure --> success: RunnerConfigurationUpdate (last handler)/fire cont command @@ -511,7 +515,7 @@ public class Runner extends Component { * @param event the event */ @Handler - public void onMonitorReady(MonitorReady event) { + public void onQmpConfigured(QmpConfigured event) { rep.fire(new RunnerConfigurationUpdate(config, state)); } diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java index 83295dd..c0f55fe 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/MonitorResult.java @@ -21,6 +21,7 @@ package org.jdrupes.vmoperator.runner.qemu.events; import com.fasterxml.jackson.databind.JsonNode; import java.util.Optional; import org.jdrupes.vmoperator.runner.qemu.commands.QmpAddCpu; +import org.jdrupes.vmoperator.runner.qemu.commands.QmpCapabilities; import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand; import org.jdrupes.vmoperator.runner.qemu.commands.QmpDelCpu; import org.jdrupes.vmoperator.runner.qemu.commands.QmpQueryHotpluggableCpus; @@ -44,6 +45,9 @@ public class MonitorResult extends Event { * @return the monitor result */ public static MonitorResult from(QmpCommand command, JsonNode response) { + if (command instanceof QmpCapabilities) { + return new QmpConfigured(command, response); + } if (command instanceof QmpQueryHotpluggableCpus) { return new HotpluggableCpuStatus(command, response); } diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/QmpConfigured.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/QmpConfigured.java new file mode 100644 index 0000000..918177b --- /dev/null +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/events/QmpConfigured.java @@ -0,0 +1,36 @@ +/* + * VM-Operator + * Copyright (C) 2023 Michael N. Lipp + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.jdrupes.vmoperator.runner.qemu.events; + +import com.fasterxml.jackson.databind.JsonNode; +import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand; + +/** + * Signals that the QMP capabilities have been enabled. + */ +public class QmpConfigured extends MonitorResult { + + /** + * Instantiates a new monitor ready. + */ + public QmpConfigured(QmpCommand command, JsonNode response) { + super(command, response); + } + +}