[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 18/32] qmp: Don't let JSON errors jump the queue
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH 18/32] qmp: Don't let JSON errors jump the queue |
Date: |
Mon, 2 Jul 2018 18:22:04 +0200 |
handle_qmp_command() reports JSON syntax errors right away. This is
wrong when OOB is enabled, because the errors can "jump the queue"
then.
The previous commit fixed the same bug for semantic errors, by
delaying the checking until dispatch. We can't delay the checking, so
delay the reporting.
Signed-off-by: Markus Armbruster <address@hidden>
---
monitor.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/monitor.c b/monitor.c
index 7a80e58bf2..fd83a57dda 100644
--- a/monitor.c
+++ b/monitor.c
@@ -253,8 +253,12 @@ struct QMPRequest {
Monitor *mon;
/* "id" field of the request */
QObject *id;
- /* Request object to be handled */
+ /*
+ * Request object to be handled or Error to be reported
+ * (exactly one of them is non-null)
+ */
QObject *req;
+ Error *err;
/*
* Whether we need to resume the monitor afterward. This flag is
* used to emulate the old QMP server behavior that the current
@@ -359,6 +363,7 @@ static void qmp_request_free(QMPRequest *req)
{
qobject_unref(req->id);
qobject_unref(req->req);
+ error_free(req->err);
g_free(req);
}
@@ -4198,8 +4203,14 @@ static void monitor_qmp_bh_dispatcher(void *data)
return;
}
- trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: "");
- monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
+ if (req_obj->req) {
+ trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: "");
+ monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
+ } else {
+ assert(req_obj->err);
+ monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL);
+ }
+
if (req_obj->need_resume) {
/* Pairs with the monitor_suspend() in handle_qmp_command() */
monitor_resume(req_obj->mon);
@@ -4226,11 +4237,6 @@ static void handle_qmp_command(JSONMessageParser
*parser, GQueue *tokens)
/* json_parser_parse_err() sucks: can fail without setting @err */
error_setg(&err, QERR_JSON_PARSING);
}
- if (err) {
- assert(!req);
- monitor_qmp_respond(mon, NULL, err, NULL);
- return;
- }
qdict = qobject_to(QDict, req);
if (qdict) {
@@ -4256,6 +4262,7 @@ static void handle_qmp_command(JSONMessageParser *parser,
GQueue *tokens)
req_obj->mon = mon;
req_obj->id = id;
req_obj->req = req;
+ req_obj->err = err;
req_obj->need_resume = false;
/* Protect qmp_requests and fetching its length. */
--
2.17.1
- [Qemu-devel] [PATCH 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id", (continued)
- [Qemu-devel] [PATCH 08/32] tests/test-qga: Demonstrate the guest-agent ignores "id", Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 14/32] qmp: Always free QMPRequest with qmp_request_free(), Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 16/32] tests/qmp-test: Demonstrate QMP errors jumping the queue, Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 18/32] qmp: Don't let JSON errors jump the queue,
Markus Armbruster <=
- [Qemu-devel] [PATCH 12/32] qmp: Redo how the client requests out-of-band execution, Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 27/32] qmp: Add some comments around null responses, Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 17/32] qmp: Don't let malformed in-band commands jump the queue, Markus Armbruster, 2018/07/02
- [Qemu-devel] [PATCH 24/32] qmp: Replace monitor_json_emitter{, raw}() by qmp_{queue, send}_response(), Markus Armbruster, 2018/07/02