From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org,
dgilbert@redhat.com
Subject: [Qemu-devel] [RFC PATCH 02/10] monitor: Split monitor_init in HMP and QMP function
Date: Fri, 7 Jun 2019 15:54:22 +0200 [thread overview]
Message-ID: <20190607135430.22149-3-kwolf@redhat.com> (raw)
In-Reply-To: <20190607135430.22149-1-kwolf@redhat.com>
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>
---
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;
@@ -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)
--
2.20.1
next prev parent reply other threads:[~2019-06-07 13:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-07 13:54 [Qemu-devel] [RFC PATCH 00/10] monitor: Split monitor.c in core/HMP/QMP/misc Kevin Wolf
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 01/10] monitor: Remove unused password prompting fields Kevin Wolf
2019-06-07 15:39 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` Kevin Wolf [this message]
2019-06-07 15:46 ` [Qemu-devel] [RFC PATCH 02/10] monitor: Split monitor_init in HMP and QMP function Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 03/10] monitor: Make MonitorQMP a child class of Monitor Kevin Wolf
2019-06-07 16:17 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 04/10] monitor: Create MonitorHMP with readline state Kevin Wolf
2019-06-07 16:32 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 05/10] monitor: Move cmd_table to MonitorHMP Kevin Wolf
2019-06-07 16:35 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 06/10] Move monitor.c to monitor/misc.c Kevin Wolf
2019-06-07 16:39 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 07/10] monitor: Create monitor_int.h with common definitions Kevin Wolf
2019-06-07 16:52 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 08/10] monitor: Split out monitor/qmp.c Kevin Wolf
2019-06-07 16:59 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 09/10] monitor: Split out monitor/hmp.c Kevin Wolf
2019-06-07 17:21 ` Dr. David Alan Gilbert
2019-06-07 13:54 ` [Qemu-devel] [RFC PATCH 10/10] monitor: Split out monitor/core.c Kevin Wolf
2019-06-07 17:29 ` Dr. David Alan Gilbert
2019-06-11 9:22 ` Kevin Wolf
2019-06-11 9:25 ` Dr. David Alan Gilbert
2019-06-07 17:30 ` Dr. David Alan Gilbert
2019-06-07 14:03 ` [Qemu-devel] [RFC PATCH 00/10] monitor: Split monitor.c in core/HMP/QMP/misc Daniel P. Berrangé
2019-06-07 14:25 ` Kevin Wolf
2019-06-07 14:31 ` Daniel P. Berrangé
2019-06-07 15:35 ` Dr. David Alan Gilbert
2019-06-07 18:11 ` [Qemu-devel] [Qemu-block] " Eric Blake
2019-06-07 16:48 ` [Qemu-devel] " no-reply
2019-06-07 20:42 ` no-reply
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=20190607135430.22149-3-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@redhat.com \
--cc=dgilbert@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.