From patchwork Tue Jun 11 13:40:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 10986971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1601F6C5 for ; Tue, 11 Jun 2019 13:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01506283BB for ; Tue, 11 Jun 2019 13:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7D1B285A2; Tue, 11 Jun 2019 13:47:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 77A8D283BB for ; Tue, 11 Jun 2019 13:47:25 +0000 (UTC) Received: from localhost ([::1]:59158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hah7U-0002fh-OK for patchwork-qemu-devel@patchwork.kernel.org; Tue, 11 Jun 2019 09:47:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56050) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hah1L-0005oL-5t for qemu-devel@nongnu.org; Tue, 11 Jun 2019 09:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hah1J-0000uX-Rl for qemu-devel@nongnu.org; Tue, 11 Jun 2019 09:41:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46440) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hah1H-0000sn-0P; Tue, 11 Jun 2019 09:40:59 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F9E244BD1; Tue, 11 Jun 2019 13:40:58 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-117-58.ams2.redhat.com [10.36.117.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACCD519C59; Tue, 11 Jun 2019 13:40:56 +0000 (UTC) From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 11 Jun 2019 15:40:34 +0200 Message-Id: <20190611134043.9524-3-kwolf@redhat.com> In-Reply-To: <20190611134043.9524-1-kwolf@redhat.com> References: <20190611134043.9524-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 11 Jun 2019 13:40:58 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 02/11] monitor: Split monitor_init in HMP and QMP function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berrange@redhat.com, qemu-block@nongnu.org, armbru@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of mixing HMP and QMP monitors in the same function, separate the monitor creation function for both. Signed-off-by: Kevin Wolf Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Markus Armbruster --- 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)