mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-07 09:43:56 -06:00
qmp: support out-of-band (oob) execution
Having "allow-oob":true for a command does not mean that this command will always be run in out-of-band mode. The out-of-band quick path will only be executed if we specify the extra "run-oob" flag when sending the QMP request: { "execute": "command-that-allows-oob", "arguments": { ... }, "control": { "run-oob": true } } 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. Note that in the patch I exported qmp_dispatch_check_obj() to be used to check the request earlier, and at the same time allowed "id" field to be there since actually we always allow that. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20180309090006.10018-19-peterx@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> [eblake: rebase to qobject_to(), spelling fix] Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
876c67512e
commit
cf869d5317
4 changed files with 111 additions and 10 deletions
|
@ -17,8 +17,9 @@
|
|||
#include "qapi/qmp/json-parser.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
#include "qapi/qmp/qbool.h"
|
||||
|
||||
static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
|
||||
QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
|
||||
{
|
||||
const QDictEntry *ent;
|
||||
const char *arg_name;
|
||||
|
@ -50,6 +51,14 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)
|
|||
"QMP input member 'arguments' must be an object");
|
||||
return NULL;
|
||||
}
|
||||
} else if (!strcmp(arg_name, "id")) {
|
||||
continue;
|
||||
} else if (!strcmp(arg_name, "control")) {
|
||||
if (qobject_type(arg_obj) != QTYPE_QDICT) {
|
||||
error_setg(errp,
|
||||
"QMP input member 'control' must be a dict");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
error_setg(errp, "QMP input member '%s' is unexpected",
|
||||
arg_name);
|
||||
|
@ -120,6 +129,28 @@ QObject *qmp_build_error_object(Error *err)
|
|||
error_get_pretty(err));
|
||||
}
|
||||
|
||||
/*
|
||||
* Detect whether a request should be run out-of-band, by quickly
|
||||
* peeking at whether we have: { "control": { "run-oob": true } }. By
|
||||
* default commands are run in-band.
|
||||
*/
|
||||
bool qmp_is_oob(QDict *dict)
|
||||
{
|
||||
QBool *bool_obj;
|
||||
|
||||
dict = qdict_get_qdict(dict, "control");
|
||||
if (!dict) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool_obj = qobject_to(QBool, qdict_get(dict, "run-oob"));
|
||||
if (!bool_obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return qbool_get_bool(bool_obj);
|
||||
}
|
||||
|
||||
QObject *qmp_dispatch(QmpCommandList *cmds, QObject *request)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue