提交 d51a67b4 编写于 作者: L Luiz Capitulino

qapi: Convert human-monitor-command

Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 6106e249
......@@ -513,10 +513,10 @@ static int do_qmp_capabilities(Monitor *mon, const QDict *params,
static void handle_user_command(Monitor *mon, const char *cmdline);
static int do_hmp_passthrough(Monitor *mon, const QDict *params,
QObject **ret_data)
char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
int64_t cpu_index, Error **errp)
{
int ret = 0;
char *output = NULL;
Monitor *old_mon, hmp;
CharDriverState mchar;
......@@ -527,25 +527,30 @@ static int do_hmp_passthrough(Monitor *mon, const QDict *params,
old_mon = cur_mon;
cur_mon = &hmp;
if (qdict_haskey(params, "cpu-index")) {
ret = monitor_set_cpu(qdict_get_int(params, "cpu-index"));
if (has_cpu_index) {
int ret = monitor_set_cpu(cpu_index);
if (ret < 0) {
cur_mon = old_mon;
qerror_report(QERR_INVALID_PARAMETER_VALUE, "cpu-index", "a CPU number");
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
"a CPU number");
goto out;
}
}
handle_user_command(&hmp, qdict_get_str(params, "command-line"));
handle_user_command(&hmp, command_line);
cur_mon = old_mon;
if (qemu_chr_mem_osize(hmp.chr) > 0) {
*ret_data = QOBJECT(qemu_chr_mem_to_qs(hmp.chr));
QString *str = qemu_chr_mem_to_qs(hmp.chr);
output = g_strdup(qstring_get_str(str));
QDECREF(str);
} else {
output = g_strdup("");
}
out:
qemu_chr_close_mem(hmp.chr);
return ret;
return output;
}
static int compare_cmd(const char *name, const char *list)
......
......@@ -1099,3 +1099,31 @@
##
{ 'command': 'blockdev-snapshot-sync',
'data': { 'device': 'str', 'snapshot-file': 'str', '*format': 'str' } }
##
# @human-monitor-command:
#
# Execute a command on the human monitor and return the output.
#
# @command-line: the command to execute in the human monitor
#
# @cpu-index: #optional The CPU to use for commands that require an implicit CPU
#
# Returns: the output of the command as a string
#
# Since: 0.14.0
#
# Notes: This command only exists as a stop-gap. It's use is highly
# discouraged. The semantics of this command are not guaranteed.
#
# Known limitations:
#
# o This command is stateless, this means that commands that depend
# on state information (such as getfd) might not work
#
# o Commands that prompt the user for data (eg. 'cont' when the block
# device is encrypted) don't currently work
##
{ 'command': 'human-monitor-command',
'data': {'command-line': 'str', '*cpu-index': 'int'},
'returns': 'str' }
......@@ -970,10 +970,7 @@ EQMP
{
.name = "human-monitor-command",
.args_type = "command-line:s,cpu-index:i?",
.params = "",
.help = "",
.user_print = monitor_user_noop,
.mhandler.cmd_new = do_hmp_passthrough,
.mhandler.cmd_new = qmp_marshal_input_human_monitor_command,
},
SQMP
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册