Message ID | 20171219084557.9801-7-peterx@redhat.com |
---|---|
State | New |
Headers | show |
Series | QMP: out-of-band (OOB) execution support | expand |
On Tue, Dec 19, 2017 at 04:45:36PM +0800, Peter Xu wrote: > 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. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > monitor.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
On 12/19/2017 02:45 AM, Peter Xu wrote: > 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. > > Signed-off-by: Peter Xu <peterx@redhat.com> > --- > monitor.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) Reviewed-by: Eric Blake <eblake@redhat.com>
diff --git a/monitor.c b/monitor.c index 0030ded8f1..35a2aef0fe 100644 --- a/monitor.c +++ b/monitor.c @@ -3811,7 +3811,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); @@ -3836,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 @@ -3874,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)
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. Signed-off-by: Peter Xu <peterx@redhat.com> --- monitor.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)