[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v3 07/27] monitor: move the cur_mon hack deeper for QM
From: |
Peter Xu |
Subject: |
[Qemu-devel] [RFC v3 07/27] monitor: move the cur_mon hack deeper for QMP |
Date: |
Mon, 6 Nov 2017 17:46:23 +0800 |
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 passed in to that using the new
JSON Parser opaque field now.
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: Eric Blake <address@hidden>
Signed-off-by: Peter Xu <address@hidden>
---
monitor.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/monitor.c b/monitor.c
index ab80d32c70..322dfb5f31 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3813,7 +3813,7 @@ static void handle_qmp_command(JSONMessageParser *parser,
GQueue *tokens,
{
QObject *req, *rsp = NULL, *id = NULL;
QDict *qdict = NULL;
- Monitor *mon = cur_mon;
+ Monitor *mon = opaque, *old_mon;
Error *err = NULL;
req = json_parser_parse_err(tokens, NULL, &err);
@@ -3838,8 +3838,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
@@ -3876,13 +3881,9 @@ err_out:
static void monitor_qmp_read(void *opaque, const uint8_t *buf, int size)
{
- Monitor *old_mon = cur_mon;
-
- cur_mon = opaque;
-
- json_message_parser_feed(&cur_mon->qmp.parser, (const char *) buf, size);
+ Monitor *mon = opaque;
- 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)
@@ -3956,7 +3957,7 @@ static void monitor_qmp_event(void *opaque, int event)
break;
case CHR_EVENT_CLOSED:
json_message_parser_destroy(&mon->qmp.parser);
- json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NULL);
+ json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon);
mon_refcount--;
monitor_fdsets_cleanup();
break;
@@ -4106,7 +4107,7 @@ void monitor_init(Chardev *chr, int flags)
qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_qmp_read,
monitor_qmp_event, NULL, mon, NULL, true);
qemu_chr_fe_set_echo(&mon->chr, true);
- json_message_parser_init(&mon->qmp.parser, handle_qmp_command, NULL);
+ json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon);
} else {
qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
monitor_event, NULL, mon, NULL, true);
--
2.13.5
- [Qemu-devel] [RFC v3 02/27] qobject: introduce qstring_get_try_str(), (continued)
- [Qemu-devel] [RFC v3 02/27] qobject: introduce qstring_get_try_str(), Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 03/27] qobject: introduce qobject_get_try_str(), Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 04/27] qobject: let object_property_get_str() use new API, Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 05/27] monitor: move skip_flush into monitor_data_init, Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 06/27] qjson: add "opaque" field to JSONMessageParser, Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 07/27] monitor: move the cur_mon hack deeper for QMP,
Peter Xu <=
- [Qemu-devel] [RFC v3 08/27] monitor: unify global init, Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 09/27] monitor: let mon_list be tail queue, Peter Xu, 2017/11/06
- [Qemu-devel] [RFC v3 10/27] monitor: create monitor dedicate iothread, Peter Xu, 2017/11/06