From: Markus Armbruster <armbru@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: berrange@redhat.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org, dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 02/11] monitor: Split monitor_init in HMP and QMP function
Date: Wed, 12 Jun 2019 08:12:00 +0200 [thread overview]
Message-ID: <87imtbuybz.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20190611134043.9524-3-kwolf@redhat.com> (Kevin Wolf's message of "Tue, 11 Jun 2019 15:40:34 +0200")
Kevin Wolf <kwolf@redhat.com> writes:
> Instead of mixing HMP and QMP monitors in the same function, separate
> the monitor creation function for both.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> ---
> monitor.c | 86 +++++++++++++++++++++++++++++++------------------------
> 1 file changed, 49 insertions(+), 37 deletions(-)
>
> diff --git a/monitor.c b/monitor.c
> index 70ce9e8a77..bb23cc0450 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -702,7 +702,7 @@ static void handle_hmp_command(Monitor *mon, const char *cmdline);
>
> static void monitor_iothread_init(void);
>
> -static void monitor_data_init(Monitor *mon, bool skip_flush,
> +static void monitor_data_init(Monitor *mon, int flags, bool skip_flush,
> bool use_io_thread)
> {
> if (use_io_thread && !mon_iothread) {
> @@ -717,6 +717,7 @@ static void monitor_data_init(Monitor *mon, bool skip_flush,
> mon->skip_flush = skip_flush;
> mon->use_io_thread = use_io_thread;
> mon->qmp.qmp_requests = g_queue_new();
> + mon->flags = flags;
> }
>
> static void monitor_data_destroy(Monitor *mon)
> @@ -740,7 +741,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
> char *output = NULL;
> Monitor *old_mon, hmp;
>
> - monitor_data_init(&hmp, true, false);
> + monitor_data_init(&hmp, 0, true, false);
>
> old_mon = cur_mon;
> cur_mon = &hmp;
Explicit initialization replaced implicit zero-initialization. Okay.
> @@ -4603,19 +4604,48 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
> monitor_list_append(mon);
> }
>
> -void monitor_init(Chardev *chr, int flags)
> +static void monitor_init_qmp(Chardev *chr, int flags)
> {
> Monitor *mon = g_malloc(sizeof(*mon));
> - bool use_readline = flags & MONITOR_USE_READLINE;
>
> /* Note: we run QMP monitor in I/O thread when @chr supports that */
> - monitor_data_init(mon, false,
> - (flags & MONITOR_USE_CONTROL)
> - && qemu_chr_has_feature(chr,
> - QEMU_CHAR_FEATURE_GCONTEXT));
> + monitor_data_init(mon, flags, false,
> + qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
>
> qemu_chr_fe_init(&mon->chr, chr, &error_abort);
> - mon->flags = flags;
> + qemu_chr_fe_set_echo(&mon->chr, true);
> +
> + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon, NULL);
> + if (mon->use_io_thread) {
> + /*
> + * Make sure the old iowatch is gone. It's possible when
> + * e.g. the chardev is in client mode, with wait=on.
> + */
> + remove_fd_in_watch(chr);
> + /*
> + * We can't call qemu_chr_fe_set_handlers() directly here
> + * since chardev might be running in the monitor I/O
> + * thread. Schedule a bottom half.
> + */
> + aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
> + monitor_qmp_setup_handlers_bh, mon);
> + /* The bottom half will add @mon to @mon_list */
> + } else {
> + qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
> + monitor_qmp_read, monitor_qmp_event,
> + NULL, mon, NULL, true);
> + monitor_list_append(mon);
> + }
> +}
> +
> +static void monitor_init_hmp(Chardev *chr, int flags)
> +{
> + Monitor *mon = g_malloc(sizeof(*mon));
> + bool use_readline = flags & MONITOR_USE_READLINE;
> +
> + monitor_data_init(mon, flags, false, false);
> + qemu_chr_fe_init(&mon->chr, chr, &error_abort);
> +
> if (use_readline) {
> mon->rs = readline_init(monitor_readline_printf,
> monitor_readline_flush,
> @@ -4624,36 +4654,18 @@ void monitor_init(Chardev *chr, int flags)
> monitor_read_command(mon, 0);
> }
>
> - if (monitor_is_qmp(mon)) {
> - qemu_chr_fe_set_echo(&mon->chr, true);
> - json_message_parser_init(&mon->qmp.parser, handle_qmp_command,
> - mon, NULL);
> - if (mon->use_io_thread) {
> - /*
> - * Make sure the old iowatch is gone. It's possible when
> - * e.g. the chardev is in client mode, with wait=on.
> - */
> - remove_fd_in_watch(chr);
> - /*
> - * We can't call qemu_chr_fe_set_handlers() directly here
> - * since chardev might be running in the monitor I/O
> - * thread. Schedule a bottom half.
> - */
> - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
> - monitor_qmp_setup_handlers_bh, mon);
> - /* The bottom half will add @mon to @mon_list */
> - return;
> - } else {
> - qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
> - monitor_qmp_read, monitor_qmp_event,
> - NULL, mon, NULL, true);
> - }
> + qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
> + monitor_event, NULL, mon, NULL, true);
> + monitor_list_append(mon);
> +}
> +
> +void monitor_init(Chardev *chr, int flags)
> +{
> + if (flags & MONITOR_USE_CONTROL) {
> + monitor_init_qmp(chr, flags);
> } else {
> - qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
> - monitor_event, NULL, mon, NULL, true);
> + monitor_init_hmp(chr, flags);
> }
> -
> - monitor_list_append(mon);
> }
>
> void monitor_cleanup(void)
This part of the diff is hard to read. I'm inserting a no-op patch just
for review: make two identical copies of monitor_init() called
monitor_init_qmp() and monitor_init_hmp(), have monitor_init() call them
depending on MONITOR_USE_CONTROL. Rebasing this patch on top of that
yields a more readable git-diff -w (readable for me, YMMV):
| @@ -4606,28 +4607,15 @@ static void monitor_qmp_setup_handlers_bh(void *opaque)
| static void monitor_init_qmp(Chardev *chr, int flags)
| {
| Monitor *mon = g_malloc(sizeof(*mon));
| - bool use_readline = flags & MONITOR_USE_READLINE;
See below.
|
| /* Note: we run QMP monitor in I/O thread when @chr supports that */
| - monitor_data_init(mon, false,
| - (flags & MONITOR_USE_CONTROL)
| - && qemu_chr_has_feature(chr,
| - QEMU_CHAR_FEATURE_GCONTEXT));
| + monitor_data_init(mon, flags, false,
| + qemu_chr_has_feature(chr, QEMU_CHAR_FEATURE_GCONTEXT));
Partially evaluated: flags & MONITOR_USE_CONTROL is true. Good.
|
| qemu_chr_fe_init(&mon->chr, chr, &error_abort);
| - mon->flags = flags;
Moved into monitor_data_init(). Good.
| - if (use_readline) {
| - mon->rs = readline_init(monitor_readline_printf,
| - monitor_readline_flush,
| - mon,
| - monitor_find_completion);
| - monitor_read_command(mon, 0);
| - }
Deleting readline support here is not a regression, because nothing ever
passes MONITOR_USE_READLINE along with MONITOR_USE_CONTROL. We use only
three of the four cases:
* Neither flag: gdbstub.c (I have no idea why and how this uses the
monitor code, and why it doesn't use readline)
* Just MONITOR_USE_READLINE:
- vl.c on behalf of -mon mode=readline,... and its various sugared
forms
- chardev/char.c for implicit mux monitor (you don't want to know)
* Just MONITOR_USE_CONTROL:
- vl.c on behalf of -mon mode=control,... and its various sugared
forms
QMP with readline could perhaps be convenient for testing. I use
socat's READLINE address type myself.
Speaking of odd flag combinations: MONITOR_USE_PRETTY is silently
ignored unless MONITOR_USE_CONTROL.
Deleting the unused (and untried) code to use QMP with readline is fine
with me, but please document MONITOR_USE_READLINE is silently ignored
with MONITOR_USE_CONTROL, or replace all the flags by an enumeration of
the actual cases: HMP without readline, HMP with readline, QMP, pretty
QMP.
| -
| - if (monitor_is_qmp(mon)) {
| qemu_chr_fe_set_echo(&mon->chr, true);
| - json_message_parser_init(&mon->qmp.parser, handle_qmp_command,
| - mon, NULL);
| +
| + json_message_parser_init(&mon->qmp.parser, handle_qmp_command, mon, NULL);
Partially evaluated: monitor_is_qmp(mon) is true. Good.
Keep the line break, please.
| if (mon->use_io_thread) {
| /*
| * Make sure the old iowatch is gone. It's possible when
| @@ -4642,33 +4630,22 @@ static void monitor_init_qmp(Chardev *chr, int flags)
| aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
| monitor_qmp_setup_handlers_bh, mon);
| /* The bottom half will add @mon to @mon_list */
| - return;
| } else {
| qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
| monitor_qmp_read, monitor_qmp_event,
| NULL, mon, NULL, true);
| - }
| - } else {
This else belongs to if (!monitor_is_qmp(mon)). Good.
| - qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
| - monitor_event, NULL, mon, NULL, true);
| - }
| -
| monitor_list_append(mon);
| }
| +}
You simplified
if (mon->use_io_thread) {
...
/* The bottom half will add @mon to @mon_list */
return;
} else {
...
}
monitor_list_append(mon);
to
if (mon->use_io_thread) {
...
/* The bottom half will add @mon to @mon_list */
} else {
...
monitor_list_append(mon);
}
Good.
|
| static void monitor_init_hmp(Chardev *chr, int flags)
| {
| Monitor *mon = g_malloc(sizeof(*mon));
| bool use_readline = flags & MONITOR_USE_READLINE;
|
| - /* Note: we run QMP monitor in I/O thread when @chr supports that */
| - monitor_data_init(mon, false,
| - (flags & MONITOR_USE_CONTROL)
| - && qemu_chr_has_feature(chr,
| - QEMU_CHAR_FEATURE_GCONTEXT));
| -
| + monitor_data_init(mon, flags, false, false);
Partially evaluated: flags & MONITOR_USE_CONTROL is false. Good.
| qemu_chr_fe_init(&mon->chr, chr, &error_abort);
| - mon->flags = flags;
| +
Moved into monitor_data_init(). Good.
| if (use_readline) {
| mon->rs = readline_init(monitor_readline_printf,
| monitor_readline_flush,
| @@ -4677,35 +4654,8 @@ static void monitor_init_hmp(Chardev *chr, int flags)
| monitor_read_command(mon, 0);
| }
|
| - if (monitor_is_qmp(mon)) {
| - qemu_chr_fe_set_echo(&mon->chr, true);
| - json_message_parser_init(&mon->qmp.parser, handle_qmp_command,
| - mon, NULL);
| - if (mon->use_io_thread) {
| - /*
| - * Make sure the old iowatch is gone. It's possible when
| - * e.g. the chardev is in client mode, with wait=on.
| - */
| - remove_fd_in_watch(chr);
| - /*
| - * We can't call qemu_chr_fe_set_handlers() directly here
| - * since chardev might be running in the monitor I/O
| - * thread. Schedule a bottom half.
| - */
| - aio_bh_schedule_oneshot(iothread_get_aio_context(mon_iothread),
| - monitor_qmp_setup_handlers_bh, mon);
| - /* The bottom half will add @mon to @mon_list */
| - return;
| - } else {
| - qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read,
| - monitor_qmp_read, monitor_qmp_event,
| - NULL, mon, NULL, true);
| - }
| - } else {
| qemu_chr_fe_set_handlers(&mon->chr, monitor_can_read, monitor_read,
| monitor_event, NULL, mon, NULL, true);
| - }
| -
Partially evaluated: monitor_is_qmp(mon) is false. Good.
| monitor_list_append(mon);
| }
|
Duplicates qemu_chr_fe_init(&mon->chr, chr, &error_abort). Quite
tolerable.
Much clearer overall.
next prev parent reply other threads:[~2019-06-12 6:13 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-11 13:40 [Qemu-devel] [PATCH v2 00/11] monitor: Split monitor.c in core/HMP/QMP/misc Kevin Wolf
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 01/11] monitor: Remove unused password prompting fields Kevin Wolf
2019-06-12 6:43 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 02/11] monitor: Split monitor_init in HMP and QMP function Kevin Wolf
2019-06-12 6:12 ` Markus Armbruster [this message]
2019-06-12 6:43 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 03/11] monitor: Make MonitorQMP a child class of Monitor Kevin Wolf
2019-06-12 7:59 ` Markus Armbruster
2019-06-12 11:28 ` Kevin Wolf
2019-06-12 14:18 ` Markus Armbruster
2019-06-12 8:05 ` [Qemu-devel] [PATCH v2.1 02.5/11] monitor: Restrict use of Monitor member qmp to actual QMP monitors Markus Armbruster
2019-06-12 8:05 ` [Qemu-devel] [PATCH v2.1 03/11] monitor: Make MonitorQMP a child class of Monitor Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 04/11] monitor: Create MonitorHMP with readline state Kevin Wolf
2019-06-12 9:07 ` Markus Armbruster
2019-06-12 9:54 ` Peter Xu
2019-06-12 10:03 ` Kevin Wolf
2019-06-12 14:08 ` Markus Armbruster
2019-06-12 14:10 ` Dr. David Alan Gilbert
2019-06-12 15:03 ` Kevin Wolf
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 05/11] monitor: Move cmd_table to MonitorHMP Kevin Wolf
2019-06-12 11:45 ` Markus Armbruster
2019-06-12 13:55 ` Kevin Wolf
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 06/11] Move monitor.c to monitor/misc.c Kevin Wolf
2019-06-11 15:38 ` Dr. David Alan Gilbert
2019-06-12 11:57 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 07/11] monitor: Move {hmp, qmp}.c to monitor/{hmp, qmp}-cmds.c Kevin Wolf
2019-06-11 16:09 ` Dr. David Alan Gilbert
2019-06-12 12:01 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 08/11] monitor: Create monitor_int.h with common definitions Kevin Wolf
2019-06-12 12:18 ` Markus Armbruster
2019-06-12 12:43 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 09/11] monitor: Split out monitor/qmp.c Kevin Wolf
2019-06-12 13:11 ` Markus Armbruster
2019-06-12 15:25 ` Kevin Wolf
2019-06-13 5:38 ` Markus Armbruster
2019-06-13 14:11 ` Kevin Wolf
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 10/11] monitor: Split out monitor/hmp.c Kevin Wolf
2019-06-12 13:17 ` Markus Armbruster
2019-06-12 15:31 ` Kevin Wolf
2019-06-13 5:44 ` Markus Armbruster
2019-06-11 13:40 ` [Qemu-devel] [PATCH v2 11/11] monitor: Split out monitor/monitor.c Kevin Wolf
2019-06-12 13:49 ` Markus Armbruster
2019-06-12 15:51 ` Kevin Wolf
2019-06-11 14:18 ` [Qemu-devel] [PATCH v2 00/11] monitor: Split monitor.c in core/HMP/QMP/misc no-reply
2019-06-11 15:24 ` no-reply
2019-06-12 14:22 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87imtbuybz.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).