From nobody Sat May 4 23:25:24 2024 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 1538564987616753.9509721027665; Wed, 3 Oct 2018 04:09:47 -0700 (PDT) Received: from localhost ([::1]:48082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7f2I-0000t5-Es for importer@patchew.org; Wed, 03 Oct 2018 07:09:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7erW-0000RV-At for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7erS-0002iU-8S for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51028) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7erR-0002Sg-Oe for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA10E3084024; Wed, 3 Oct 2018 10:58:13 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96F991821F; Wed, 3 Oct 2018 10:58:10 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:50 +0400 Message-Id: <20181003105755.10862-2-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 03 Oct 2018 10:58:13 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 1/6] chardev: avoid crash if no associated address 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A socket chardev may not have associated address (when adding client fd manually for example). But on disconnect, updating socket filename expects an address and may lead to this crash: Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault. 0x0000555555d8c70c in SocketAddress_to_str (prefix=3D0x555556043062 "disc= onnected:", addr=3D0x0, is_listen=3Dfalse, is_telnet=3Dfalse) at /home/elma= rco/src/qq/chardev/char-socket.c:388 388 switch (addr->type) { (gdb) bt #0 0x0000555555d8c70c in SocketAddress_to_str (prefix=3D0x555556043062 "= disconnected:", addr=3D0x0, is_listen=3Dfalse, is_telnet=3Dfalse) at /home/= elmarco/src/qq/chardev/char-socket.c:388 #1 0x0000555555d8c8aa in update_disconnected_filename (s=3D0x555556b1ed0= 0) at /home/elmarco/src/qq/chardev/char-socket.c:419 #2 0x0000555555d8c959 in tcp_chr_disconnect (chr=3D0x555556b1ed00) at /h= ome/elmarco/src/qq/chardev/char-socket.c:438 #3 0x0000555555d8cba1 in tcp_chr_hup (channel=3D0x555556b75690, cond=3DG= _IO_HUP, opaque=3D0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-sock= et.c:482 #4 0x0000555555da596e in qio_channel_fd_source_dispatch (source=3D0x5555= 56bb68b0, callback=3D0x555555d8cb58 , user_data=3D0x555556b1ed= 00) at /home/elmarco/src/qq/io/channel-watch.c:84 Replace filename with a generic "disconnected:socket" in this case. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 7cd0ae2824..a75b46d9fe 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -423,8 +423,12 @@ static void update_disconnected_filename(SocketChardev= *s) Chardev *chr =3D CHARDEV(s); =20 g_free(chr->filename); - chr->filename =3D SocketAddress_to_str("disconnected:", s->addr, - s->is_listen, s->is_telnet); + if (s->addr) { + chr->filename =3D SocketAddress_to_str("disconnected:", s->addr, + s->is_listen, s->is_telnet); + } else { + chr->filename =3D g_strdup("disconnected:socket"); + } } =20 /* NB may be called even if tcp_chr_connect has not been --=20 2.19.0.271.gfe8321ec05 From nobody Sat May 4 23:25:24 2024 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 1538564766896333.1342958488219; Wed, 3 Oct 2018 04:06:06 -0700 (PDT) Received: from localhost ([::1]:48044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7eyj-00067i-8q for importer@patchew.org; Wed, 03 Oct 2018 07:06:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7erW-0000RT-Ai for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7erS-0002iz-FC for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54780) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7erS-0002Zp-35 for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:34 -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 79EAC3D13; Wed, 3 Oct 2018 10:58:22 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B17B27BC4; Wed, 3 Oct 2018 10:58:18 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:51 +0400 Message-Id: <20181003105755.10862-3-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@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.29]); Wed, 03 Oct 2018 10:58:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 2/6] chardev: remove qemu_chr_fe_read_all() counter 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is no obvious reason to have a loop counter. This limits from reading several megabytes large buffers in one go, since socket read/write usually have a limit. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- chardev/char-fe.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index b1f228e8b5..f158f158f8 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -56,7 +56,7 @@ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t = *buf, int len) int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len) { Chardev *s =3D be->chr; - int offset =3D 0, counter =3D 10; + int offset =3D 0; int res; =20 if (!s || !CHARDEV_GET_CLASS(s)->chr_sync_read) { @@ -88,10 +88,6 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, = int len) } =20 offset +=3D res; - - if (!counter--) { - break; - } } =20 if (qemu_chr_replay(s) && replay_mode =3D=3D REPLAY_MODE_RECORD) { --=20 2.19.0.271.gfe8321ec05 From nobody Sat May 4 23:25:24 2024 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 1538564538789857.9133699798081; Wed, 3 Oct 2018 04:02:18 -0700 (PDT) Received: from localhost ([::1]:48010 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7ev3-0002Zk-JR for importer@patchew.org; Wed, 03 Oct 2018 07:02:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7erW-0000RU-Ar for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7erS-0002iM-6H for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7erR-0002dP-Oc for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:33 -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 379F23002707; Wed, 3 Oct 2018 10:58:28 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC6B727BC4; Wed, 3 Oct 2018 10:58:26 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:52 +0400 Message-Id: <20181003105755.10862-4-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@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.46]); Wed, 03 Oct 2018 10:58:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 3/6] chardev: unref if underlying chardev has no parent 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" It's possible to write code creating a chardev backend that is not registered. When it is not user-created, it makes sense to keep it hidden. Let the associated frontend destroy it also in this case. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-fe.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index f158f158f8..a8931f7afd 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -235,7 +235,12 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del) d->backends[b->tag] =3D NULL; } if (del) { - object_unparent(OBJECT(b->chr)); + Object *obj =3D OBJECT(b->chr); + if (obj->parent) { + object_unparent(obj); + } else { + object_unref(obj); + } } b->chr =3D NULL; } --=20 2.19.0.271.gfe8321ec05 From nobody Sat May 4 23:25:24 2024 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 1538565076322458.3110263445566; Wed, 3 Oct 2018 04:11:16 -0700 (PDT) Received: from localhost ([::1]:48092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7f3Y-0001an-Fm for importer@patchew.org; Wed, 03 Oct 2018 07:11:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7erY-0000Sp-Ra for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7erW-0002mD-Ev for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51892) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7erW-0002lK-44 for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BE5F308A94E; Wed, 3 Oct 2018 10:58:37 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6895B5D6A6; Wed, 3 Oct 2018 10:58:32 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:53 +0400 Message-Id: <20181003105755.10862-5-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 03 Oct 2018 10:58:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 4/6] char.h: fix gtk-doc comment style 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Fix up conformance to GTK-Doc function comment style, as documented in https://developer.gnome.org/gtk-doc-manual/stable/documenting_symbols.html.= en Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Markus Armbruster --- include/chardev/char-fe.h | 81 ++++++++++++++++++--------------------- include/chardev/char.h | 61 +++++++++++++---------------- 2 files changed, 63 insertions(+), 79 deletions(-) diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index c67271f1ba..46c997d352 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -20,7 +20,7 @@ struct CharBackend { }; =20 /** - * @qemu_chr_fe_init: + * qemu_chr_fe_init: * * Initializes a front end for the given CharBackend and * Chardev. Call qemu_chr_fe_deinit() to remove the association and @@ -31,7 +31,7 @@ struct CharBackend { bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp); =20 /** - * @qemu_chr_fe_deinit: + * qemu_chr_fe_deinit: * @b: a CharBackend * @del: if true, delete the chardev backend * @@ -42,9 +42,9 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error *= *errp); void qemu_chr_fe_deinit(CharBackend *b, bool del); =20 /** - * @qemu_chr_fe_get_driver: + * qemu_chr_fe_get_driver: * - * Returns the driver associated with a CharBackend or NULL if no + * Returns: the driver associated with a CharBackend or NULL if no * associated Chardev. * Note: avoid this function as the driver should never be accessed direct= ly, * especially by the frontends that support chardevice hotswap. @@ -53,21 +53,21 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del); Chardev *qemu_chr_fe_get_driver(CharBackend *be); =20 /** - * @qemu_chr_fe_backend_connected: + * qemu_chr_fe_backend_connected: * - * Returns true if there is a chardevice associated with @be. + * Returns: true if there is a chardevice associated with @be. */ bool qemu_chr_fe_backend_connected(CharBackend *be); =20 /** - * @qemu_chr_fe_backend_open: + * qemu_chr_fe_backend_open: * - * Returns true if chardevice associated with @be is open. + * Returns: true if chardevice associated with @be is open. */ bool qemu_chr_fe_backend_open(CharBackend *be); =20 /** - * @qemu_chr_fe_set_handlers: + * qemu_chr_fe_set_handlers: * @b: a CharBackend * @fd_can_read: callback to get the amount of data the frontend may * receive @@ -95,7 +95,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, bool set_open); =20 /** - * @qemu_chr_fe_take_focus: + * qemu_chr_fe_take_focus: * * Take the focus (if the front end is muxed). * @@ -104,14 +104,14 @@ void qemu_chr_fe_set_handlers(CharBackend *b, void qemu_chr_fe_take_focus(CharBackend *b); =20 /** - * @qemu_chr_fe_accept_input: + * qemu_chr_fe_accept_input: * * Notify that the frontend is ready to receive data */ void qemu_chr_fe_accept_input(CharBackend *be); =20 /** - * @qemu_chr_fe_disconnect: + * qemu_chr_fe_disconnect: * * Close a fd accepted by character backend. * Without associated Chardev, do nothing. @@ -119,7 +119,7 @@ void qemu_chr_fe_accept_input(CharBackend *be); void qemu_chr_fe_disconnect(CharBackend *be); =20 /** - * @qemu_chr_fe_wait_connected: + * qemu_chr_fe_wait_connected: * * Wait for characted backend to be connected, return < 0 on error or * if no associated Chardev. @@ -127,19 +127,18 @@ void qemu_chr_fe_disconnect(CharBackend *be); int qemu_chr_fe_wait_connected(CharBackend *be, Error **errp); =20 /** - * @qemu_chr_fe_set_echo: + * qemu_chr_fe_set_echo: + * @echo: true to enable echo, false to disable echo * * Ask the backend to override its normal echo setting. This only really * applies to the stdio backend and is used by the QMP server such that you * can see what you type if you try to type QMP commands. * Without associated Chardev, do nothing. - * - * @echo true to enable echo, false to disable echo */ void qemu_chr_fe_set_echo(CharBackend *be, bool echo); =20 /** - * @qemu_chr_fe_set_open: + * qemu_chr_fe_set_open: * * Set character frontend open status. This is an indication that the * front end is ready (or not) to begin doing I/O. @@ -148,83 +147,77 @@ void qemu_chr_fe_set_echo(CharBackend *be, bool echo); void qemu_chr_fe_set_open(CharBackend *be, int fe_open); =20 /** - * @qemu_chr_fe_printf: + * qemu_chr_fe_printf: + * @fmt: see #printf * * Write to a character backend using a printf style interface. This * function is thread-safe. It does nothing without associated * Chardev. - * - * @fmt see #printf */ void qemu_chr_fe_printf(CharBackend *be, const char *fmt, ...) GCC_FMT_ATTR(2, 3); =20 /** - * @qemu_chr_fe_add_watch: + * qemu_chr_fe_add_watch: + * @cond: the condition to poll for + * @func: the function to call when the condition happens + * @user_data: the opaque pointer to pass to @func * * If the backend is connected, create and add a #GSource that fires * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP) * is active; return the #GSource's tag. If it is disconnected, * or without associated Chardev, return 0. * - * @cond the condition to poll for - * @func the function to call when the condition happens - * @user_data the opaque pointer to pass to @func - * * Returns: the source tag */ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, GIOFunc func, void *user_data); =20 /** - * @qemu_chr_fe_write: + * qemu_chr_fe_write: + * @buf: the data + * @len: the number of bytes to send * * Write data to a character backend from the front end. This function * will send data from the front end to the back end. This function * is thread-safe. * - * @buf the data - * @len the number of bytes to send - * * Returns: the number of bytes consumed (0 if no associated Chardev) */ int qemu_chr_fe_write(CharBackend *be, const uint8_t *buf, int len); =20 /** - * @qemu_chr_fe_write_all: + * qemu_chr_fe_write_all: + * @buf: the data + * @len: the number of bytes to send * * Write data to a character backend from the front end. This function wi= ll * send data from the front end to the back end. Unlike @qemu_chr_fe_writ= e, * this function will block if the back end cannot consume all of the data * attempted to be written. This function is thread-safe. * - * @buf the data - * @len the number of bytes to send - * * Returns: the number of bytes consumed (0 if no associated Chardev) */ int qemu_chr_fe_write_all(CharBackend *be, const uint8_t *buf, int len); =20 /** - * @qemu_chr_fe_read_all: + * qemu_chr_fe_read_all: + * @buf: the data buffer + * @len: the number of bytes to read * * Read data to a buffer from the back end. * - * @buf the data buffer - * @len the number of bytes to read - * * Returns: the number of bytes read (0 if no associated Chardev) */ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf, int len); =20 /** - * @qemu_chr_fe_ioctl: + * qemu_chr_fe_ioctl: + * @cmd: see CHR_IOCTL_* + * @arg: the data associated with @cmd * * Issue a device specific ioctl to a backend. This function is thread-sa= fe. * - * @cmd see CHR_IOCTL_* - * @arg the data associated with @cmd - * * Returns: if @cmd is not supported by the backend or there is no * associated Chardev, -ENOTSUP, otherwise the return * value depends on the semantics of @cmd @@ -232,7 +225,7 @@ int qemu_chr_fe_read_all(CharBackend *be, uint8_t *buf,= int len); int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *arg); =20 /** - * @qemu_chr_fe_get_msgfd: + * qemu_chr_fe_get_msgfd: * * For backends capable of fd passing, return the latest file descriptor p= assed * by a client. @@ -245,7 +238,7 @@ int qemu_chr_fe_ioctl(CharBackend *be, int cmd, void *a= rg); int qemu_chr_fe_get_msgfd(CharBackend *be); =20 /** - * @qemu_chr_fe_get_msgfds: + * qemu_chr_fe_get_msgfds: * * For backends capable of fd passing, return the number of file received * descriptors and fills the fds array up to num elements @@ -258,7 +251,7 @@ int qemu_chr_fe_get_msgfd(CharBackend *be); int qemu_chr_fe_get_msgfds(CharBackend *be, int *fds, int num); =20 /** - * @qemu_chr_fe_set_msgfds: + * qemu_chr_fe_set_msgfds: * * For backends capable of fd passing, set an array of fds to be passed wi= th * the next send operation. diff --git a/include/chardev/char.h b/include/chardev/char.h index 6f0576e214..3e4fe6dad0 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -68,12 +68,11 @@ struct Chardev { }; =20 /** - * @qemu_chr_new_from_opts: + * qemu_chr_new_from_opts: + * @opts: see qemu-config.c for a list of valid options * * Create a new character backend from a QemuOpts list. * - * @opts see qemu-config.c for a list of valid options - * * Returns: on success: a new character backend * otherwise: NULL; @errp specifies the error * or left untouched in case of help option @@ -82,17 +81,16 @@ Chardev *qemu_chr_new_from_opts(QemuOpts *opts, Error **errp); =20 /** - * @qemu_chr_parse_common: + * qemu_chr_parse_common: + * @opts: the options that still need parsing + * @backend: a new backend * * Parse the common options available to all character backends. - * - * @opts the options that still need parsing - * @backend a new backend */ void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backend); =20 /** - * @qemu_chr_parse_opts: + * qemu_chr_parse_opts: * * Parse the options to the ChardevBackend struct. * @@ -102,49 +100,46 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp); =20 /** - * @qemu_chr_new: + * qemu_chr_new: + * @label: the name of the backend + * @filename: the URI * * Create a new character backend from a URI. * - * @label the name of the backend - * @filename the URI - * * Returns: a new character backend */ Chardev *qemu_chr_new(const char *label, const char *filename); =20 /** - * @qemu_chr_change: + * qemu_chr_change: + * @opts: the new backend options * * Change an existing character backend - * - * @opts the new backend options */ void qemu_chr_change(QemuOpts *opts, Error **errp); =20 /** - * @qemu_chr_cleanup: + * qemu_chr_cleanup: * * Delete all chardevs (when leaving qemu) */ void qemu_chr_cleanup(void); =20 /** - * @qemu_chr_new_noreplay: + * qemu_chr_new_noreplay: + * @label: the name of the backend + * @filename: the URI * * Create a new character backend from a URI. * Character device communications are not written * into the replay log. * - * @label the name of the backend - * @filename the URI - * * Returns: a new character backend */ Chardev *qemu_chr_new_noreplay(const char *label, const char *filename); =20 /** - * @qemu_chr_be_can_write: + * qemu_chr_be_can_write: * * Determine how much data the front end can currently accept. This funct= ion * returns the number of bytes the front end can accept. If it returns 0,= the @@ -156,43 +151,39 @@ Chardev *qemu_chr_new_noreplay(const char *label, con= st char *filename); int qemu_chr_be_can_write(Chardev *s); =20 /** - * @qemu_chr_be_write: + * qemu_chr_be_write: + * @buf: a buffer to receive data from the front end + * @len: the number of bytes to receive from the front end * * Write data from the back end to the front end. Before issuing this cal= l, * the caller should call @qemu_chr_be_can_write to determine how much data * the front end can currently accept. - * - * @buf a buffer to receive data from the front end - * @len the number of bytes to receive from the front end */ void qemu_chr_be_write(Chardev *s, uint8_t *buf, int len); =20 /** - * @qemu_chr_be_write_impl: + * qemu_chr_be_write_impl: + * @buf: a buffer to receive data from the front end + * @len: the number of bytes to receive from the front end * * Implementation of back end writing. Used by replay module. - * - * @buf a buffer to receive data from the front end - * @len the number of bytes to receive from the front end */ void qemu_chr_be_write_impl(Chardev *s, uint8_t *buf, int len); =20 /** - * @qemu_chr_be_update_read_handlers: + * qemu_chr_be_update_read_handlers: + * @context: the gcontext that will be used to attach the watch sources * * Invoked when frontend read handlers are setup - * - * @context the gcontext that will be used to attach the watch sources */ void qemu_chr_be_update_read_handlers(Chardev *s, GMainContext *context); =20 /** - * @qemu_chr_be_event: + * qemu_chr_be_event: + * @event: the event to send * * Send an event from the back end to the front end. - * - * @event the event to send */ void qemu_chr_be_event(Chardev *s, int event); =20 --=20 2.19.0.271.gfe8321ec05 From nobody Sat May 4 23:25:24 2024 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 1538564475685276.4387158860028; Wed, 3 Oct 2018 04:01:15 -0700 (PDT) Received: from localhost ([::1]:48004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7eu2-0001q7-4x for importer@patchew.org; Wed, 03 Oct 2018 07:01:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7erj-0000dB-T7 for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7erf-0002s6-Q0 for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7erf-0002re-Gw for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:47 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA44930821EC; Wed, 3 Oct 2018 10:58:46 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 325B09D8DE; Wed, 3 Oct 2018 10:58:41 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:54 +0400 Message-Id: <20181003105755.10862-6-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 03 Oct 2018 10:58:46 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 5/6] chardev: mark the calls that allow an implicit mux monitor 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is mostly for readability of the code. Let's make it clear which callers can create an implicit monitor when the chardev is muxed. This will also enforce a safer behaviour, as we don't really support creating monitor anywhere/anytime at the moment. Add an assert() to make sure the programmer explicitely wanted that behaviour. There are documented cases, such as: -serial/-parallel/-virtioconsole and to less extent -debugcon. Less obvious and questionable ones are -gdb, SLIRP -guestfwd and Xen console. Add a FIXME note for those, but keep the support for now. Other qemu_chr_new() callers either have a fixed parameter/filename string or do not need it, such as -qtest: * qtest.c: qtest_init() Afaik, only used by tests/libqtest.c, without mux. I don't think we support it outside of qemu testing: drop support for implicit mux monitor (qemu_chr_new() call: no implicit mux now). * hw/ All with literal @filename argument that doesn't enable mux monitor. * tests/ All with @filename argument that doesn't enable mux monitor. On a related note, the list of monitor creation places: - the chardev creators listed above: all from command line (except perhaps Xen console?) - -gdb & hmp gdbserver will create a "GDB monitor command" chardev that is wired to an HMP monitor. - -mon command line option From this short study, I would like to think that a monitor may only be created in the main thread today, though I remain skeptical :) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Markus Armbruster --- include/chardev/char.h | 24 ++++++++++++++++++++---- chardev/char.c | 37 ++++++++++++++++++++++++++++++------- gdbstub.c | 6 +++++- hw/char/xen_console.c | 6 +++++- net/slirp.c | 6 +++++- vl.c | 10 +++++----- 6 files changed, 70 insertions(+), 19 deletions(-) diff --git a/include/chardev/char.h b/include/chardev/char.h index 3e4fe6dad0..7becd8c80c 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -105,14 +105,27 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, * @filename: the URI * * Create a new character backend from a URI. + * Do not implicitly initialize a monitor if the chardev is muxed. * * Returns: a new character backend */ Chardev *qemu_chr_new(const char *label, const char *filename); =20 /** - * qemu_chr_change: - * @opts: the new backend options + * qemu_chr_new_mux_mon: + * @label: the name of the backend + * @filename: the URI + * + * Create a new character backend from a URI. + * Implicitly initialize a monitor if the chardev is muxed. + * + * Returns: a new character backend + */ +Chardev *qemu_chr_new_mux_mon(const char *label, const char *filename); + +/** +* qemu_chr_change: +* @opts: the new backend options * * Change an existing character backend */ @@ -129,6 +142,7 @@ void qemu_chr_cleanup(void); * qemu_chr_new_noreplay: * @label: the name of the backend * @filename: the URI + * @permit_mux_mon: if chardev is muxed, initialize a monitor * * Create a new character backend from a URI. * Character device communications are not written @@ -136,7 +150,8 @@ void qemu_chr_cleanup(void); * * Returns: a new character backend */ -Chardev *qemu_chr_new_noreplay(const char *label, const char *filename); +Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, + bool permit_mux_mon); =20 /** * qemu_chr_be_can_write: @@ -194,7 +209,8 @@ bool qemu_chr_has_feature(Chardev *chr, ChardevFeature feature); void qemu_chr_set_feature(Chardev *chr, ChardevFeature feature); -QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename); +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename, + bool permit_mux_mon); int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all= ); #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true) int qemu_chr_wait_connected(Chardev *chr, Error **errp); diff --git a/chardev/char.c b/chardev/char.c index 76d866e6fe..e115166995 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -329,7 +329,8 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp) return 0; } =20 -QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename) +QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename, + bool permit_mux_mon) { char host[65], port[33], width[8], height[8]; int pos; @@ -344,6 +345,10 @@ QemuOpts *qemu_chr_parse_compat(const char *label, con= st char *filename) } =20 if (strstart(filename, "mon:", &p)) { + if (!permit_mux_mon) { + error_report("mon: isn't supported in this context"); + return NULL; + } filename =3D p; qemu_opt_set(opts, "mux", "on", &error_abort); if (strcmp(filename, "stdio") =3D=3D 0) { @@ -683,7 +688,8 @@ out: return chr; } =20 -Chardev *qemu_chr_new_noreplay(const char *label, const char *filename) +Chardev *qemu_chr_new_noreplay(const char *label, const char *filename, + bool permit_mux_mon) { const char *p; Chardev *chr; @@ -694,25 +700,32 @@ Chardev *qemu_chr_new_noreplay(const char *label, con= st char *filename) return qemu_chr_find(p); } =20 - opts =3D qemu_chr_parse_compat(label, filename); + opts =3D qemu_chr_parse_compat(label, filename, permit_mux_mon); if (!opts) return NULL; =20 chr =3D qemu_chr_new_from_opts(opts, &err); - if (err) { + if (!chr) { error_report_err(err); + goto out; } - if (chr && qemu_opt_get_bool(opts, "mux", 0)) { + + if (qemu_opt_get_bool(opts, "mux", 0)) { + assert(permit_mux_mon); monitor_init(chr, MONITOR_USE_READLINE); } + +out: qemu_opts_del(opts); return chr; } =20 -Chardev *qemu_chr_new(const char *label, const char *filename) +static Chardev *qemu_chr_new_permit_mux_mon(const char *label, + const char *filename, + bool permit_mux_mon) { Chardev *chr; - chr =3D qemu_chr_new_noreplay(label, filename); + chr =3D qemu_chr_new_noreplay(label, filename, permit_mux_mon); if (chr) { if (replay_mode !=3D REPLAY_MODE_NONE) { qemu_chr_set_feature(chr, QEMU_CHAR_FEATURE_REPLAY); @@ -726,6 +739,16 @@ Chardev *qemu_chr_new(const char *label, const char *f= ilename) return chr; } =20 +Chardev *qemu_chr_new(const char *label, const char *filename) +{ + return qemu_chr_new_permit_mux_mon(label, filename, false); +} + +Chardev *qemu_chr_new_mux_mon(const char *label, const char *filename) +{ + return qemu_chr_new_permit_mux_mon(label, filename, true); +} + static int qmp_query_chardev_foreach(Object *obj, void *data) { Chardev *chr =3D CHARDEV(obj); diff --git a/gdbstub.c b/gdbstub.c index d6ab95006c..c8478de8f5 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2038,7 +2038,11 @@ int gdbserver_start(const char *device) sigaction(SIGINT, &act, NULL); } #endif - chr =3D qemu_chr_new_noreplay("gdb", device); + /* + * FIXME: it's a bit weird to allow using a mux chardev here + * and implicitly setup a monitor. We may want to break this. + */ + chr =3D qemu_chr_new_noreplay("gdb", device, true); if (!chr) return -1; } diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index 8b4b4bf523..44f7236382 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -207,7 +207,11 @@ static int con_init(struct XenDevice *xendev) } else { snprintf(label, sizeof(label), "xencons%d", con->xendev.dev); qemu_chr_fe_init(&con->chr, - qemu_chr_new(label, output), &error_abort); + /* + * FIXME: sure we want to support implicit + * muxed monitors here? + */ + qemu_chr_new_mux_mon(label, output), &error_abort= ); } =20 xenstore_store_pv_console_info(con->xendev.dev, diff --git a/net/slirp.c b/net/slirp.c index c93b64dd91..99884de204 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -764,7 +764,11 @@ static int slirp_guestfwd(SlirpState *s, const char *c= onfig_str, Error **errp) } } else { Error *err =3D NULL; - Chardev *chr =3D qemu_chr_new(buf, p); + /* + * FIXME: sure we want to support implicit + * muxed monitors here? + */ + Chardev *chr =3D qemu_chr_new_mux_mon(buf, p); =20 if (!chr) { error_setg(errp, "Could not open guest forwarding device '%s'", diff --git a/vl.c b/vl.c index 0388852deb..a867c9c4d9 100644 --- a/vl.c +++ b/vl.c @@ -2310,7 +2310,7 @@ static void monitor_parse(const char *optarg, const c= har *mode, bool pretty) } else { snprintf(label, sizeof(label), "compat_monitor%d", monitor_device_index); - opts =3D qemu_chr_parse_compat(label, optarg); + opts =3D qemu_chr_parse_compat(label, optarg, true); if (!opts) { error_report("parse error: %s", optarg); exit(1); @@ -2382,7 +2382,7 @@ static int serial_parse(const char *devname) snprintf(label, sizeof(label), "serial%d", index); serial_hds =3D g_renew(Chardev *, serial_hds, index + 1); =20 - serial_hds[index] =3D qemu_chr_new(label, devname); + serial_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!serial_hds[index]) { error_report("could not connect serial device" " to character backend '%s'", devname); @@ -2418,7 +2418,7 @@ static int parallel_parse(const char *devname) exit(1); } snprintf(label, sizeof(label), "parallel%d", index); - parallel_hds[index] =3D qemu_chr_new(label, devname); + parallel_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!parallel_hds[index]) { error_report("could not connect parallel device" " to character backend '%s'", devname); @@ -2449,7 +2449,7 @@ static int virtcon_parse(const char *devname) qemu_opt_set(dev_opts, "driver", "virtconsole", &error_abort); =20 snprintf(label, sizeof(label), "virtcon%d", index); - virtcon_hds[index] =3D qemu_chr_new(label, devname); + virtcon_hds[index] =3D qemu_chr_new_mux_mon(label, devname); if (!virtcon_hds[index]) { error_report("could not connect virtio console" " to character backend '%s'", devname); @@ -2465,7 +2465,7 @@ static int debugcon_parse(const char *devname) { QemuOpts *opts; =20 - if (!qemu_chr_new("debugcon", devname)) { + if (!qemu_chr_new_mux_mon("debugcon", devname)) { exit(1); } opts =3D qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NUL= L); --=20 2.19.0.271.gfe8321ec05 From nobody Sat May 4 23:25:24 2024 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 1538565164596520.9270512433084; Wed, 3 Oct 2018 04:12:44 -0700 (PDT) Received: from localhost ([::1]:48098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7f59-0002Qm-FE for importer@patchew.org; Wed, 03 Oct 2018 07:12:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42341) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g7ero-0000fc-Ff for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g7ern-0002w3-MO for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58514) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g7ern-0002va-DD for qemu-devel@nongnu.org; Wed, 03 Oct 2018 06:58:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 919DA30832D8; Wed, 3 Oct 2018 10:58:54 +0000 (UTC) Received: from localhost (ovpn-112-51.ams2.redhat.com [10.36.112.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91B4C66D46; Wed, 3 Oct 2018 10:58:51 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 3 Oct 2018 14:57:55 +0400 Message-Id: <20181003105755.10862-7-marcandre.lureau@redhat.com> In-Reply-To: <20181003105755.10862-1-marcandre.lureau@redhat.com> References: <20181003105755.10862-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 03 Oct 2018 10:58:54 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 6/6] chardev: use a child source for qio input source 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: peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" GLib child source were added with version 2.28. We can use them now that we bumped our requirement to 2.40. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-io.c | 48 +++++------------------------------------------ 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/chardev/char-io.c b/chardev/char-io.c index f81052481a..8ced184160 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -33,7 +33,6 @@ typedef struct IOWatchPoll { IOCanReadHandler *fd_can_read; GSourceFunc fd_read; void *opaque; - GMainContext *context; } IOWatchPoll; =20 static IOWatchPoll *io_watch_poll_from_source(GSource *source) @@ -55,47 +54,24 @@ static gboolean io_watch_poll_prepare(GSource *source, iwp->src =3D qio_channel_create_watch( iwp->ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL); g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL); - g_source_attach(iwp->src, iwp->context); - } else { - g_source_destroy(iwp->src); + g_source_add_child_source(source, iwp->src); g_source_unref(iwp->src); + } else { + g_source_remove_child_source(source, iwp->src); iwp->src =3D NULL; } return FALSE; } =20 -static gboolean io_watch_poll_check(GSource *source) -{ - return FALSE; -} - static gboolean io_watch_poll_dispatch(GSource *source, GSourceFunc callba= ck, gpointer user_data) { - abort(); -} - -static void io_watch_poll_finalize(GSource *source) -{ - /* Due to a glib bug, removing the last reference to a source - * inside a finalize callback causes recursive locking (and a - * deadlock). This is not a problem inside other callbacks, - * including dispatch callbacks, so we call io_remove_watch_poll - * to remove this source. At this point, iwp->src must - * be NULL, or we would leak it. - * - * This would be solved much more elegantly by child sources, - * but we support older glib versions that do not have them. - */ - IOWatchPoll *iwp =3D io_watch_poll_from_source(source); - assert(iwp->src =3D=3D NULL); + return G_SOURCE_CONTINUE; } =20 static GSourceFuncs io_watch_poll_funcs =3D { .prepare =3D io_watch_poll_prepare, - .check =3D io_watch_poll_check, .dispatch =3D io_watch_poll_dispatch, - .finalize =3D io_watch_poll_finalize, }; =20 GSource *io_add_watch_poll(Chardev *chr, @@ -115,7 +91,6 @@ GSource *io_add_watch_poll(Chardev *chr, iwp->ioc =3D ioc; iwp->fd_read =3D (GSourceFunc) fd_read; iwp->src =3D NULL; - iwp->context =3D context; =20 name =3D g_strdup_printf("chardev-iowatch-%s", chr->label); g_source_set_name((GSource *)iwp, name); @@ -126,23 +101,10 @@ GSource *io_add_watch_poll(Chardev *chr, return (GSource *)iwp; } =20 -static void io_remove_watch_poll(GSource *source) -{ - IOWatchPoll *iwp; - - iwp =3D io_watch_poll_from_source(source); - if (iwp->src) { - g_source_destroy(iwp->src); - g_source_unref(iwp->src); - iwp->src =3D NULL; - } - g_source_destroy(&iwp->parent); -} - void remove_fd_in_watch(Chardev *chr) { if (chr->gsource) { - io_remove_watch_poll(chr->gsource); + g_source_destroy(chr->gsource); chr->gsource =3D NULL; } } --=20 2.19.0.271.gfe8321ec05