[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 21/30] qapi: Inline do_qmp_dispatch() into qmp_dispatch()
From: |
Markus Armbruster |
Subject: |
[PATCH v2 21/30] qapi: Inline do_qmp_dispatch() into qmp_dispatch() |
Date: |
Tue, 3 Mar 2020 17:34:56 +0100 |
Both functions check @request is a QDict, and both have code for
QCO_NO_SUCCESS_RESP. This wasn't the case back when they were
created. It's a sign of muddled responsibilities. Inline. The next
commits will clean up some more.
Signed-off-by: Markus Armbruster <address@hidden>
---
qapi/qmp-dispatch.c | 90 +++++++++++++++++++++------------------------
1 file changed, 41 insertions(+), 49 deletions(-)
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index bc264b3c9b..a588072523 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -75,19 +75,42 @@ static QDict *qmp_dispatch_check_obj(const QObject
*request, bool allow_oob,
return dict;
}
-static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
- bool allow_oob, Error **errp)
+QDict *qmp_error_response(Error *err)
{
- Error *local_err = NULL;
+ 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)
+{
+ return qdict_haskey(dict, "exec-oob")
+ && !qdict_haskey(dict, "execute");
+}
+
+QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,
+ bool allow_oob)
+{
+ Error *err = NULL;
bool oob;
const char *command;
- QDict *args, *dict;
+ QDict *args;
QmpCommand *cmd;
+ QDict *dict = qobject_to(QDict, request);
+ QObject *id = dict ? qdict_get(dict, "id") : NULL;
QObject *ret = NULL;
+ QDict *rsp;
- dict = qmp_dispatch_check_obj(request, allow_oob, errp);
+ dict = qmp_dispatch_check_obj(request, allow_oob, &err);
if (!dict) {
- return NULL;
+ goto out;
}
command = qdict_get_try_str(dict, "execute");
@@ -99,27 +122,27 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds,
QObject *request,
}
cmd = qmp_find_command(cmds, command);
if (cmd == NULL) {
- error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
+ error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
"The command %s has not been found", command);
- return NULL;
+ goto out;
}
if (!cmd->enabled) {
- error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
+ error_set(&err, ERROR_CLASS_COMMAND_NOT_FOUND,
"The command %s has been disabled for this instance",
command);
- return NULL;
+ goto out;
}
if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
- error_setg(errp, "The command %s does not support OOB",
+ error_setg(&err, "The command %s does not support OOB",
command);
- return NULL;
+ goto out;
}
if (runstate_check(RUN_STATE_PRECONFIG) &&
!(cmd->options & QCO_ALLOW_PRECONFIG)) {
- error_setg(errp, "The command '%s' isn't permitted in '%s' state",
+ error_setg(&err, "The command '%s' isn't permitted in '%s' state",
cmd->name, RunState_str(RUN_STATE_PRECONFIG));
- return NULL;
+ goto out;
}
if (!qdict_haskey(dict, "arguments")) {
@@ -129,9 +152,9 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds,
QObject *request,
qobject_ref(args);
}
- cmd->fn(args, &ret, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ cmd->fn(args, &ret, &err);
+ if (err) {
+ ;
} else if (cmd->options & QCO_NO_SUCCESS_RESP) {
g_assert(!ret);
} else if (!ret) {
@@ -141,38 +164,7 @@ static QObject *do_qmp_dispatch(QmpCommandList *cmds,
QObject *request,
qobject_unref(args);
- return ret;
-}
-
-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)
-{
- return qdict_haskey(dict, "exec-oob")
- && !qdict_haskey(dict, "execute");
-}
-
-QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request,
- bool allow_oob)
-{
- Error *err = NULL;
- QDict *dict = qobject_to(QDict, request);
- QObject *ret, *id = dict ? qdict_get(dict, "id") : NULL;
- QDict *rsp;
-
- ret = do_qmp_dispatch(cmds, request, allow_oob, &err);
+out:
if (err) {
rsp = qmp_error_response(err);
} else if (ret) {
--
2.21.1
- [PATCH v2 27/30] qemu-options: New -compat to set policy for deprecated interfaces, (continued)
- [PATCH v2 27/30] qemu-options: New -compat to set policy for deprecated interfaces, Markus Armbruster, 2020/03/03
- [PATCH v2 07/30] tests/test-qmp-cmds: Simplify test data setup, Markus Armbruster, 2020/03/03
- [PATCH v2 18/30] qapi/schema: Rename QAPISchemaObjectType{Variant, Variants}, Markus Armbruster, 2020/03/03
- [PATCH v2 08/30] tests/test-qmp-event: Simplify test data setup, Markus Armbruster, 2020/03/03
- [PATCH v2 01/30] qemu-doc: Belatedly document QMP command arg & result deprecation, Markus Armbruster, 2020/03/03
- [PATCH v2 22/30] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP, Markus Armbruster, 2020/03/03
- [PATCH v2 12/30] qapi: Add feature flags to remaining definitions, Markus Armbruster, 2020/03/03
- [PATCH v2 15/30] qapi/introspect: Factor out _make_tree(), Markus Armbruster, 2020/03/03
- [PATCH v2 30/30] qapi: New -compat deprecated-input=crash, Markus Armbruster, 2020/03/03
- [PATCH v2 17/30] qapi/schema: Reorder classes so related ones are together, Markus Armbruster, 2020/03/03
- [PATCH v2 21/30] qapi: Inline do_qmp_dispatch() into qmp_dispatch(),
Markus Armbruster <=
- [PATCH v2 29/30] qapi: Implement -compat deprecated-input=reject, Markus Armbruster, 2020/03/03
- [PATCH v2 28/30] qapi: Implement -compat deprecated-output=hide, Markus Armbruster, 2020/03/03
- [PATCH v2 26/30] qapi: Mark deprecated QMP parts with feature 'deprecated', Markus Armbruster, 2020/03/03
- [PATCH v2 06/30] tests/test-qmp-cmds: Check responses more thoroughly, Markus Armbruster, 2020/03/03
- [PATCH v2 23/30] qapi: Simplify how qmp_dispatch() gets the request ID, Markus Armbruster, 2020/03/03
- [PATCH v2 20/30] qapi: Add feature flags to struct members, Markus Armbruster, 2020/03/03
- [PATCH v2 14/30] qapi/introspect: Rename *qlit* to reduce confusion, Markus Armbruster, 2020/03/03
- Re: [PATCH v2 00/30] Configurable policy for handling deprecated interfaces, Peter Maydell, 2020/03/03