Re: [Qemu-devel] [RFC 06/15] monitor: move the cur_mon hack deeper for QMP

2017-09-19 Thread Peter Xu
On Tue, Sep 19, 2017 at 04:05:48PM -0500, Eric Blake wrote:
> On 09/14/2017 02:50 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 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
> > splitted from the QMP parser.
> 
> English is weird: 'split' is the word for present, past, and past
> participle tenses; there is no word 'splitted'.

Fixed.

> 
> > 
> > Signed-off-by: Peter Xu 
> > ---
> >  monitor.c | 19 ++-
> >  1 file changed, 10 insertions(+), 9 deletions(-)
> > 
> 
> Reviewed-by: Eric Blake 

Thanks!

-- 
Peter Xu



Re: [Qemu-devel] [RFC 06/15] monitor: move the cur_mon hack deeper for QMP

2017-09-19 Thread Eric Blake
On 09/14/2017 02:50 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 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
> splitted from the QMP parser.

English is weird: 'split' is the word for present, past, and past
participle tenses; there is no word 'splitted'.

> 
> Signed-off-by: Peter Xu 
> ---
>  monitor.c | 19 ++-
>  1 file changed, 10 insertions(+), 9 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [RFC 06/15] monitor: move the cur_mon hack deeper for QMP

2017-09-14 Thread Peter Xu
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
splitted from the QMP parser.

Signed-off-by: Peter Xu 
---
 monitor.c | 19 ++-
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/monitor.c b/monitor.c
index 9096b64..d7eb3c2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3822,7 +3822,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, );
@@ -3847,8 +3847,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 == _cap_negotiation_commands) {
 qdict = qdict_get_qdict(qobject_to_qdict(rsp), "error");
 if (qdict
@@ -3885,13 +3890,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(_mon->qmp.parser, (const char *) buf, size);
+Monitor *mon = opaque;
 
-cur_mon = old_mon;
+json_message_parser_feed(>qmp.parser, (const char *) buf, size);
 }
 
 static void monitor_read(void *opaque, const uint8_t *buf, int size)
@@ -3965,7 +3966,7 @@ static void monitor_qmp_event(void *opaque, int event)
 break;
 case CHR_EVENT_CLOSED:
 json_message_parser_destroy(>qmp.parser);
-json_message_parser_init(>qmp.parser, handle_qmp_command, NULL);
+json_message_parser_init(>qmp.parser, handle_qmp_command, mon);
 mon_refcount--;
 monitor_fdsets_cleanup();
 break;
@@ -4115,7 +4116,7 @@ void monitor_init(Chardev *chr, int flags)
 qemu_chr_fe_set_handlers(>chr, monitor_can_read, monitor_qmp_read,
  monitor_qmp_event, NULL, mon, NULL, true);
 qemu_chr_fe_set_echo(>chr, true);
-json_message_parser_init(>qmp.parser, handle_qmp_command, NULL);
+json_message_parser_init(>qmp.parser, handle_qmp_command, mon);
 } else {
 qemu_chr_fe_set_handlers(>chr, monitor_can_read, monitor_read,
  monitor_event, NULL, mon, NULL, true);
-- 
2.7.4