qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH 7/9] qdev-monitor: Restructure and fix the check for command


From: Mirela Grujic
Subject: [RFC PATCH 7/9] qdev-monitor: Restructure and fix the check for command availability
Date: Thu, 13 May 2021 10:25:47 +0200

The existing code had to be restructured to make room for adding
checks that are specific to the machine phases.

The fix is related to the way that commands with the 'allow-preconfig'
option are treated.

Commands labelled with the 'allow-preconfig' option were meant to be allowed
during the 'preconfig' state, i.e. before the machine is initialized.
The equivalent of 'preconfig' state (after its removal) is machine init
phase MACHINE_INIT_PHASE_ACCEL_CREATED. Therefore, commands with
'allow-preconfig' option should be allowed to run while the machine is
in MACHINE_INIT_PHASE_ACCEL_CREATED phase.
Before this patch, those commands were allowed to run if the machine is
not ready, which includes three more phases besides the accel-created
phase. Since there were no means to enter other phases via QMP, the
implementation was fine. However, with the introduction of
'next-machine-phase' and 'advance-machine-phase' commands, one could
enter machine 'initialized' phase and still have available 'preconfig'
commands, which is incorrect.

This patch makes available 'allow-preconfig' commands only when they're
needed - before the machine is initialized, in the accel-created phase.
To enable a command after the machine gets initialized and before it
becomes ready, one should use 'allow-init-config' option that will be
introduced in the following patch.

Signed-off-by: Mirela Grujic <mirela.grujic@greensocs.com>
---
 softmmu/qdev-monitor.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index be8a892517..448f9dbb6f 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -998,10 +998,19 @@ int qemu_global_option(const char *str)
 
 bool qmp_command_available(const QmpCommand *cmd, Error **errp)
 {
-    if (!machine_is_ready() && !(cmd->options & QCO_ALLOW_PRECONFIG)) {
-        error_setg(errp, "The command '%s' is permitted only after machine 
initialization has completed",
-                   cmd->name);
-        return false;
+    switch (phase_get()) {
+    case MACHINE_INIT_PHASE_ACCEL_CREATED:
+        if (cmd->options & QCO_ALLOW_PRECONFIG) {
+            return true;
+        }
+        break;
+    case MACHINE_INIT_PHASE_READY:
+        /* All commands are available when the machine is ready */
+        return true;
+    default:
+        break;
     }
-    return true;
+    error_setg(errp, "The command '%s' is not permitted at this phase",
+               cmd->name);
+    return false;
 }
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]