qemu-devel
[Top][All Lists]
Advanced

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

[PATCH v2] qga: return a more explicit error on why a command is disable


From: marcandre . lureau
Subject: [PATCH v2] qga: return a more explicit error on why a command is disabled
Date: Wed, 17 Feb 2021 11:09:44 +0400

From: Marc-André Lureau <marcandre.lureau@redhat.com>

qmp_disable_command() now takes an enum for the reason, to be able
to give more explicit error messages.

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1928806

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---

v2:
 - replace string with an enum for disabling reason
 - remove trailing dot

 include/qapi/qmp/dispatch.h | 12 ++++++++++--
 monitor/qmp-cmds-control.c  |  2 +-
 qapi/qmp-dispatch.c         | 10 +++++++++-
 qapi/qmp-registry.c         | 16 +++++++++-------
 qga/main.c                  |  4 ++--
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h
index 1486cac3ef..fda9ffad73 100644
--- a/include/qapi/qmp/dispatch.h
+++ b/include/qapi/qmp/dispatch.h
@@ -28,6 +28,13 @@ typedef enum QmpCommandOptions
     QCO_COROUTINE             =  (1U << 3),
 } QmpCommandOptions;
 
+typedef enum QmpDisabled
+{
+    QMP_DISABLED_NONE,
+    QMP_DISABLED_GENERIC,
+    QMP_DISABLED_FROZEN,
+} QmpDisabled;
+
 typedef struct QmpCommand
 {
     const char *name;
@@ -35,7 +42,7 @@ typedef struct QmpCommand
     QmpCommandFunc *fn;
     QmpCommandOptions options;
     QTAILQ_ENTRY(QmpCommand) node;
-    bool enabled;
+    QmpDisabled disabled;
 } QmpCommand;
 
 typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList;
@@ -44,7 +51,8 @@ void qmp_register_command(QmpCommandList *cmds, const char 
*name,
                           QmpCommandFunc *fn, QmpCommandOptions options);
 const QmpCommand *qmp_find_command(const QmpCommandList *cmds,
                                    const char *name);
-void qmp_disable_command(QmpCommandList *cmds, const char *name);
+void qmp_disable_command(QmpCommandList *cmds, const char *name,
+                         QmpDisabled disabled);
 void qmp_enable_command(QmpCommandList *cmds, const char *name);
 
 bool qmp_command_is_enabled(const QmpCommand *cmd);
diff --git a/monitor/qmp-cmds-control.c b/monitor/qmp-cmds-control.c
index 509ae870bd..94a8e133b6 100644
--- a/monitor/qmp-cmds-control.c
+++ b/monitor/qmp-cmds-control.c
@@ -107,7 +107,7 @@ static void query_commands_cb(const QmpCommand *cmd, void 
*opaque)
     CommandInfo *info;
     CommandInfoList **list = opaque;
 
-    if (!cmd->enabled) {
+    if (!qmp_command_is_enabled(cmd)) {
         return;
     }
 
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 0a2b20a4e4..b65f670152 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -155,11 +155,19 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject 
*request,
                   "The command %s has not been found", command);
         goto out;
     }
-    if (!cmd->enabled) {
+    switch (cmd->disabled) {
+    case QMP_DISABLED_FROZEN:
+        error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
+                  "The command %s has been disabled after fsfreeze",
+                  command);
+        goto out;
+    case QMP_DISABLED_GENERIC:
         error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
                   "The command %s has been disabled for this instance",
                   command);
         goto out;
+    case QMP_DISABLED_NONE:
+        break;
     }
     if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
         error_setg(&err, "The command %s does not support OOB",
diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c
index 58c65b5052..e39e3b449c 100644
--- a/qapi/qmp-registry.c
+++ b/qapi/qmp-registry.c
@@ -25,7 +25,7 @@ void qmp_register_command(QmpCommandList *cmds, const char 
*name,
 
     cmd->name = name;
     cmd->fn = fn;
-    cmd->enabled = true;
+    cmd->disabled = QMP_DISABLED_NONE;
     cmd->options = options;
     QTAILQ_INSERT_TAIL(cmds, cmd, node);
 }
@@ -43,31 +43,33 @@ const QmpCommand *qmp_find_command(const QmpCommandList 
*cmds, const char *name)
 }
 
 static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
-                               bool enabled)
+                               QmpDisabled disabled)
 {
     QmpCommand *cmd;
 
     QTAILQ_FOREACH(cmd, cmds, node) {
         if (strcmp(cmd->name, name) == 0) {
-            cmd->enabled = enabled;
+            cmd->disabled = disabled;
             return;
         }
     }
 }
 
-void qmp_disable_command(QmpCommandList *cmds, const char *name)
+void qmp_disable_command(QmpCommandList *cmds, const char *name,
+                         QmpDisabled disabled)
 {
-    qmp_toggle_command(cmds, name, false);
+    assert(disabled != QMP_DISABLED_NONE);
+    qmp_toggle_command(cmds, name, disabled);
 }
 
 void qmp_enable_command(QmpCommandList *cmds, const char *name)
 {
-    qmp_toggle_command(cmds, name, true);
+    qmp_toggle_command(cmds, name, QMP_DISABLED_NONE);
 }
 
 bool qmp_command_is_enabled(const QmpCommand *cmd)
 {
-    return cmd->enabled;
+    return cmd->disabled != QMP_DISABLED_NONE;
 }
 
 const char *qmp_command_name(const QmpCommand *cmd)
diff --git a/qga/main.c b/qga/main.c
index e7f8f3b161..0dbf0cacd2 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -375,7 +375,7 @@ static void ga_disable_non_whitelisted(const QmpCommand 
*cmd, void *opaque)
     }
     if (!whitelisted) {
         g_debug("disabling command: %s", name);
-        qmp_disable_command(&ga_commands, name);
+        qmp_disable_command(&ga_commands, name, QMP_DISABLED_FROZEN);
     }
 }
 
@@ -1329,7 +1329,7 @@ static GAState *initialize_agent(GAConfig *config, int 
socket_activation)
         s->blacklist = config->blacklist;
         do {
             g_debug("disabling command: %s", (char *)l->data);
-            qmp_disable_command(&ga_commands, l->data);
+            qmp_disable_command(&ga_commands, l->data, QMP_DISABLED_GENERIC);
             l = g_list_next(l);
         } while (l);
     }
-- 
2.29.0




reply via email to

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