[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 17/36] monitor: move the cur_mon hack deeper for QMP
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PULL 17/36] monitor: move the cur_mon hack deeper for QMP |
Date: |
Mon, 12 Mar 2018 13:36:08 -0500 |
From: Peter Xu <address@hidden>
In monitor_qmp_read(), we have the hack to temporarily replace the
cur_mon pointer. Now we move this hack deeper inside the QMP dispatcher
routine since the Monitor pointer can be actually obtained using
container_of() upon the parser object, just like most of the other JSON
parser users do.
This does not make much sense as a single patch. However, this will be
a big step for the next patch, when the QMP dispatcher routine will be
split from the QMP parser.
Reviewed-by: Stefan Hajnoczi <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
Message-Id: <address@hidden>
[eblake: rebase context of qobject_to() macro]
Signed-off-by: Eric Blake <address@hidden>
---
monitor.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/monitor.c b/monitor.c
index b5acc92b735..83e98741b4c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3762,7 +3762,9 @@ static void handle_qmp_command(JSONMessageParser *parser,
GQueue *tokens)
{
QObject *req, *rsp = NULL, *id = NULL;
QDict *qdict = NULL;
- Monitor *mon = cur_mon;
+ MonitorQMP *mon_qmp = container_of(parser, MonitorQMP, parser);
+ Monitor *old_mon, *mon = container_of(mon_qmp, Monitor, qmp);
+
Error *err = NULL;
req = json_parser_parse_err(tokens, NULL, &err);
@@ -3787,8 +3789,13 @@ static void handle_qmp_command(JSONMessageParser
*parser, GQueue *tokens)
QDECREF(req_json);
}
+ old_mon = cur_mon;
+ cur_mon = mon;
+
rsp = qmp_dispatch(cur_mon->qmp.commands, req);
+ cur_mon = old_mon;
+
if (mon->qmp.commands == &qmp_cap_negotiation_commands) {
qdict = qdict_get_qdict(qobject_to(QDict, rsp), "error");
if (qdict
@@ -3825,13 +3832,9 @@ err_out:
static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
{
- Monitor *old_mon = cur_mon;
+ Monitor *mon = opaque;
- cur_mon = opaque;
-
- json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, size);
-
- cur_mon = old_mon;
+ json_message_parser_feed(&mon->qmp.parser, (const char *) buf, size);
}
static void monitor_read(void *opaque, const uint8_t *buf, int size)
--
2.14.3
- [Qemu-devel] [PULL 02/36] qlit: use QType instead of int, (continued)
- [Qemu-devel] [PULL 02/36] qlit: use QType instead of int, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 05/36] compiler: Add QEMU_BUILD_BUG_MSG() macro, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 08/36] qapi: Remove qobject_to_X() functions, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 06/36] qapi: Add qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 03/36] qlit: add qobject_from_qlit(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 09/36] qapi: Make more of qobject_to(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 04/36] qapi: generate a literal qobject for introspection, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 16/36] monitor: move skip_flush into monitor_data_init, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 18/36] monitor: unify global init, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 11/36] block: Deprecate "backing": "", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 17/36] monitor: move the cur_mon hack deeper for QMP,
Eric Blake <=
- [Qemu-devel] [PULL 10/36] block: Handle null backing link, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 13/36] qobject: introduce qstring_get_try_str(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 26/36] qmp: add new event "command-dropped", Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 19/36] monitor: let mon_list be tail queue, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 01/36] qapi2texi: minor python code simplification, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 12/36] docs: update QMP documents for OOB commands, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 14/36] qobject: introduce qobject_get_try_str(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 22/36] monitor: introduce monitor_qmp_respond(), Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 20/36] monitor: allow using IO thread for parsing, Eric Blake, 2018/03/12
- [Qemu-devel] [PULL 24/36] monitor: let suspend/resume work even with QMPs, Eric Blake, 2018/03/12