2011-07-19 23:50:37 +04: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 20:49:57 +03:00
|
|
|
#include "qemu/osdep.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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2012-12-17 21:19:43 +04:00
|
|
|
#include "qapi/qmp/dispatch.h"
|
2018-02-01 14:18:39 +03:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2016-06-09 19:48:32 +03:00
|
|
|
#include "qapi/qmp/qjson.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2018-03-11 05:38:05 +03:00
|
|
|
#include "qapi/qmp/qbool.h"
|
2011-07-19 23:50:37 +04:00
|
|
|
|
2018-07-03 11:53:43 +03:00
|
|
|
static QDict *qmp_dispatch_check_obj(const QObject *request, bool allow_oob,
|
|
|
|
Error **errp)
|
2011-07-19 23:50:37 +04: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 11:53:38 +03:00
|
|
|
const char *exec_key = NULL;
|
2011-07-19 23:50:37 +04:00
|
|
|
const QDictEntry *ent;
|
|
|
|
const char *arg_name;
|
|
|
|
const QObject *arg_obj;
|
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 11:53:38 +03:00
|
|
|
QDict *dict;
|
2011-07-19 23:50:37 +04:00
|
|
|
|
2018-02-24 18:40:29 +03:00
|
|
|
dict = qobject_to(QDict, request);
|
2017-02-17 23:38:18 +03:00
|
|
|
if (!dict) {
|
2017-04-27 11:41:23 +03:00
|
|
|
error_setg(errp, "QMP input must be a JSON object");
|
2011-07-19 23:50:37 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 11:53:38 +03:00
|
|
|
if (!strcmp(arg_name, "execute")
|
|
|
|
|| (!strcmp(arg_name, "exec-oob") && allow_oob)) {
|
2011-07-19 23:50:37 +04: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 11:53:38 +03:00
|
|
|
error_setg(errp, "QMP input member '%s' must be a string",
|
|
|
|
arg_name);
|
2011-07-19 23:50:37 +04: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 11:53:38 +03:00
|
|
|
if (exec_key) {
|
|
|
|
error_setg(errp, "QMP input member '%s' clashes with '%s'",
|
|
|
|
arg_name, exec_key);
|
2017-03-03 15:32:21 +03: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 11:53:38 +03:00
|
|
|
exec_key = arg_name;
|
|
|
|
} else if (!strcmp(arg_name, "arguments")) {
|
2018-03-11 05:38:05 +03: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 11:53:38 +03:00
|
|
|
"QMP input member 'arguments' must be an object");
|
2018-03-11 05:38:05 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-02-20 18:42:53 +03:00
|
|
|
} else if (!strcmp(arg_name, "id")) {
|
|
|
|
continue;
|
2017-03-03 15:32:21 +03:00
|
|
|
} else {
|
2017-04-27 11:41:23 +03:00
|
|
|
error_setg(errp, "QMP input member '%s' is unexpected",
|
2017-03-03 15:32:29 +03:00
|
|
|
arg_name);
|
2011-07-19 23:50:37 +04: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 11:53:38 +03:00
|
|
|
if (!exec_key) {
|
2017-04-27 11:41:23 +03:00
|
|
|
error_setg(errp, "QMP input lacks member 'execute'");
|
2011-07-19 23:50:37 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2017-03-03 15:32:25 +03:00
|
|
|
static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
|
2018-07-03 11:53:37 +03:00
|
|
|
bool allow_oob, Error **errp)
|
2011-07-19 23:50:37 +04:00
|
|
|
{
|
2014-05-02 15:26:37 +04:00
|
|
|
Error *local_err = NULL;
|
2018-07-03 11:53:43 +03:00
|
|
|
bool oob;
|
2011-07-19 23:50:37 +04:00
|
|
|
const char *command;
|
|
|
|
QDict *args, *dict;
|
|
|
|
QmpCommand *cmd;
|
|
|
|
QObject *ret = NULL;
|
|
|
|
|
2018-07-03 11:53:37 +03:00
|
|
|
dict = qmp_dispatch_check_obj(request, allow_oob, errp);
|
2014-05-02 15:26:35 +04:00
|
|
|
if (!dict) {
|
2011-07-19 23:50:37 +04: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 11:53:38 +03:00
|
|
|
command = qdict_get_try_str(dict, "execute");
|
2018-07-03 11:53:43 +03: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 11:53:38 +03:00
|
|
|
if (!command) {
|
|
|
|
assert(allow_oob);
|
|
|
|
command = qdict_get_str(dict, "exec-oob");
|
2018-07-03 11:53:43 +03: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 11:53:38 +03:00
|
|
|
}
|
2017-03-03 15:32:25 +03:00
|
|
|
cmd = qmp_find_command(cmds, command);
|
2011-07-19 23:50:37 +04:00
|
|
|
if (cmd == NULL) {
|
2015-01-13 18:16:35 +03:00
|
|
|
error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
|
|
|
|
"The command %s has not been found", command);
|
2011-07-19 23:50:37 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2011-12-07 08:03:42 +04:00
|
|
|
if (!cmd->enabled) {
|
2014-03-22 03:42:26 +04:00
|
|
|
error_setg(errp, "The command %s has been disabled for this instance",
|
|
|
|
command);
|
2011-12-07 08:03:42 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-07-03 11:53:43 +03:00
|
|
|
if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
|
|
|
|
error_setg(errp, "The command %s does not support OOB",
|
|
|
|
command);
|
2019-03-25 18:47:48 +03:00
|
|
|
return NULL;
|
2018-07-03 11:53:43 +03:00
|
|
|
}
|
2011-07-19 23:50:37 +04:00
|
|
|
|
2018-05-11 20:24:43 +03:00
|
|
|
if (runstate_check(RUN_STATE_PRECONFIG) &&
|
|
|
|
!(cmd->options & QCO_ALLOW_PRECONFIG)) {
|
|
|
|
error_setg(errp, "The command '%s' isn't permitted in '%s' state",
|
|
|
|
cmd->name, RunState_str(RUN_STATE_PRECONFIG));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-19 23:50:37 +04:00
|
|
|
if (!qdict_haskey(dict, "arguments")) {
|
|
|
|
args = qdict_new();
|
|
|
|
} else {
|
|
|
|
args = qdict_get_qdict(dict, "arguments");
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_ref(args);
|
2011-07-19 23:50:37 +04:00
|
|
|
}
|
|
|
|
|
2016-04-29 00:45:11 +03:00
|
|
|
cmd->fn(args, &ret, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
} else if (cmd->options & QCO_NO_SUCCESS_RESP) {
|
|
|
|
g_assert(!ret);
|
|
|
|
} else if (!ret) {
|
2018-07-03 11:53:53 +03:00
|
|
|
/* TODO turn into assertion */
|
2016-04-29 00:45:11 +03:00
|
|
|
ret = QOBJECT(qdict_new());
|
2011-07-19 23:50:37 +04:00
|
|
|
}
|
|
|
|
|
2018-04-19 18:01:43 +03:00
|
|
|
qobject_unref(args);
|
2011-07-19 23:50:37 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-03 11:53:48 +03:00
|
|
|
QDict *qmp_error_response(Error *err)
|
2012-08-01 23:30:13 +04:00
|
|
|
{
|
2018-07-03 11:53:48 +03:00
|
|
|
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;
|
2012-08-01 23:30:13 +04:00
|
|
|
}
|
|
|
|
|
2018-03-11 05:38:05 +03: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 11:53:38 +03:00
|
|
|
* Does @qdict look like a command to be run out-of-band?
|
2018-03-11 05:38:05 +03:00
|
|
|
*/
|
2018-08-29 16:40:35 +03:00
|
|
|
bool qmp_is_oob(const QDict *dict)
|
2018-03-11 05:38:05 +03: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 11:53:38 +03:00
|
|
|
return qdict_haskey(dict, "exec-oob")
|
|
|
|
&& !qdict_haskey(dict, "execute");
|
2018-03-11 05:38:05 +03:00
|
|
|
}
|
|
|
|
|
2018-07-03 11:53:49 +03:00
|
|
|
QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,
|
|
|
|
bool allow_oob)
|
2011-07-19 23:50:37 +04:00
|
|
|
{
|
|
|
|
Error *err = NULL;
|
2019-02-20 18:42:53 +03:00
|
|
|
QDict *dict = qobject_to(QDict, request);
|
|
|
|
QObject *ret, *id = dict ? qdict_get(dict, "id") : NULL;
|
2011-07-19 23:50:37 +04:00
|
|
|
QDict *rsp;
|
|
|
|
|
2018-07-03 11:53:37 +03:00
|
|
|
ret = do_qmp_dispatch(cmds, request, allow_oob, &err);
|
2011-07-19 23:50:37 +04:00
|
|
|
if (err) {
|
2018-07-03 11:53:48 +03:00
|
|
|
rsp = qmp_error_response(err);
|
2011-07-19 23:50:37 +04:00
|
|
|
} else if (ret) {
|
2018-07-03 11:53:48 +03:00
|
|
|
rsp = qdict_new();
|
2011-07-19 23:50:37 +04:00
|
|
|
qdict_put_obj(rsp, "return", ret);
|
|
|
|
} else {
|
2018-07-03 11:53:53 +03:00
|
|
|
/* Can only happen for commands with QCO_NO_SUCCESS_RESP */
|
2018-07-03 11:53:48 +03:00
|
|
|
rsp = NULL;
|
2011-07-19 23:50:37 +04:00
|
|
|
}
|
|
|
|
|
2019-02-20 18:42:53 +03:00
|
|
|
if (rsp && id) {
|
|
|
|
qdict_put_obj(rsp, "id", qobject_ref(id));
|
|
|
|
}
|
|
|
|
|
2018-07-03 11:53:49 +03:00
|
|
|
return rsp;
|
2011-07-19 23:50:37 +04:00
|
|
|
}
|