From nobody Wed Nov 5 16:17:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153510183008452.63104120668538; Fri, 24 Aug 2018 02:10:30 -0700 (PDT) Received: from localhost ([::1]:40569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft86t-0001bG-BE for importer@patchew.org; Fri, 24 Aug 2018 05:10:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ft85O-0008Il-HF for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:08:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ft85N-000655-K9 for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:08:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37118 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ft85N-00064x-EN for qemu-devel@nongnu.org; Fri, 24 Aug 2018 05:08:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21C0287A74 for ; Fri, 24 Aug 2018 09:08:53 +0000 (UTC) Received: from xz-x1.redhat.com (ovpn-12-107.pek2.redhat.com [10.72.12.107]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD44E10EE797; Fri, 24 Aug 2018 09:08:45 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Fri, 24 Aug 2018 17:08:26 +0800 Message-Id: <20180824090826.21370-4-peterx@redhat.com> In-Reply-To: <20180824090826.21370-1-peterx@redhat.com> References: <20180824090826.21370-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 24 Aug 2018 09:08:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 24 Aug 2018 09:08:53 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC 3/3] monitor: switch to use chardev's iothread X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now after we have chardev maintained iothread, we switch to that one by adding a parsing phase for monitors even before chardevs start to initialize. Then chardevs will use a constant gcontext since the creation of the object and it should never change. Remove the context setup in qemu_chr_be_update_read_handlers(), instead assert it in qemu_chr_fe_set_handlers() properly to make sure the context to be setup is always the one provided when chardev creates. Note that now we kept all the context parameters in misc functions, however it should be always setting the same context, otherwise a programming bug. In the future we may remove all these parameters. Signed-off-by: Peter Xu --- chardev/char-fe.c | 6 ++++++ chardev/char.c | 1 - monitor.c | 4 ++-- vl.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index b1f228e8b5..fcb232c9b6 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -267,6 +267,12 @@ void qemu_chr_fe_set_handlers(CharBackend *b, remove_fd_in_watch(s); } else { fe_open =3D 1; + /* + * Currently we don't allow to change context after chardev is + * created. TODO: either remove these context parameters, or + * re-activate dynamic context switch for chardevs. + */ + assert(context =3D=3D s->gcontext); } b->chr_can_read =3D fd_can_read; b->chr_read =3D fd_read; diff --git a/chardev/char.c b/chardev/char.c index c98d245ef7..da8ca9082b 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -200,7 +200,6 @@ void qemu_chr_be_update_read_handlers(Chardev *s, { ChardevClass *cc =3D CHARDEV_GET_CLASS(s); =20 - s->gcontext =3D context; if (cc->chr_update_read_handler) { cc->chr_update_read_handler(s); } diff --git a/monitor.c b/monitor.c index a1999e396c..1e45f3466e 100644 --- a/monitor.c +++ b/monitor.c @@ -4543,7 +4543,7 @@ static AioContext *monitor_get_aio_context(void) =20 static void monitor_iothread_init(void) { - mon_iothread =3D iothread_create("mon_iothread", &error_abort); + mon_iothread =3D qemu_chr_iothread_get(CHR_CONTEXT_MONITOR); =20 /* * The dispatcher BH must run in the main loop thread, since we @@ -4735,7 +4735,7 @@ void monitor_cleanup(void) qemu_bh_delete(qmp_respond_bh); qmp_respond_bh =3D NULL; =20 - iothread_destroy(mon_iothread); + /* It'll be cleaned up by chardev */ mon_iothread =3D NULL; } =20 diff --git a/vl.c b/vl.c index 25e156c020..5bc0946987 100644 --- a/vl.c +++ b/vl.c @@ -2349,6 +2349,32 @@ static int mon_init_func(void *opaque, QemuOpts *opt= s, Error **errp) return 0; } =20 +/* + * This setup the backends properly, it really has nothing to do with + * monitor itself yet. + */ +static int mon_setup_func(void *opaque, QemuOpts *opts, Error **errp) +{ + const char *chardev; + int flags; + QemuOpts *chr_opts; + + flags =3D mon_parse_flags(opts); + chardev =3D qemu_opt_get(opts, "chardev"); + + /* + * If out-of-band is enabled on the monitor, choose the correct + * context for the backend before it initializes. + */ + if (flags & MONITOR_USE_OOB) { + chr_opts =3D qemu_opts_find(qemu_find_opts("chardev"), chardev); + qemu_opt_set_number(chr_opts, "context", CHR_CONTEXT_MONITOR, + &error_abort); + } + + return 0; +} + static void monitor_parse(const char *optarg, const char *mode, bool prett= y) { static int monitor_device_index =3D 0; @@ -4278,6 +4304,11 @@ int main(int argc, char **argv, char **envp) exit(1); } =20 + if (qemu_opts_foreach(qemu_find_opts("mon"), + mon_setup_func, NULL, NULL)) { + exit(1); + } + if (qemu_opts_foreach(qemu_find_opts("chardev"), chardev_init_func, NULL, NULL)) { exit(1); --=20 2.17.1