From nobody Fri Oct 24 21:59:51 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 152023277089350.439738733166905; Sun, 4 Mar 2018 22:52:50 -0800 (PST) Received: from localhost ([::1]:47443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjzF-0008UC-Ui for importer@patchew.org; Mon, 05 Mar 2018 01:52:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxa-0007UL-Q9 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxW-0001Ru-SH for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57620 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 1esjxW-0001R6-Nu for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39E4B402312B for ; Mon, 5 Mar 2018 06:50:51 +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 0B1102166BAE; Mon, 5 Mar 2018 06:50:48 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:32 +0800 Message-Id: <20180305065040.10353-2-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 06:50:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 06:50:51 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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 Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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:51 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 1520232770893894.2997959114126; Sun, 4 Mar 2018 22:52:50 -0800 (PST) Received: from localhost ([::1]:47442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjzF-0008UA-Kh for importer@patchew.org; Mon, 05 Mar 2018 01:52:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxa-0007UK-PR for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxW-0001Rp-SP for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36614 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 1esjxW-0001R5-OS for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7EB64040858 for ; Mon, 5 Mar 2018 06:50: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 B8CD22166BAE; Mon, 5 Mar 2018 06:50:51 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:33 +0800 Message-Id: <20180305065040.10353-3-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:50:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:50:53 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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 Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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:51 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 1520232904728430.22496840816007; Sun, 4 Mar 2018 22:55:04 -0800 (PST) Received: from localhost ([::1]:47454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk1W-0002Su-Vh for importer@patchew.org; Mon, 05 Mar 2018 01:55:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46542) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxa-0007UJ-Ow for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxZ-0001VZ-8V for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35598 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 1esjxZ-0001Ub-2l for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:50:57 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F5CA8D6C7 for ; Mon, 5 Mar 2018 06:50: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 72AFD2166BAE; Mon, 5 Mar 2018 06:50:54 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:34 +0800 Message-Id: <20180305065040.10353-4-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:50:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:50:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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-Transfer-Encoding: quoted-printable MIME-Version: 1.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. Signed-off-by: Peter Xu Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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:51 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 1520233164612147.4111056214242; Sun, 4 Mar 2018 22:59:24 -0800 (PST) Received: from localhost ([::1]:47477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk5X-0005zU-CJ for importer@patchew.org; Mon, 05 Mar 2018 01:59:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxe-0007Wx-Iq for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxd-0001Xt-Fr for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:02 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35600 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 1esjxd-0001Xf-AH for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:01 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D47518D6C7 for ; Mon, 5 Mar 2018 06:51:00 +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 9B1722166BAE; Mon, 5 Mar 2018 06:50:57 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:35 +0800 Message-Id: <20180305065040.10353-5-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:51:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:51:00 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- 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:51 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 1520232914916168.63356426377038; Sun, 4 Mar 2018 22:55:14 -0800 (PST) Received: from localhost ([::1]:47455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk1h-0002c3-Tf for importer@patchew.org; Mon, 05 Mar 2018 01:55:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxk-0007b7-4w for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxg-0001a6-6L for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36616 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 1esjxg-0001Zu-1U for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B7844040858 for ; Mon, 5 Mar 2018 06:51:03 +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 5D6FB2166BAE; Mon, 5 Mar 2018 06:51:01 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:36 +0800 Message-Id: <20180305065040.10353-6-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:51:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:51:03 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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. Reviewed-by: Paolo Bonzini Signed-off-by: Peter Xu --- chardev/char-mux.c | 33 +++++++++++++++++++++++++++++---- chardev/char.c | 43 +++++++++++++++++-------------------------- include/chardev/char.h | 2 ++ 3 files changed, 48 insertions(+), 30 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.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, --=20 2.14.3 From nobody Fri Oct 24 21:59:51 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 1520232783248766.9654818158808; Sun, 4 Mar 2018 22:53:03 -0800 (PST) Received: from localhost ([::1]:47444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjzV-0000Fy-MA for importer@patchew.org; Mon, 05 Mar 2018 01:52:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxk-0007b9-51 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxi-0001b0-Vn for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:08 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53490 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 1esjxi-0001aj-RO for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AF8640FB65A for ; Mon, 5 Mar 2018 06:51:06 +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 149C02166BAE; Mon, 5 Mar 2018 06:51:03 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:37 +0800 Message-Id: <20180305065040.10353-7-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:51:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:51:06 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- 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:51 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 1520232905961691.0690865628321; Sun, 4 Mar 2018 22:55:05 -0800 (PST) Received: from localhost ([::1]:47453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk1W-0002Sp-IG for importer@patchew.org; Mon, 05 Mar 2018 01:55:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxn-0007dh-3R for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxm-0001cO-86 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:11 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57630 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 1esjxm-0001c7-3d for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:10 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A3CB402314E for ; Mon, 5 Mar 2018 06:51:09 +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 587802166BAE; Mon, 5 Mar 2018 06:51:06 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:38 +0800 Message-Id: <20180305065040.10353-8-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 06:51:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 05 Mar 2018 06:51:09 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- 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:51 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 1520233307773807.944233316225; Sun, 4 Mar 2018 23:01:47 -0800 (PST) Received: from localhost ([::1]:47500 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esk83-0008Iv-0m for importer@patchew.org; Mon, 05 Mar 2018 02:01:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxp-0007fe-Jg for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxo-0001dE-UJ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:13 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36620 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 1esjxo-0001d6-Pm for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 54E1F4040858 for ; Mon, 5 Mar 2018 06:51:12 +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 238ED2166BAE; Mon, 5 Mar 2018 06:51:09 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:39 +0800 Message-Id: <20180305065040.10353-9-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:51:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:51:12 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- 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:51 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 1520232792383830.0359524705465; Sun, 4 Mar 2018 22:53:12 -0800 (PST) Received: from localhost ([::1]:47445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjzj-0000SY-Ie for importer@patchew.org; Mon, 05 Mar 2018 01:53:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjxv-0007kf-JH for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjxr-0001eF-MN for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:19 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53498 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 1esjxr-0001e0-HM for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:51:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1302140FB65A for ; Mon, 5 Mar 2018 06:51:15 +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 D92C22166BAE; Mon, 5 Mar 2018 06:51:12 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:50:40 +0800 Message-Id: <20180305065040.10353-10-peterx@redhat.com> In-Reply-To: <20180305065040.10353-1-peterx@redhat.com> References: <20180305065040.10353-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:51:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:51:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 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 --- 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