Skip to content

Commit c98939d

Browse files
elmarcomdroth
authored andcommitted
qga: return a more explicit error on why a command is disabled
qmp_disable_command() now takes an optional error string to return a more explicit error message. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1928806 Signed-off-by: Marc-André Lureau <[email protected]> *fix up 80+ char line Signed-off-by: Michael Roth <[email protected]>
1 parent 86dc17d commit c98939d

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

include/qapi/qmp/dispatch.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ typedef struct QmpCommand
3636
QmpCommandOptions options;
3737
QTAILQ_ENTRY(QmpCommand) node;
3838
bool enabled;
39+
const char *disable_reason;
3940
} QmpCommand;
4041

4142
typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList;
@@ -44,7 +45,8 @@ void qmp_register_command(QmpCommandList *cmds, const char *name,
4445
QmpCommandFunc *fn, QmpCommandOptions options);
4546
const QmpCommand *qmp_find_command(const QmpCommandList *cmds,
4647
const char *name);
47-
void qmp_disable_command(QmpCommandList *cmds, const char *name);
48+
void qmp_disable_command(QmpCommandList *cmds, const char *name,
49+
const char *err_msg);
4850
void qmp_enable_command(QmpCommandList *cmds, const char *name);
4951

5052
bool qmp_command_is_enabled(const QmpCommand *cmd);

qapi/qmp-dispatch.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,10 @@ QDict *qmp_dispatch(const QmpCommandList *cmds, QObject *request,
157157
}
158158
if (!cmd->enabled) {
159159
error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
160-
"The command %s has been disabled for this instance",
161-
command);
160+
"Command %s has been disabled%s%s",
161+
command,
162+
cmd->disable_reason ? ": " : "",
163+
cmd->disable_reason ?: "");
162164
goto out;
163165
}
164166
if (oob && !(cmd->options & QCO_ALLOW_OOB)) {

qapi/qmp-registry.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,28 @@ const QmpCommand *qmp_find_command(const QmpCommandList *cmds, const char *name)
4343
}
4444

4545
static void qmp_toggle_command(QmpCommandList *cmds, const char *name,
46-
bool enabled)
46+
bool enabled, const char *disable_reason)
4747
{
4848
QmpCommand *cmd;
4949

5050
QTAILQ_FOREACH(cmd, cmds, node) {
5151
if (strcmp(cmd->name, name) == 0) {
5252
cmd->enabled = enabled;
53+
cmd->disable_reason = disable_reason;
5354
return;
5455
}
5556
}
5657
}
5758

58-
void qmp_disable_command(QmpCommandList *cmds, const char *name)
59+
void qmp_disable_command(QmpCommandList *cmds, const char *name,
60+
const char *disable_reason)
5961
{
60-
qmp_toggle_command(cmds, name, false);
62+
qmp_toggle_command(cmds, name, false, disable_reason);
6163
}
6264

6365
void qmp_enable_command(QmpCommandList *cmds, const char *name)
6466
{
65-
qmp_toggle_command(cmds, name, true);
67+
qmp_toggle_command(cmds, name, true, NULL);
6668
}
6769

6870
bool qmp_command_is_enabled(const QmpCommand *cmd)

qga/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static void ga_disable_non_whitelisted(const QmpCommand *cmd, void *opaque)
375375
}
376376
if (!whitelisted) {
377377
g_debug("disabling command: %s", name);
378-
qmp_disable_command(&ga_commands, name);
378+
qmp_disable_command(&ga_commands, name, "the agent is in frozen state");
379379
}
380380
}
381381

@@ -1328,7 +1328,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
13281328
s->blacklist = config->blacklist;
13291329
do {
13301330
g_debug("disabling command: %s", (char *)l->data);
1331-
qmp_disable_command(&ga_commands, l->data);
1331+
qmp_disable_command(&ga_commands, l->data, NULL);
13321332
l = g_list_next(l);
13331333
} while (l);
13341334
}

0 commit comments

Comments
 (0)