2011-07-19 21:50:37 +02:00
|
|
|
/*
|
|
|
|
* Core Definitions for QAPI/QMP Dispatch
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2011
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
|
|
|
* See the COPYING.LIB file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-01-29 18:49:57 +01:00
|
|
|
#include "qemu/osdep.h"
|
2020-10-05 17:58:50 +02:00
|
|
|
|
|
|
|
#include "block/aio.h"
|
2021-03-18 16:55:10 +01:00
|
|
|
#include "qapi/compat-policy.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 18:19:43 +01:00
|
|
|
#include "qapi/qmp/dispatch.h"
|
2018-02-01 12:18:39 +01:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2016-06-09 18:48:32 +02:00
|
|
|
#include "qapi/qmp/qjson.h"
|
2021-03-18 16:55:18 +01:00
|
|
|
#include "qapi/qobject-input-visitor.h"
|
qapi: Implement deprecated-output=hide for QMP command results
This policy suppresses deprecated bits in output, and thus permits
"testing the future". Implement it for QMP command results. Example:
when QEMU is run with -compat deprecated-output=hide, then
{"execute": "query-cpus-fast"}
yields
{"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
instead of
{"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
Note the suppression of deprecated member "arch".
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210318155519.1224118-4-armbru@redhat.com>
2021-03-18 16:55:11 +01:00
|
|
|
#include "qapi/qobject-output-visitor.h"
|
2018-03-11 03:38:05 +01:00
|
|
|
#include "qapi/qmp/qbool.h"
|
2020-10-05 17:58:50 +02:00
|
|
|
#include "qemu/coroutine.h"
|
|
|
|
#include "qemu/main-loop.h"
|
2011-07-19 21:50:37 +02:00
|
|
|
|
2021-03-18 16:55:18 +01:00
|
|
|
Visitor *qobject_input_visitor_new_qmp(QObject *obj)
|
|
|
|
{
|
|
|
|
Visitor *v = qobject_input_visitor_new(obj);
|
|
|
|
|
2021-10-25 06:24:03 +02:00
|
|
|
visit_set_policy(v, &compat_policy);
|
2021-03-18 16:55:18 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
qapi: Implement deprecated-output=hide for QMP command results
This policy suppresses deprecated bits in output, and thus permits
"testing the future". Implement it for QMP command results. Example:
when QEMU is run with -compat deprecated-output=hide, then
{"execute": "query-cpus-fast"}
yields
{"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
instead of
{"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
Note the suppression of deprecated member "arch".
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210318155519.1224118-4-armbru@redhat.com>
2021-03-18 16:55:11 +01:00
|
|
|
Visitor *qobject_output_visitor_new_qmp(QObject **result)
|
|
|
|
{
|
|
|
|
Visitor *v = qobject_output_visitor_new(result);
|
|
|
|
|
2021-10-25 06:24:03 +02:00
|
|
|
visit_set_policy(v, &compat_policy);
|
qapi: Implement deprecated-output=hide for QMP command results
This policy suppresses deprecated bits in output, and thus permits
"testing the future". Implement it for QMP command results. Example:
when QEMU is run with -compat deprecated-output=hide, then
{"execute": "query-cpus-fast"}
yields
{"return": [{"thread-id": 9805, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
instead of
{"return": [{"arch": "x86", "thread-id": 22436, "props": {"core-id": 0, "thread-id": 0, "socket-id": 0}, "qom-path": "/machine/unattached/device[0]", "cpu-index": 0, "target": "x86_64"}]}
Note the suppression of deprecated member "arch".
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20210318155519.1224118-4-armbru@redhat.com>
2021-03-18 16:55:11 +01:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2020-03-17 12:54:48 +01:00
|
|
|
static QDict *qmp_dispatch_check_obj(QDict *dict, bool allow_oob,
|
2018-07-03 10:53:43 +02:00
|
|
|
Error **errp)
|
2011-07-19 21:50:37 +02:00
|
|
|
{
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
const char *exec_key = NULL;
|
2011-07-19 21:50:37 +02:00
|
|
|
const QDictEntry *ent;
|
|
|
|
const char *arg_name;
|
|
|
|
const QObject *arg_obj;
|
|
|
|
|
|
|
|
for (ent = qdict_first(dict); ent;
|
|
|
|
ent = qdict_next(dict, ent)) {
|
|
|
|
arg_name = qdict_entry_key(ent);
|
|
|
|
arg_obj = qdict_entry_value(ent);
|
|
|
|
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
if (!strcmp(arg_name, "execute")
|
|
|
|
|| (!strcmp(arg_name, "exec-oob") && allow_oob)) {
|
2011-07-19 21:50:37 +02:00
|
|
|
if (qobject_type(arg_obj) != QTYPE_QSTRING) {
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
error_setg(errp, "QMP input member '%s' must be a string",
|
|
|
|
arg_name);
|
2011-07-19 21:50:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
if (exec_key) {
|
|
|
|
error_setg(errp, "QMP input member '%s' clashes with '%s'",
|
|
|
|
arg_name, exec_key);
|
2017-03-03 13:32:21 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
exec_key = arg_name;
|
|
|
|
} else if (!strcmp(arg_name, "arguments")) {
|
2018-03-11 03:38:05 +01:00
|
|
|
if (qobject_type(arg_obj) != QTYPE_QDICT) {
|
|
|
|
error_setg(errp,
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
"QMP input member 'arguments' must be an object");
|
2018-03-11 03:38:05 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-02-20 16:42:53 +01:00
|
|
|
} else if (!strcmp(arg_name, "id")) {
|
|
|
|
continue;
|
2017-03-03 13:32:21 +01:00
|
|
|
} else {
|
2017-04-27 10:41:23 +02:00
|
|
|
error_setg(errp, "QMP input member '%s' is unexpected",
|
2017-03-03 13:32:29 +01:00
|
|
|
arg_name);
|
2011-07-19 21:50:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
if (!exec_key) {
|
2017-04-27 10:41:23 +02:00
|
|
|
error_setg(errp, "QMP input lacks member 'execute'");
|
2011-07-19 21:50:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2020-03-17 12:54:46 +01:00
|
|
|
QDict *qmp_error_response(Error *err)
|
|
|
|
{
|
|
|
|
QDict *rsp;
|
|
|
|
|
|
|
|
rsp = qdict_from_jsonf_nofail("{ 'error': { 'class': %s, 'desc': %s } }",
|
|
|
|
QapiErrorClass_str(error_get_class(err)),
|
|
|
|
error_get_pretty(err));
|
|
|
|
error_free(err);
|
|
|
|
return rsp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Does @qdict look like a command to be run out-of-band?
|
|
|
|
*/
|
|
|
|
bool qmp_is_oob(const QDict *dict)
|
2011-07-19 21:50:37 +02:00
|
|
|
{
|
2020-03-17 12:54:46 +01:00
|
|
|
return qdict_haskey(dict, "exec-oob")
|
|
|
|
&& !qdict_haskey(dict, "execute");
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:58:50 +02:00
|
|
|
typedef struct QmpDispatchBH {
|
|
|
|
const QmpCommand *cmd;
|
|
|
|
Monitor *cur_mon;
|
|
|
|
QDict *args;
|
|
|
|
QObject **ret;
|
|
|
|
Error **errp;
|
|
|
|
Coroutine *co;
|
|
|
|
} QmpDispatchBH;
|
|
|
|
|
|
|
|
static void do_qmp_dispatch_bh(void *opaque)
|
|
|
|
{
|
|
|
|
QmpDispatchBH *data = opaque;
|
|
|
|
|
|
|
|
assert(monitor_cur() == NULL);
|
|
|
|
monitor_set_cur(qemu_coroutine_self(), data->cur_mon);
|
|
|
|
data->cmd->fn(data->args, data->ret, data->errp);
|
|
|
|
monitor_set_cur(qemu_coroutine_self(), NULL);
|
|
|
|
aio_co_wake(data->co);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Runs outside of coroutine context for OOB commands, but in coroutine
|
|
|
|
* context for everything else.
|
|
|
|
*/
|
2022-12-16 12:48:26 +01:00
|
|
|
QDict *coroutine_mixed_fn qmp_dispatch(const QmpCommandList *cmds, QObject *request,
|
|
|
|
bool allow_oob, Monitor *cur_mon)
|
2020-03-17 12:54:46 +01:00
|
|
|
{
|
|
|
|
Error *err = NULL;
|
2018-07-03 10:53:43 +02:00
|
|
|
bool oob;
|
2011-07-19 21:50:37 +02:00
|
|
|
const char *command;
|
2020-03-17 12:54:46 +01:00
|
|
|
QDict *args;
|
2020-03-16 18:18:24 +01:00
|
|
|
const QmpCommand *cmd;
|
2020-03-17 12:54:48 +01:00
|
|
|
QDict *dict;
|
|
|
|
QObject *id;
|
2011-07-19 21:50:37 +02:00
|
|
|
QObject *ret = NULL;
|
2020-03-17 12:54:47 +01:00
|
|
|
QDict *rsp = NULL;
|
2011-07-19 21:50:37 +02:00
|
|
|
|
2020-03-17 12:54:48 +01:00
|
|
|
dict = qobject_to(QDict, request);
|
2014-05-02 13:26:35 +02:00
|
|
|
if (!dict) {
|
2020-03-17 12:54:48 +01:00
|
|
|
id = NULL;
|
|
|
|
error_setg(&err, "QMP input must be a JSON object");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = qdict_get(dict, "id");
|
|
|
|
|
|
|
|
if (!qmp_dispatch_check_obj(dict, allow_oob, &err)) {
|
2020-03-17 12:54:46 +01:00
|
|
|
goto out;
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|
|
|
|
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
command = qdict_get_try_str(dict, "execute");
|
2018-07-03 10:53:43 +02:00
|
|
|
oob = false;
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
if (!command) {
|
|
|
|
assert(allow_oob);
|
|
|
|
command = qdict_get_str(dict, "exec-oob");
|
2018-07-03 10:53:43 +02:00
|
|
|
oob = true;
|
qmp: Redo how the client requests out-of-band execution
Commit cf869d53172 "qmp: support out-of-band (oob) execution" added a
general mechanism for command-independent arguments just for an
out-of-band flag:
The "control" key is introduced to store this extra flag. "control"
field is used to store arguments that are shared by all the commands,
rather than command specific arguments. Let "run-oob" be the first.
However, it failed to reject unknown members of "control". For
instance, in QMP command
{"execute": "query-name", "id": 42, "control": {"crap": true}}
"crap" gets silently ignored.
Instead of fixing this, revert the general "control" mechanism
(because YAGNI), and do it the way I initially proposed, with key
"exec-oob". Simpler code, simpler interface.
An out-of-band command
{"execute": "migrate-pause", "id": 42, "control": {"run-oob": true}}
becomes
{"exec-oob": "migrate-pause", "id": 42}
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180703085358.13941-13-armbru@redhat.com>
[Commit message typo fixed]
2018-07-03 10:53:38 +02:00
|
|
|
}
|
2017-03-03 13:32:25 +01:00
|
|
|
cmd = qmp_find_command(cmds, command);
|
2011-07-19 21:50:37 +02:00
|
|
|
if (cmd == NULL) {
|
2020-03-17 12:54:46 +01:00
|
|
|
error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
|
2015-01-13 16:16:35 +01:00
|
|
|
"The command %s has not been found", command);
|
2020-03-17 12:54:46 +01:00
|
|
|
goto out;
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|
2021-10-28 12:25:19 +02:00
|
|
|
if (!compat_policy_input_ok(cmd->special_features, &compat_policy,
|
|
|
|
ERROR_CLASS_COMMAND_NOT_FOUND,
|
|
|
|
"command", command, &err)) {
|
|
|
|
goto out;
|
2021-03-18 16:55:17 +01:00
|
|
|
}
|
2011-12-07 05:03:42 +01:00
|
|
|
if (!cmd->enabled) {
|
2020-03-17 12:54:46 +01:00
|
|
|
error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
|
2021-02-19 09:28:14 +01:00
|
|
|
"Command %s has been disabled%s%s",
|
|
|
|
command,
|
|
|
|
cmd->disable_reason ? ": " : "",
|
|
|
|
cmd->disable_reason ?: "");
|
2020-03-17 12:54:46 +01:00
|
|
|
goto out;
|
2011-12-07 05:03:42 +01:00
|
|
|
}
|
2018-07-03 10:53:43 +02:00
|
|
|
if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
|
2020-03-17 12:54:46 +01:00
|
|
|
error_setg(&err, "The command %s does not support OOB",
|
2018-07-03 10:53:43 +02:00
|
|
|
command);
|
2020-03-17 12:54:46 +01:00
|
|
|
goto out;
|
2018-07-03 10:53:43 +02:00
|
|
|
}
|
2011-07-19 21:50:37 +02:00
|
|
|
|
2020-10-27 09:44:18 +01:00
|
|
|
if (!qmp_command_available(cmd, &err)) {
|
2020-03-17 12:54:46 +01:00
|
|
|
goto out;
|
2018-05-11 19:24:43 +02:00
|
|
|
}
|
|
|
|
|
2011-07-19 21:50:37 +02:00
|
|
|
if (!qdict_haskey(dict, "arguments")) {
|
|
|
|
args = qdict_new();
|
|
|
|
} else {
|
|
|
|
args = qdict_get_qdict(dict, "arguments");
|
2018-04-19 17:01:43 +02:00
|
|
|
qobject_ref(args);
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|
2020-10-05 17:58:47 +02:00
|
|
|
|
2020-10-05 17:58:50 +02:00
|
|
|
assert(!(oob && qemu_in_coroutine()));
|
2020-10-05 17:58:47 +02:00
|
|
|
assert(monitor_cur() == NULL);
|
2020-10-05 17:58:50 +02:00
|
|
|
if (!!(cmd->options & QCO_COROUTINE) == qemu_in_coroutine()) {
|
2024-01-18 15:48:23 +01:00
|
|
|
if (qemu_in_coroutine()) {
|
|
|
|
/*
|
|
|
|
* Move the coroutine from iohandler_ctx to qemu_aio_context for
|
|
|
|
* executing the command handler so that it can make progress if it
|
|
|
|
* involves an AIO_WAIT_WHILE().
|
|
|
|
*/
|
2024-02-06 20:06:10 +01:00
|
|
|
aio_co_reschedule_self(qemu_get_aio_context());
|
2024-01-18 15:48:23 +01:00
|
|
|
}
|
|
|
|
|
2020-10-05 17:58:50 +02:00
|
|
|
monitor_set_cur(qemu_coroutine_self(), cur_mon);
|
|
|
|
cmd->fn(args, &ret, &err);
|
|
|
|
monitor_set_cur(qemu_coroutine_self(), NULL);
|
2024-01-18 15:48:23 +01:00
|
|
|
|
|
|
|
if (qemu_in_coroutine()) {
|
|
|
|
/*
|
|
|
|
* Yield and reschedule so the main loop stays responsive.
|
|
|
|
*
|
|
|
|
* Move back to iohandler_ctx so that nested event loops for
|
|
|
|
* qemu_aio_context don't start new monitor commands.
|
|
|
|
*/
|
2024-02-06 20:06:10 +01:00
|
|
|
aio_co_reschedule_self(iohandler_get_aio_context());
|
2024-01-18 15:48:23 +01:00
|
|
|
}
|
2020-10-05 17:58:50 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Actual context doesn't match the one the command needs.
|
|
|
|
*
|
|
|
|
* Case 1: we are in coroutine context, but command does not
|
|
|
|
* have QCO_COROUTINE. We need to drop out of coroutine
|
|
|
|
* context for executing it.
|
|
|
|
*
|
|
|
|
* Case 2: we are outside coroutine context, but command has
|
|
|
|
* QCO_COROUTINE. Can't actually happen, because we get here
|
|
|
|
* outside coroutine context only when executing a command
|
|
|
|
* out of band, and OOB commands never have QCO_COROUTINE.
|
|
|
|
*/
|
|
|
|
assert(!oob && qemu_in_coroutine() && !(cmd->options & QCO_COROUTINE));
|
|
|
|
|
|
|
|
QmpDispatchBH data = {
|
|
|
|
.cur_mon = cur_mon,
|
|
|
|
.cmd = cmd,
|
|
|
|
.args = args,
|
|
|
|
.ret = &ret,
|
|
|
|
.errp = &err,
|
|
|
|
.co = qemu_coroutine_self(),
|
|
|
|
};
|
2024-01-18 15:48:23 +01:00
|
|
|
aio_bh_schedule_oneshot(iohandler_get_aio_context(), do_qmp_dispatch_bh,
|
2020-10-05 17:58:50 +02:00
|
|
|
&data);
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
}
|
2020-03-17 12:54:47 +01:00
|
|
|
qobject_unref(args);
|
2020-03-17 12:54:46 +01:00
|
|
|
if (err) {
|
2020-03-25 19:47:22 +01:00
|
|
|
/* or assert(!ret) after reviewing all handlers: */
|
|
|
|
qobject_unref(ret);
|
2020-03-17 12:54:47 +01:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd->options & QCO_NO_SUCCESS_RESP) {
|
2016-04-28 23:45:11 +02:00
|
|
|
g_assert(!ret);
|
2020-03-17 12:54:47 +01:00
|
|
|
return NULL;
|
2016-04-28 23:45:11 +02:00
|
|
|
} else if (!ret) {
|
2020-03-17 12:54:49 +01:00
|
|
|
/*
|
|
|
|
* When the command's schema has no 'returns', cmd->fn()
|
|
|
|
* leaves @ret null. The QMP spec calls for an empty object
|
|
|
|
* then; supply it.
|
|
|
|
*/
|
2016-04-28 23:45:11 +02:00
|
|
|
ret = QOBJECT(qdict_new());
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|
|
|
|
|
2020-03-17 12:54:47 +01:00
|
|
|
rsp = qdict_new();
|
|
|
|
qdict_put_obj(rsp, "return", ret);
|
2011-07-19 21:50:37 +02:00
|
|
|
|
2020-03-17 12:54:46 +01:00
|
|
|
out:
|
2011-07-19 21:50:37 +02:00
|
|
|
if (err) {
|
2020-03-17 12:54:47 +01:00
|
|
|
assert(!rsp);
|
2018-07-03 10:53:48 +02:00
|
|
|
rsp = qmp_error_response(err);
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|
|
|
|
|
2020-03-17 12:54:47 +01:00
|
|
|
assert(rsp);
|
|
|
|
|
|
|
|
if (id) {
|
2019-02-20 16:42:53 +01:00
|
|
|
qdict_put_obj(rsp, "id", qobject_ref(id));
|
|
|
|
}
|
|
|
|
|
2018-07-03 10:53:49 +02:00
|
|
|
return rsp;
|
2011-07-19 21:50:37 +02:00
|
|
|
}
|