From nobody Fri Oct 24 21:59:46 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 1520314689881762.1172140270501; Mon, 5 Mar 2018 21:38:09 -0800 (PST) Received: from localhost ([::1]:53594 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5If-0003zO-3v for importer@patchew.org; Tue, 06 Mar 2018 00:38:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5EK-0000rs-Pp for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5EH-0006hC-Nj for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:40 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41342 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 1et5EH-0006gn-JD for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 470B64023B98 for ; Tue, 6 Mar 2018 05:33:36 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 148D6AFD5E; Tue, 6 Mar 2018 05:33:33 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:12 +0800 Message-Id: <20180306053320.15401-2-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:36 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 1/9] vl: export machine_init_done 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We have that variable but not exported. Export that so modules can have a way to poke on whether machine init has finished. Meanwhile, set that up even before calling the notifiers, so that notifiers who may depend on this field will get a correct answer. Suggested-by: Paolo Bonzini Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- include/sysemu/sysemu.h | 2 ++ stubs/machine-init-done.c | 2 ++ vl.c | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 77bb3da582..3f0f35610b 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -86,6 +86,8 @@ void qemu_system_guest_panicked(GuestPanicInformation *in= fo); void qemu_add_exit_notifier(Notifier *notify); void qemu_remove_exit_notifier(Notifier *notify); =20 +extern bool machine_init_done; + void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify); =20 diff --git a/stubs/machine-init-done.c b/stubs/machine-init-done.c index 9a0d62514f..4121f1709b 100644 --- a/stubs/machine-init-done.c +++ b/stubs/machine-init-done.c @@ -2,6 +2,8 @@ #include "qemu-common.h" #include "sysemu/sysemu.h" =20 +bool machine_init_done =3D true; + void qemu_add_machine_init_done_notifier(Notifier *notify) { } diff --git a/vl.c b/vl.c index a33ac008fb..57777e8d47 100644 --- a/vl.c +++ b/vl.c @@ -2712,7 +2712,7 @@ static void qemu_run_exit_notifiers(void) notifier_list_notify(&exit_notifiers, NULL); } =20 -static bool machine_init_done; +bool machine_init_done; =20 void qemu_add_machine_init_done_notifier(Notifier *notify) { @@ -2729,8 +2729,8 @@ void qemu_remove_machine_init_done_notifier(Notifier = *notify) =20 static void qemu_run_machine_init_done_notifiers(void) { - notifier_list_notify(&machine_init_done_notifiers, NULL); machine_init_done =3D true; + notifier_list_notify(&machine_init_done_notifiers, NULL); } =20 static const QEMUOption *lookup_opt(int argc, char **argv, --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520314536352328.1171922682846; Mon, 5 Mar 2018 21:35:36 -0800 (PST) Received: from localhost ([::1]:53579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5G3-0001oz-V4 for importer@patchew.org; Tue, 06 Mar 2018 00:35:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41441) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5EK-0000ru-QM for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5EJ-0006hs-IM for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:40 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52460 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 1et5EJ-0006ho-Dh for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:39 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06A8E8163C5F for ; Tue, 6 Mar 2018 05:33:39 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6941AFD5E; Tue, 6 Mar 2018 05:33:36 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:13 +0800 Message-Id: <20180306053320.15401-3-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:33:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:33:39 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 2/9] chardev: fix leak in tcp_chr_telnet_init_io() 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Need to free TCPChardevTelnetInit when session established. Since at it, switch to use G_SOURCE_* macros. Reviewed-by: Daniel P. Berrange Reviewed-by: Paolo Bonzini Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi --- chardev/char-socket.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 113feaf948..205ee377a4 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -591,19 +591,23 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *io= c, ret =3D 0; } else { tcp_chr_disconnect(init->chr); - return FALSE; + goto end; } } init->buflen -=3D ret; =20 if (init->buflen =3D=3D 0) { tcp_chr_connect(init->chr); - return FALSE; + goto end; } =20 memmove(init->buf, init->buf + ret, init->buflen); =20 - return TRUE; + return G_SOURCE_CONTINUE; + +end: + g_free(init); + return G_SOURCE_REMOVE; } =20 static void tcp_chr_telnet_init(Chardev *chr) --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520314537627733.6907877800687; Mon, 5 Mar 2018 21:35:37 -0800 (PST) Received: from localhost ([::1]:53580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5G9-0001ra-6B for importer@patchew.org; Tue, 06 Mar 2018 00:35:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41463) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5EN-0000sX-4s for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5EM-0006kA-Ai for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:43 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50194 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 1et5EM-0006jy-5h for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCB23402B023 for ; Tue, 6 Mar 2018 05:33:41 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86EBAAFD5E; Tue, 6 Mar 2018 05:33:39 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:14 +0800 Message-Id: <20180306053320.15401-4-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 06 Mar 2018 05:33:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Tue, 06 Mar 2018 05:33:41 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'peterx@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/9] chardev: update net listener gcontext 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" TCP chardevs can be using QIO network listeners working in the background when in listening mode. However the network listeners are always running in main context. This can race with chardevs that are running in non-main contexts. To solve this, we need to re-setup the net listeners in tcp_chr_update_read_handler() with the newly cached gcontext. Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 205ee377a4..5aa01e15ff 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -422,8 +422,8 @@ static void tcp_chr_disconnect(Chardev *chr) tcp_chr_free_connection(chr); =20 if (s->listener) { - qio_net_listener_set_client_func(s->listener, tcp_chr_accept, - chr, NULL); + qio_net_listener_set_client_func_full(s->listener, tcp_chr_accept, + chr, NULL, chr->gcontext); } update_disconnected_filename(s); if (emit_close) { @@ -559,6 +559,16 @@ static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s =3D SOCKET_CHARDEV(chr); =20 + if (s->listener) { + /* + * It's possible that chardev context is changed in + * qemu_chr_be_update_read_handlers(). Reset it for QIO net + * listener if there is. + */ + qio_net_listener_set_client_func_full(s->listener, tcp_chr_accept, + chr, NULL, chr->gcontext); + } + if (!s->connected) { return; } @@ -743,7 +753,8 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelS= ocket *sioc) qio_channel_set_delay(s->ioc, false); } if (s->listener) { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + qio_net_listener_set_client_func_full(s->listener, NULL, NULL, + NULL, chr->gcontext); } =20 if (s->tls_creds) { @@ -824,7 +835,8 @@ static void char_socket_finalize(Object *obj) tcp_chr_reconn_timer_cancel(s); qapi_free_SocketAddress(s->addr); if (s->listener) { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + qio_net_listener_set_client_func_full(s->listener, NULL, NULL, + NULL, chr->gcontext); object_unref(OBJECT(s->listener)); } if (s->tls_creds) { @@ -980,8 +992,10 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } if (!s->ioc) { - qio_net_listener_set_client_func(s->listener, tcp_chr_acce= pt, - chr, NULL); + qio_net_listener_set_client_func_full(s->listener, + tcp_chr_accept, + chr, NULL, + chr->gcontext); } } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 1520314692200154.5992354646479; Mon, 5 Mar 2018 21:38:12 -0800 (PST) Received: from localhost ([::1]:53595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Ih-000418-5y for importer@patchew.org; Tue, 06 Mar 2018 00:38:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5EQ-0000vh-6W for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5EP-0006l4-2S for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:46 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52468 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 1et5EO-0006kt-TN for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 785648182D1E for ; Tue, 6 Mar 2018 05:33:44 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 456BA1C701; Tue, 6 Mar 2018 05:33:42 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:15 +0800 Message-Id: <20180306053320.15401-5-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:33:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:33:44 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 4/9] chardev: allow telnet gsource to switch gcontext 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It was originally created by qio_channel_add_watch() so it's always assigning the task to main context. Now we use the new API called qio_channel_add_watch_source() so that we get the GSource handle rather than the tag ID. Meanwhile, caching the gsource and TCPChardevTelnetInit (which holds the handshake data) in SocketChardev.telnet_source so that we can also do dynamic context switch when update read handlers. Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 67 +++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 5aa01e15ff..c22b3f330c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -39,6 +39,11 @@ =20 #define TCP_MAX_FDS 16 =20 +typedef struct { + char buf[21]; + size_t buflen; +} TCPChardevTelnetInit; + typedef struct { Chardev parent; QIOChannel *ioc; /* Client I/O channel */ @@ -59,6 +64,8 @@ typedef struct { bool is_listen; bool is_telnet; bool is_tn3270; + GSource *telnet_source; + TCPChardevTelnetInit *telnet_init; =20 GSource *reconnect_timer; int64_t reconnect_time; @@ -69,6 +76,7 @@ typedef struct { OBJECT_CHECK(SocketChardev, (obj), TYPE_CHARDEV_SOCKET) =20 static gboolean socket_reconnect_timeout(gpointer opaque); +static void tcp_chr_telnet_init(Chardev *chr); =20 static void tcp_chr_reconn_timer_cancel(SocketChardev *s) { @@ -555,6 +563,15 @@ static void tcp_chr_connect(void *opaque) qemu_chr_be_event(chr, CHR_EVENT_OPENED); } =20 +static void tcp_chr_telnet_destroy(SocketChardev *s) +{ + if (s->telnet_source) { + g_source_destroy(s->telnet_source); + g_source_unref(s->telnet_source); + s->telnet_source =3D NULL; + } +} + static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s =3D SOCKET_CHARDEV(chr); @@ -569,6 +586,10 @@ static void tcp_chr_update_read_handler(Chardev *chr) chr, NULL, chr->gcontext); } =20 + if (s->telnet_source) { + tcp_chr_telnet_init(CHARDEV(s)); + } + if (!s->connected) { return; } @@ -582,32 +603,30 @@ static void tcp_chr_update_read_handler(Chardev *chr) } } =20 -typedef struct { - Chardev *chr; - char buf[21]; - size_t buflen; -} TCPChardevTelnetInit; - static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc, GIOCondition cond G_GNUC_UNUSED, gpointer user_data) { - TCPChardevTelnetInit *init =3D user_data; + SocketChardev *s =3D user_data; + Chardev *chr =3D CHARDEV(s); + TCPChardevTelnetInit *init =3D s->telnet_init; ssize_t ret; =20 + assert(init); + ret =3D qio_channel_write(ioc, init->buf, init->buflen, NULL); if (ret < 0) { if (ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { ret =3D 0; } else { - tcp_chr_disconnect(init->chr); + tcp_chr_disconnect(chr); goto end; } } init->buflen -=3D ret; =20 if (init->buflen =3D=3D 0) { - tcp_chr_connect(init->chr); + tcp_chr_connect(chr); goto end; } =20 @@ -616,16 +635,30 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *io= c, return G_SOURCE_CONTINUE; =20 end: - g_free(init); + g_free(s->telnet_init); + s->telnet_init =3D NULL; + g_source_unref(s->telnet_source); + s->telnet_source =3D NULL; return G_SOURCE_REMOVE; } =20 static void tcp_chr_telnet_init(Chardev *chr) { SocketChardev *s =3D SOCKET_CHARDEV(chr); - TCPChardevTelnetInit *init =3D g_new0(TCPChardevTelnetInit, 1); + TCPChardevTelnetInit *init; size_t n =3D 0; =20 + /* Destroy existing task */ + tcp_chr_telnet_destroy(s); + + if (s->telnet_init) { + /* We are possibly during a handshake already */ + goto cont; + } + + s->telnet_init =3D g_new0(TCPChardevTelnetInit, 1); + init =3D s->telnet_init; + #define IACSET(x, a, b, c) \ do { \ x[n++] =3D a; \ @@ -633,7 +666,6 @@ static void tcp_chr_telnet_init(Chardev *chr) x[n++] =3D c; \ } while (0) =20 - init->chr =3D chr; if (!s->is_tn3270) { init->buflen =3D 12; /* Prep the telnet negotion to put telnet in binary, @@ -656,10 +688,11 @@ static void tcp_chr_telnet_init(Chardev *chr) =20 #undef IACSET =20 - qio_channel_add_watch( - s->ioc, G_IO_OUT, - tcp_chr_telnet_init_io, - init, NULL); +cont: + s->telnet_source =3D qio_channel_add_watch_source(s->ioc, G_IO_OUT, + tcp_chr_telnet_init_io, + s, NULL, + chr->gcontext); } =20 =20 @@ -834,6 +867,8 @@ static void char_socket_finalize(Object *obj) tcp_chr_free_connection(chr); tcp_chr_reconn_timer_cancel(s); qapi_free_SocketAddress(s->addr); + tcp_chr_telnet_destroy(s); + g_free(s->telnet_init); if (s->listener) { qio_net_listener_set_client_func_full(s->listener, NULL, NULL, NULL, chr->gcontext); --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 1520314824435346.3176383295853; Mon, 5 Mar 2018 21:40:24 -0800 (PST) Received: from localhost ([::1]:53605 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Kp-0006D7-KZ for importer@patchew.org; Tue, 06 Mar 2018 00:40:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5EZ-00011D-QU for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5EY-0006oH-DG for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:55 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41354 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 1et5EY-0006o8-88 for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:54 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CD2444023B98 for ; Tue, 6 Mar 2018 05:33:53 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03723AFD5E; Tue, 6 Mar 2018 05:33:44 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:16 +0800 Message-Id: <20180306053320.15401-6-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:53 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 5/9] chardev: introduce chr_machine_done hook 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Introduce ChardevClass.chr_machine_done() hook so that chardevs can run customized procedures after machine init. There was an existing mux user already that did similar thing but used a raw machine done notifier. Generalize it into a framework, and let the mux chardevs provide such a class-specific hook to achieve the same thing. Then we can move the mux related code to the char-mux.c file. Since at it, replace the mux_realized variable with the global machine_init_done varible. This notifier framework will be further leverged by other type of chardevs soon. Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-mux.c | 33 +++++++++++++++++++++++++++++---- chardev/char.c | 43 +++++++++++++++++-------------------------- include/chardev/char-mux.h | 2 -- include/chardev/char.h | 2 ++ tests/test-char.c | 1 - 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index d48e78103a..1b925c8dec 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -27,6 +27,7 @@ #include "qemu/option.h" #include "chardev/char.h" #include "sysemu/block-backend.h" +#include "sysemu/sysemu.h" #include "chardev/char-mux.h" =20 /* MUX driver for serial I/O splitting */ @@ -230,14 +231,12 @@ static void mux_chr_read(void *opaque, const uint8_t = *buf, int size) } } =20 -bool muxes_realized; - void mux_chr_send_all_event(Chardev *chr, int event) { MuxChardev *d =3D MUX_CHARDEV(chr); int i; =20 - if (!muxes_realized) { + if (!machine_init_done) { return; } =20 @@ -327,7 +326,7 @@ static void qemu_chr_open_mux(Chardev *chr, /* only default to opened state if we've realized the initial * set of muxes */ - *be_opened =3D muxes_realized; + *be_opened =3D machine_init_done; qemu_chr_fe_init(&d->chr, drv, errp); } =20 @@ -347,6 +346,31 @@ static void qemu_chr_parse_mux(QemuOpts *opts, Chardev= Backend *backend, mux->chardev =3D g_strdup(chardev); } =20 +/** + * Called after processing of default and command-line-specified + * chardevs to deliver CHR_EVENT_OPENED events to any FEs attached + * to a mux chardev. This is done here to ensure that + * output/prompts/banners are only displayed for the FE that has + * focus when initial command-line processing/machine init is + * completed. + * + * After this point, any new FE attached to any new or existing + * mux will receive CHR_EVENT_OPENED notifications for the BE + * immediately. + */ +static int open_muxes(Chardev *chr) +{ + /* send OPENED to all already-attached FEs */ + mux_chr_send_all_event(chr, CHR_EVENT_OPENED); + /* + * mark mux as OPENED so any new FEs will immediately receive + * OPENED event + */ + qemu_chr_be_event(chr, CHR_EVENT_OPENED); + + return 0; +} + static void char_mux_class_init(ObjectClass *oc, void *data) { ChardevClass *cc =3D CHARDEV_CLASS(oc); @@ -357,6 +381,7 @@ static void char_mux_class_init(ObjectClass *oc, void *= data) cc->chr_accept_input =3D mux_chr_accept_input; cc->chr_add_watch =3D mux_chr_add_watch; cc->chr_be_event =3D mux_chr_be_event; + cc->chr_machine_done =3D open_muxes; } =20 static const TypeInfo char_mux_type_info =3D { diff --git a/chardev/char.c b/chardev/char.c index 01d979a1da..fda820863c 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -281,40 +281,31 @@ static const TypeInfo char_type_info =3D { .class_init =3D char_class_init, }; =20 -/** - * Called after processing of default and command-line-specified - * chardevs to deliver CHR_EVENT_OPENED events to any FEs attached - * to a mux chardev. This is done here to ensure that - * output/prompts/banners are only displayed for the FE that has - * focus when initial command-line processing/machine init is - * completed. - * - * After this point, any new FE attached to any new or existing - * mux will receive CHR_EVENT_OPENED notifications for the BE - * immediately. - */ -static int open_muxes(Object *child, void *opaque) +static int chardev_machine_done_notify_one(Object *child, void *opaque) { - if (CHARDEV_IS_MUX(child)) { - /* send OPENED to all already-attached FEs */ - mux_chr_send_all_event(CHARDEV(child), CHR_EVENT_OPENED); - /* mark mux as OPENED so any new FEs will immediately receive - * OPENED event - */ - qemu_chr_be_event(CHARDEV(child), CHR_EVENT_OPENED); + Chardev *chr =3D (Chardev *)child; + ChardevClass *class =3D CHARDEV_GET_CLASS(chr); + + if (class->chr_machine_done) { + return class->chr_machine_done(chr); } =20 return 0; } =20 -static void muxes_realize_done(Notifier *notifier, void *unused) +static void chardev_machine_done_hook(Notifier *notifier, void *unused) { - muxes_realized =3D true; - object_child_foreach(get_chardevs_root(), open_muxes, NULL); + int ret =3D object_child_foreach(get_chardevs_root(), + chardev_machine_done_notify_one, NULL); + + if (ret) { + error_report("Failed to call chardev machine_done hooks"); + exit(1); + } } =20 -static Notifier muxes_realize_notify =3D { - .notify =3D muxes_realize_done, +static Notifier chardev_machine_done_notify =3D { + .notify =3D chardev_machine_done_hook, }; =20 static bool qemu_chr_is_busy(Chardev *s) @@ -1118,7 +1109,7 @@ static void register_types(void) * as part of realize functions like serial_isa_realizefn when -nograp= hic * is specified */ - qemu_add_machine_init_done_notifier(&muxes_realize_notify); + qemu_add_machine_init_done_notifier(&chardev_machine_done_notify); } =20 type_init(register_types); diff --git a/include/chardev/char-mux.h b/include/chardev/char-mux.h index 8928977897..1e13187767 100644 --- a/include/chardev/char-mux.h +++ b/include/chardev/char-mux.h @@ -27,8 +27,6 @@ #include "chardev/char.h" #include "chardev/char-fe.h" =20 -extern bool muxes_realized; - #define MAX_MUX 4 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2. */ #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1) diff --git a/include/chardev/char.h b/include/chardev/char.h index a381dc3df8..1cb1f4763f 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -247,6 +247,8 @@ typedef struct ChardevClass { void (*chr_set_echo)(Chardev *chr, bool echo); void (*chr_set_fe_open)(Chardev *chr, int fe_open); void (*chr_be_event)(Chardev *s, int event); + /* Return 0 if succeeded, 1 if failed */ + int (*chr_machine_done)(Chardev *chr); } ChardevClass; =20 Chardev *qemu_chardev_new(const char *id, const char *typename, diff --git a/tests/test-char.c b/tests/test-char.c index b358620911..e49af9e398 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -166,7 +166,6 @@ static void char_mux_test(void) FeHandler h1 =3D { 0, }, h2 =3D { 0, }; CharBackend chr_be1, chr_be2; =20 - muxes_realized =3D true; /* done after machine init */ opts =3D qemu_opts_create(qemu_find_opts("chardev"), "mux-label", 1, &error_abort); qemu_opt_set(opts, "backend", "ringbuf", &error_abort); --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 1520314826656197.74713249875617; Mon, 5 Mar 2018 21:40:26 -0800 (PST) Received: from localhost ([::1]:53606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Kr-0006GU-RG for importer@patchew.org; Tue, 06 Mar 2018 00:40:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Ed-000161-3p for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5Eb-0006sl-59 for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:59 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60176 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 1et5Eb-0006s8-0y for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 994C6D142A for ; Tue, 6 Mar 2018 05:33:56 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A17CAFD5E; Tue, 6 Mar 2018 05:33:54 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:17 +0800 Message-Id: <20180306053320.15401-7-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 06 Mar 2018 05:33:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 06 Mar 2018 05:33:56 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 6/9] chardev: use chardev's gcontext for async connect 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Generalize the function to create the async QIO task connection. Also, fix the context pointer to use the chardev's gcontext. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index c22b3f330c..1ce5adad9a 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -901,11 +901,22 @@ cleanup: object_unref(OBJECT(sioc)); } =20 +static void tcp_chr_connect_async(Chardev *chr) +{ + SocketChardev *s =3D SOCKET_CHARDEV(chr); + QIOChannelSocket *sioc; + + sioc =3D qio_channel_socket_new(); + tcp_chr_set_client_ioc_name(chr, sioc); + qio_channel_socket_connect_async(sioc, s->addr, + qemu_chr_socket_connected, + chr, NULL, chr->gcontext); +} + static gboolean socket_reconnect_timeout(gpointer opaque) { Chardev *chr =3D CHARDEV(opaque); SocketChardev *s =3D SOCKET_CHARDEV(opaque); - QIOChannelSocket *sioc; =20 g_source_unref(s->reconnect_timer); s->reconnect_timer =3D NULL; @@ -914,11 +925,7 @@ static gboolean socket_reconnect_timeout(gpointer opaq= ue) return false; } =20 - sioc =3D qio_channel_socket_new(); - tcp_chr_set_client_ioc_name(chr, sioc); - qio_channel_socket_connect_async(sioc, s->addr, - qemu_chr_socket_connected, - chr, NULL, NULL); + tcp_chr_connect_async(chr); =20 return false; } @@ -998,11 +1005,7 @@ static void qmp_chardev_open_socket(Chardev *chr, } =20 if (s->reconnect_time) { - sioc =3D qio_channel_socket_new(); - tcp_chr_set_client_ioc_name(chr, sioc); - qio_channel_socket_connect_async(sioc, s->addr, - qemu_chr_socket_connected, - chr, NULL, NULL); + tcp_chr_connect_async(chr); } else { if (s->is_listen) { char *name; --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520314919011285.7332571279676; Mon, 5 Mar 2018 21:41:59 -0800 (PST) Received: from localhost ([::1]:53619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5MH-0007YZ-B4 for importer@patchew.org; Tue, 06 Mar 2018 00:41:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Ee-00017n-Pb for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5Ed-0006uC-Sf for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:00 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41358 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 1et5Ed-0006tz-O4 for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:33:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5803E4001416 for ; Tue, 6 Mar 2018 05:33:59 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24BC6AFD5E; Tue, 6 Mar 2018 05:33:56 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:18 +0800 Message-Id: <20180306053320.15401-8-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:33:59 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 7/9] chardev: tcp: postpone async connection setup 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch allows the socket chardev async connection be setup with non-default gcontext. We do it by postponing the setup to machine done, since until then we can know which context we should run the async operation on. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ce5adad9a..165612845a 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1004,9 +1004,8 @@ static void qmp_chardev_open_socket(Chardev *chr, s->reconnect_time =3D reconnect; } =20 - if (s->reconnect_time) { - tcp_chr_connect_async(chr); - } else { + /* If reconnect_time is set, will do that in chr_machine_done. */ + if (!s->reconnect_time) { if (s->is_listen) { char *name; s->listener =3D qio_net_listener_new(); @@ -1138,6 +1137,17 @@ char_socket_get_connected(Object *obj, Error **errp) return s->connected; } =20 +static int tcp_chr_machine_done_hook(Chardev *chr) +{ + SocketChardev *s =3D SOCKET_CHARDEV(chr); + + if (s->reconnect_time) { + tcp_chr_connect_async(chr); + } + + return 0; +} + static void char_socket_class_init(ObjectClass *oc, void *data) { ChardevClass *cc =3D CHARDEV_CLASS(oc); @@ -1153,6 +1163,7 @@ static void char_socket_class_init(ObjectClass *oc, v= oid *data) cc->chr_add_client =3D tcp_chr_add_client; cc->chr_add_watch =3D tcp_chr_add_watch; cc->chr_update_read_handler =3D tcp_chr_update_read_handler; + cc->chr_machine_done =3D tcp_chr_machine_done_hook; =20 object_class_property_add(oc, "addr", "SocketAddress", char_socket_get_addr, NULL, --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 152031469303397.16724398215536; Mon, 5 Mar 2018 21:38:13 -0800 (PST) Received: from localhost ([::1]:53596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Ii-00043W-AF for importer@patchew.org; Tue, 06 Mar 2018 00:38:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Eh-0001AP-Cz for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5Eg-0006vP-LL for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:03 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41362 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 1et5Eg-0006vH-GM for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:02 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1627B4001416 for ; Tue, 6 Mar 2018 05:34:02 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7BCAAFD5E; Tue, 6 Mar 2018 05:33:59 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:19 +0800 Message-Id: <20180306053320.15401-9-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:34:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 06 Mar 2018 05:34:02 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 8/9] chardev: tcp: let TLS run on chardev context 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now qio_channel_tls_handshake() is ready to receive the context. Let socket chardev use it, then the TLS handshake of chardev will always be with the chardev's context. Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 --- chardev/char-socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 165612845a..bd40864f87 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -750,7 +750,7 @@ static void tcp_chr_tls_init(Chardev *chr) tcp_chr_tls_handshake, chr, NULL, - NULL); + chr->gcontext); } =20 =20 --=20 2.14.3 From nobody Fri Oct 24 21:59:46 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 152031482681674.47993851615888; Mon, 5 Mar 2018 21:40:26 -0800 (PST) Received: from localhost ([::1]:53607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Ks-0006HL-3M for importer@patchew.org; Tue, 06 Mar 2018 00:40:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1et5Em-0001C3-Dt for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1et5Ej-0006wG-At for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52478 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 1et5Ej-0006wA-6l for qemu-devel@nongnu.org; Tue, 06 Mar 2018 00:34:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7F578182D1E for ; Tue, 6 Mar 2018 05:34:04 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96012AFD5E; Tue, 6 Mar 2018 05:34:02 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 13:33:20 +0800 Message-Id: <20180306053320.15401-10-peterx@redhat.com> In-Reply-To: <20180306053320.15401-1-peterx@redhat.com> References: <20180306053320.15401-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:34:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 06 Mar 2018 05:34:04 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 9/9] chardev: tcp: postpone TLS work until machine done 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: Paolo Bonzini , peterx@redhat.com, Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" TLS handshake may create background GSource tasks, while we won't know the correct GMainContext until the whole chardev (including frontend) inited. Let's postpone the initial TLS handshake until machine done. For dynamically created tcp chardev, we don't postpone that by checking the init_machine_done variable. Signed-off-by: Peter Xu Acked-by: Stefan Hajnoczi --- chardev/char-socket.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index bd40864f87..997c70dd7d 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -31,6 +31,7 @@ #include "qemu/option.h" #include "qapi/error.h" #include "qapi/clone-visitor.h" +#include "sysemu/sysemu.h" =20 #include "chardev/char-io.h" =20 @@ -722,6 +723,11 @@ static void tcp_chr_tls_init(Chardev *chr) Error *err =3D NULL; gchar *name; =20 + if (!machine_init_done) { + /* This will be postponed to machine_done notifier */ + return; + } + if (s->is_listen) { tioc =3D qio_channel_tls_new_server( s->ioc, s->tls_creds, @@ -1145,6 +1151,10 @@ static int tcp_chr_machine_done_hook(Chardev *chr) tcp_chr_connect_async(chr); } =20 + if (s->tls_creds) { + tcp_chr_tls_init(chr); + } + return 0; } =20 --=20 2.14.3