monitor: Allow to exclude commands from QMP
Ported commands that are marked 'user_only' will not be considered for QMP monitor sessions. This allows to implement new commands that do not (yet) provide a sufficiently stable interface for QMP use. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
e4940c603a
commit
a6c4d36425
18
monitor.c
18
monitor.c
|
@ -333,6 +333,11 @@ static inline bool monitor_handler_is_async(const mon_cmd_t *cmd)
|
||||||
return cmd->flags & MONITOR_CMD_ASYNC;
|
return cmd->flags & MONITOR_CMD_ASYNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool monitor_cmd_user_only(const mon_cmd_t *cmd)
|
||||||
|
{
|
||||||
|
return (cmd->flags & MONITOR_CMD_USER_ONLY);
|
||||||
|
}
|
||||||
|
|
||||||
static inline int monitor_has_error(const Monitor *mon)
|
static inline int monitor_has_error(const Monitor *mon)
|
||||||
{
|
{
|
||||||
return mon->error != NULL;
|
return mon->error != NULL;
|
||||||
|
@ -615,6 +620,11 @@ static int do_info(Monitor *mon, const QDict *qdict, QObject **ret_data)
|
||||||
goto help;
|
goto help;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (monitor_ctrl_mode(mon) && monitor_cmd_user_only(cmd)) {
|
||||||
|
qerror_report(QERR_COMMAND_NOT_FOUND, item);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (monitor_handler_is_async(cmd)) {
|
if (monitor_handler_is_async(cmd)) {
|
||||||
if (monitor_ctrl_mode(mon)) {
|
if (monitor_ctrl_mode(mon)) {
|
||||||
qmp_async_info_handler(mon, cmd);
|
qmp_async_info_handler(mon, cmd);
|
||||||
|
@ -712,13 +722,14 @@ static void do_info_commands(Monitor *mon, QObject **ret_data)
|
||||||
cmd_list = qlist_new();
|
cmd_list = qlist_new();
|
||||||
|
|
||||||
for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
|
for (cmd = mon_cmds; cmd->name != NULL; cmd++) {
|
||||||
if (monitor_handler_ported(cmd) && !compare_cmd(cmd->name, "info")) {
|
if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd) &&
|
||||||
|
!compare_cmd(cmd->name, "info")) {
|
||||||
qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
|
qlist_append_obj(cmd_list, get_cmd_dict(cmd->name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (cmd = info_cmds; cmd->name != NULL; cmd++) {
|
for (cmd = info_cmds; cmd->name != NULL; cmd++) {
|
||||||
if (monitor_handler_ported(cmd)) {
|
if (monitor_handler_ported(cmd) && !monitor_cmd_user_only(cmd)) {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
snprintf(buf, sizeof(buf), "query-%s", cmd->name);
|
snprintf(buf, sizeof(buf), "query-%s", cmd->name);
|
||||||
qlist_append_obj(cmd_list, get_cmd_dict(buf));
|
qlist_append_obj(cmd_list, get_cmd_dict(buf));
|
||||||
|
@ -4271,7 +4282,8 @@ static void handle_qmp_command(JSONMessageParser *parser, QList *tokens)
|
||||||
qobject_from_jsonf("{ 'item': %s }", info_item));
|
qobject_from_jsonf("{ 'item': %s }", info_item));
|
||||||
} else {
|
} else {
|
||||||
cmd = monitor_find_command(cmd_name);
|
cmd = monitor_find_command(cmd_name);
|
||||||
if (!cmd || !monitor_handler_ported(cmd)) {
|
if (!cmd || !monitor_handler_ported(cmd)
|
||||||
|
|| monitor_cmd_user_only(cmd)) {
|
||||||
qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
|
qerror_report(QERR_COMMAND_NOT_FOUND, cmd_name);
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ extern Monitor *default_mon;
|
||||||
|
|
||||||
/* flags for monitor commands */
|
/* flags for monitor commands */
|
||||||
#define MONITOR_CMD_ASYNC 0x0001
|
#define MONITOR_CMD_ASYNC 0x0001
|
||||||
|
#define MONITOR_CMD_USER_ONLY 0x0002
|
||||||
|
|
||||||
/* QMP events */
|
/* QMP events */
|
||||||
typedef enum MonitorEvent {
|
typedef enum MonitorEvent {
|
||||||
|
|
Loading…
Reference in New Issue