From patchwork Thu Mar 1 08:44:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsQy76K77z9s1X for ; Thu, 1 Mar 2018 19:46:07 +1100 (AEDT) Received: from localhost ([::1]:48922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqn-00085Z-Ii for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:46:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52331) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJpf-0007c7-34 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:44:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJpe-0006ly-BP for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:44:55 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39586 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 1erJpe-0006lo-77 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:44: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 C28768D6F1 for ; Thu, 1 Mar 2018 08:44:53 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 77C3C9C055; Thu, 1 Mar 2018 08:44:50 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:24 +0800 Message-Id: <20180301084438.13594-2-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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]); Thu, 01 Mar 2018 08:44:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 01 Mar 2018 08:44: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 01/15] 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Need to free TCPChardevTelnetInit when session established. Since at it, switch to use G_SOURCE_* macros. Reviewed-by: Daniel P. Berrange Signed-off-by: Peter Xu --- 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 bdd6cff5f6..43a2cc2c1c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -591,19 +591,23 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc, ret = 0; } else { tcp_chr_disconnect(init->chr); - return FALSE; + goto end; } } init->buflen -= ret; if (init->buflen == 0) { tcp_chr_connect(init->chr); - return FALSE; + goto end; } memmove(init->buf, init->buf + ret, init->buflen); - return TRUE; + return G_SOURCE_CONTINUE; + +end: + g_free(init); + return G_SOURCE_REMOVE; } static void tcp_chr_telnet_init(Chardev *chr) From patchwork Thu Mar 1 08:44:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR3n0jJZz9s1S for ; Thu, 1 Mar 2018 19:51:01 +1100 (AEDT) Received: from localhost ([::1]:48943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJvX-0003S4-3o for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:50:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJpn-0007iI-61 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJpi-0006qZ-9q for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:03 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42056 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 1erJpi-0006qD-5u for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:44:58 -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 B1ECEEAEAB for ; Thu, 1 Mar 2018 08:44:57 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 597189C04F; Thu, 1 Mar 2018 08:44:54 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:25 +0800 Message-Id: <20180301084438.13594-3-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:44:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:44:57 +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 02/15] qio: rename qio_task_thread_result 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It is strange that it was called gio_task_thread_result. Rename it to follow the naming rule of the file. Reviewed-by: Daniel P. Berrange Signed-off-by: Peter Xu --- io/task.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/task.c b/io/task.c index 3ce556017c..1a0a1c7185 100644 --- a/io/task.c +++ b/io/task.c @@ -80,7 +80,7 @@ struct QIOTaskThreadData { }; -static gboolean gio_task_thread_result(gpointer opaque) +static gboolean qio_task_thread_result(gpointer opaque) { struct QIOTaskThreadData *data = opaque; @@ -110,7 +110,7 @@ static gpointer qio_task_thread_worker(gpointer opaque) * the worker results */ trace_qio_task_thread_exit(data->task); - g_idle_add(gio_task_thread_result, data); + g_idle_add(qio_task_thread_result, data); return NULL; } From patchwork Thu Mar 1 08:44:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR701wbZz9s1X for ; Thu, 1 Mar 2018 19:53:48 +1100 (AEDT) Received: from localhost ([::1]:48960 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJyE-0005xq-7x for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:53:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52466) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJpz-0007up-PA for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJpt-000705-Ln for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:15 -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 1erJpt-0006z6-EK for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:09 -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 65D0F80AD238 for ; Thu, 1 Mar 2018 08:45:08 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 520999C04F; Thu, 1 Mar 2018 08:44:58 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:26 +0800 Message-Id: <20180301084438.13594-4-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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]); Thu, 01 Mar 2018 08:45:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 08:45:08 +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 03/15] qio: introduce qio_channel_add_watch_{full|source} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Firstly, introduce an internal qio_channel_add_watch_full(), which enhances qio_channel_add_watch() that context can be specified. Then add a new API wrapper qio_channel_add_watch_source() to return a GSource pointer rather than a tag ID. Note that the _source() call will keep a reference of GSource so that callers need to unref them explicitly when finished using the GSource. Signed-off-by: Peter Xu Reviewed-by: Daniel P. Berrangé --- include/io/channel.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ io/channel.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 78 insertions(+), 6 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 3995e243a3..e8cdadb0b0 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -648,6 +648,50 @@ guint qio_channel_add_watch(QIOChannel *ioc, gpointer user_data, GDestroyNotify notify); +/** + * qio_channel_add_watch_full: + * @ioc: the channel object + * @condition: the I/O condition to monitor + * @func: callback to invoke when the source becomes ready + * @user_data: opaque data to pass to @func + * @notify: callback to free @user_data + * @context: the context to run the watch source + * + * Similar as qio_channel_add_watch(), but allows to specify context + * to run the watch source. + * + * Returns: the source ID + */ +guint qio_channel_add_watch_full(QIOChannel *ioc, + GIOCondition condition, + QIOChannelFunc func, + gpointer user_data, + GDestroyNotify notify, + GMainContext *context); + +/** + * qio_channel_add_watch_source: + * @ioc: the channel object + * @condition: the I/O condition to monitor + * @func: callback to invoke when the source becomes ready + * @user_data: opaque data to pass to @func + * @notify: callback to free @user_data + * @context: gcontext to bind the source to + * + * Similar as qio_channel_add_watch(), but allows to specify context + * to run the watch source, meanwhile return the GSource object + * instead of tag ID, with the GSource referenced already. + * + * Note: callers is responsible to unref the source when not needed. + * + * Returns: the source pointer + */ +GSource *qio_channel_add_watch_source(QIOChannel *ioc, + GIOCondition condition, + QIOChannelFunc func, + gpointer user_data, + GDestroyNotify notify, + GMainContext *context); /** * qio_channel_attach_aio_context: diff --git a/io/channel.c b/io/channel.c index ec4b86de7c..8dd0684f5d 100644 --- a/io/channel.c +++ b/io/channel.c @@ -299,11 +299,12 @@ void qio_channel_set_aio_fd_handler(QIOChannel *ioc, klass->io_set_aio_fd_handler(ioc, ctx, io_read, io_write, opaque); } -guint qio_channel_add_watch(QIOChannel *ioc, - GIOCondition condition, - QIOChannelFunc func, - gpointer user_data, - GDestroyNotify notify) +guint qio_channel_add_watch_full(QIOChannel *ioc, + GIOCondition condition, + QIOChannelFunc func, + gpointer user_data, + GDestroyNotify notify, + GMainContext *context) { GSource *source; guint id; @@ -312,12 +313,39 @@ guint qio_channel_add_watch(QIOChannel *ioc, g_source_set_callback(source, (GSourceFunc)func, user_data, notify); - id = g_source_attach(source, NULL); + id = g_source_attach(source, context); g_source_unref(source); return id; } +guint qio_channel_add_watch(QIOChannel *ioc, + GIOCondition condition, + QIOChannelFunc func, + gpointer user_data, + GDestroyNotify notify) +{ + return qio_channel_add_watch_full(ioc, condition, func, + user_data, notify, NULL); +} + +GSource *qio_channel_add_watch_source(QIOChannel *ioc, + GIOCondition condition, + QIOChannelFunc func, + gpointer user_data, + GDestroyNotify notify, + GMainContext *context) +{ + GSource *source; + guint id; + + id = qio_channel_add_watch_full(ioc, condition, func, + user_data, notify, context); + source = g_main_context_find_source_by_id(context, id); + g_source_ref(source); + return source; +} + int qio_channel_shutdown(QIOChannel *ioc, QIOChannelShutdown how, From patchwork Thu Mar 1 08:44:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsQxw55Bhz9s1S for ; Thu, 1 Mar 2018 19:45:56 +1100 (AEDT) Received: from localhost ([::1]:48918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqc-0007wW-Oq for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:45:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJpz-0007uj-KV for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJpy-00075G-G6 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:15 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41594 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 1erJpx-00074N-UT for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:14 -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 25CC94040852 for ; Thu, 1 Mar 2018 08:45:13 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E0F29C04A; Thu, 1 Mar 2018 08:45:08 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:27 +0800 Message-Id: <20180301084438.13594-5-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.5]); Thu, 01 Mar 2018 08:45:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 01 Mar 2018 08:45:13 +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 04/15] migration: let incoming side use thread 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: Laurent Vivier , Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The old incoming migration is running in main thread and default gcontext. With the new qio_channel_add_watch_full() we can now let it run in the thread's own gcontext (if there is one). Currently this patch does nothing alone. But when any of the incoming migration is run in another iothread (e.g., the upcoming migrate-recover command), this patch will bind the incoming logic to the iothread instead of the main thread (which may already get page faulted and hanged). RDMA is not considered for now since it's not even using the QIO watch framework at all. CC: Juan Quintela CC: Dr. David Alan Gilbert CC: Laurent Vivier Signed-off-by: Peter Xu --- migration/exec.c | 9 ++++----- migration/fd.c | 9 ++++----- migration/socket.c | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/migration/exec.c b/migration/exec.c index 0bc5a427dd..9d0f82f1f0 100644 --- a/migration/exec.c +++ b/migration/exec.c @@ -65,9 +65,8 @@ void exec_start_incoming_migration(const char *command, Error **errp) } qio_channel_set_name(ioc, "migration-exec-incoming"); - qio_channel_add_watch(ioc, - G_IO_IN, - exec_accept_incoming_migration, - NULL, - NULL); + qio_channel_add_watch_full(ioc, G_IO_IN, + exec_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); } diff --git a/migration/fd.c b/migration/fd.c index cd06182d1e..9a380bbbc4 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -66,9 +66,8 @@ void fd_start_incoming_migration(const char *infd, Error **errp) } qio_channel_set_name(QIO_CHANNEL(ioc), "migration-fd-incoming"); - qio_channel_add_watch(ioc, - G_IO_IN, - fd_accept_incoming_migration, - NULL, - NULL); + qio_channel_add_watch_full(ioc, G_IO_IN, + fd_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); } diff --git a/migration/socket.c b/migration/socket.c index e090097077..60d732535c 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -173,11 +173,11 @@ static void socket_start_incoming_migration(SocketAddress *saddr, return; } - qio_channel_add_watch(QIO_CHANNEL(listen_ioc), - G_IO_IN, - socket_accept_incoming_migration, - listen_ioc, - (GDestroyNotify)object_unref); + qio_channel_add_watch_full(QIO_CHANNEL(listen_ioc), G_IO_IN, + socket_accept_incoming_migration, + listen_ioc, + (GDestroyNotify)object_unref, + g_main_context_get_thread_default()); } void tcp_start_incoming_migration(const char *host_port, Error **errp) From patchwork Thu Mar 1 08:44:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR1j6TcGz9s1S for ; Thu, 1 Mar 2018 19:49:13 +1100 (AEDT) Received: from localhost ([::1]:48931 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJtn-0001sM-OW for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:49:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJq3-0007y2-KX for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJq2-00078J-Hp for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:19 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42074 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 1erJq2-00077S-34 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:18 -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 7E744EB6EF for ; Thu, 1 Mar 2018 08:45:17 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAEA49C05A; Thu, 1 Mar 2018 08:45:13 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:28 +0800 Message-Id: <20180301084438.13594-6-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:45:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:45:17 +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 05/15] qio: refactor net listener source operations 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Three functions are abstracted from the old code: - qio_net_listener_source_add(): create one source for listener - qio_net_listener_sources_clear(): unset existing net lister sources - qio_net_listener_sources_update(): setup all sources for listener Use them where possible. Signed-off-by: Peter Xu --- io/net-listener.c | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/io/net-listener.c b/io/net-listener.c index de38dfae99..3e9ac51b0e 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -106,6 +106,39 @@ int qio_net_listener_open_sync(QIONetListener *listener, } } +static guint qio_net_listener_source_add(QIONetListener *listener, + QIOChannelSocket *sioc) +{ + return qio_channel_add_watch(QIO_CHANNEL(sioc), G_IO_IN, + qio_net_listener_channel_func, + listener, (GDestroyNotify)object_unref); +} + +static void qio_net_listener_sources_clear(QIONetListener *listener) +{ + size_t i; + + for (i = 0; i < listener->nsioc; i++) { + if (listener->io_tag[i]) { + g_source_remove(listener->io_tag[i]); + listener->io_tag[i] = 0; + } + } +} + +static void qio_net_listener_sources_update(QIONetListener *listener) +{ + size_t i; + + if (listener->io_func != NULL) { + for (i = 0; i < listener->nsioc; i++) { + assert(listener->io_tag[i] == 0); + object_ref(OBJECT(listener)); + listener->io_tag[i] = qio_net_listener_source_add( + listener, listener->sioc[i]); + } + } +} void qio_net_listener_add(QIONetListener *listener, QIOChannelSocket *sioc) @@ -127,10 +160,8 @@ void qio_net_listener_add(QIONetListener *listener, if (listener->io_func != NULL) { object_ref(OBJECT(listener)); - listener->io_tag[listener->nsioc] = qio_channel_add_watch( - QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + listener->io_tag[listener->nsioc] = qio_net_listener_source_add( + listener, listener->sioc[listener->nsioc]); } listener->nsioc++; @@ -142,8 +173,6 @@ void qio_net_listener_set_client_func(QIONetListener *listener, gpointer data, GDestroyNotify notify) { - size_t i; - if (listener->io_notify) { listener->io_notify(listener->io_data); } @@ -151,22 +180,8 @@ void qio_net_listener_set_client_func(QIONetListener *listener, listener->io_data = data; listener->io_notify = notify; - for (i = 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] = 0; - } - } - - if (listener->io_func != NULL) { - for (i = 0; i < listener->nsioc; i++) { - object_ref(OBJECT(listener)); - listener->io_tag[i] = qio_channel_add_watch( - QIO_CHANNEL(listener->sioc[i]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); - } - } + qio_net_listener_sources_clear(listener); + qio_net_listener_sources_update(listener); } @@ -210,12 +225,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener) }; size_t i; - for (i = 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] = 0; - } - } + qio_net_listener_sources_clear(listener); sources = g_new0(GSource *, listener->nsioc); for (i = 0; i < listener->nsioc; i++) { @@ -238,15 +248,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); - if (listener->io_func != NULL) { - for (i = 0; i < listener->nsioc; i++) { - object_ref(OBJECT(listener)); - listener->io_tag[i] = qio_channel_add_watch( - QIO_CHANNEL(listener->sioc[i]), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); - } - } + qio_net_listener_sources_update(listener); return data.sioc; } @@ -259,11 +261,9 @@ void qio_net_listener_disconnect(QIONetListener *listener) return; } + qio_net_listener_sources_clear(listener); + for (i = 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] = 0; - } qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL); } listener->connected = false; From patchwork Thu Mar 1 08:44:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR1y3YcRz9s1S for ; Thu, 1 Mar 2018 19:49:26 +1100 (AEDT) Received: from localhost ([::1]:48933 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJu0-00025K-Gb for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:49:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52514) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqH-0008A7-Op for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqC-0007CD-Rr for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42100 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 1erJqC-0007C4-JU for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:28 -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 07AC4FB640 for ; Thu, 1 Mar 2018 08:45:28 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37C879C04A; Thu, 1 Mar 2018 08:45:17 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:29 +0800 Message-Id: <20180301084438.13594-7-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:45:28 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:45:28 +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 06/15] qio: store gsources for net listeners 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Originally we were storing the GSources tag IDs. That'll be not enough if we are going to support non-default gcontext for QIO code. Switch to GSources without changing anything real. Now we still always pass in NULL, which means the default gcontext. Signed-off-by: Peter Xu Reviewed-by: Daniel P. Berrangé --- include/io/net-listener.h | 21 ++++++++++++++-- io/net-listener.c | 62 +++++++++++++++++++++++++++++------------------ 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 56d6da7a76..566be283b3 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -53,7 +53,7 @@ struct QIONetListener { char *name; QIOChannelSocket **sioc; - gulong *io_tag; + GSource **io_source; size_t nsioc; bool connected; @@ -120,17 +120,34 @@ void qio_net_listener_add(QIONetListener *listener, QIOChannelSocket *sioc); /** - * qio_net_listener_set_client_func: + * qio_net_listener_set_client_func_full: * @listener: the network listener object * @func: the callback function * @data: opaque data to pass to @func * @notify: callback to free @data + * @context: the context that the sources will be bound to * * Register @func to be invoked whenever a new client * connects to the listener. @func will be invoked * passing in the QIOChannelSocket instance for the * client. */ +void qio_net_listener_set_client_func_full(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context); + +/** + * qio_net_listener_set_client_func: + * @listener: the network listener object + * @func: the callback function + * @data: opaque data to pass to @func + * @notify: callback to free @data + * + * Wrapper of qio_net_listener_set_client_func_full(), only that the + * sources will always be bound to default main context. + */ void qio_net_listener_set_client_func(QIONetListener *listener, QIONetListenerClientFunc func, gpointer data, diff --git a/io/net-listener.c b/io/net-listener.c index 3e9ac51b0e..14fd47db6c 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -106,12 +106,15 @@ int qio_net_listener_open_sync(QIONetListener *listener, } } -static guint qio_net_listener_source_add(QIONetListener *listener, - QIOChannelSocket *sioc) +static GSource *qio_net_listener_source_add(QIONetListener *listener, + QIOChannelSocket *sioc, + GMainContext *context) { - return qio_channel_add_watch(QIO_CHANNEL(sioc), G_IO_IN, - qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + return qio_channel_add_watch_source(QIO_CHANNEL(sioc), G_IO_IN, + qio_net_listener_channel_func, + listener, + (GDestroyNotify)object_unref, + context); } static void qio_net_listener_sources_clear(QIONetListener *listener) @@ -119,23 +122,25 @@ static void qio_net_listener_sources_clear(QIONetListener *listener) size_t i; for (i = 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] = 0; + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] = NULL; } } } -static void qio_net_listener_sources_update(QIONetListener *listener) +static void qio_net_listener_sources_update(QIONetListener *listener, + GMainContext *context) { size_t i; if (listener->io_func != NULL) { for (i = 0; i < listener->nsioc; i++) { - assert(listener->io_tag[i] == 0); + assert(listener->io_source[i] == NULL); object_ref(OBJECT(listener)); - listener->io_tag[i] = qio_net_listener_source_add( - listener, listener->sioc[i]); + listener->io_source[i] = qio_net_listener_source_add( + listener, listener->sioc[i], context); } } } @@ -151,27 +156,30 @@ void qio_net_listener_add(QIONetListener *listener, listener->sioc = g_renew(QIOChannelSocket *, listener->sioc, listener->nsioc + 1); - listener->io_tag = g_renew(gulong, listener->io_tag, listener->nsioc + 1); + listener->io_source = g_renew(typeof(listener->io_source[0]), + listener->io_source, + listener->nsioc + 1); listener->sioc[listener->nsioc] = sioc; - listener->io_tag[listener->nsioc] = 0; + listener->io_source[listener->nsioc] = NULL; object_ref(OBJECT(sioc)); listener->connected = true; if (listener->io_func != NULL) { object_ref(OBJECT(listener)); - listener->io_tag[listener->nsioc] = qio_net_listener_source_add( - listener, listener->sioc[listener->nsioc]); + listener->io_source[listener->nsioc] = qio_net_listener_source_add( + listener, listener->sioc[listener->nsioc], NULL); } listener->nsioc++; } -void qio_net_listener_set_client_func(QIONetListener *listener, - QIONetListenerClientFunc func, - gpointer data, - GDestroyNotify notify) +void qio_net_listener_set_client_func_full(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify, + GMainContext *context) { if (listener->io_notify) { listener->io_notify(listener->io_data); @@ -181,9 +189,17 @@ void qio_net_listener_set_client_func(QIONetListener *listener, listener->io_notify = notify; qio_net_listener_sources_clear(listener); - qio_net_listener_sources_update(listener); + qio_net_listener_sources_update(listener, context); } +void qio_net_listener_set_client_func(QIONetListener *listener, + QIONetListenerClientFunc func, + gpointer data, + GDestroyNotify notify) +{ + qio_net_listener_set_client_func_full(listener, func, data, + notify, NULL); +} struct QIONetListenerClientWaitData { QIOChannelSocket *sioc; @@ -248,7 +264,7 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetListener *listener) g_main_loop_unref(loop); g_main_context_unref(ctxt); - qio_net_listener_sources_update(listener); + qio_net_listener_sources_update(listener, NULL); return data.sioc; } @@ -285,7 +301,7 @@ static void qio_net_listener_finalize(Object *obj) for (i = 0; i < listener->nsioc; i++) { object_unref(OBJECT(listener->sioc[i])); } - g_free(listener->io_tag); + g_free(listener->io_source); g_free(listener->sioc); g_free(listener->name); } From patchwork Thu Mar 1 08:44:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR536Xtlz9s1S for ; Thu, 1 Mar 2018 19:52:07 +1100 (AEDT) Received: from localhost ([::1]:48950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJwb-0004U5-W8 for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:52:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqI-0008AL-01 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqH-0007Dq-3D for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:34 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42110 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 1erJqG-0007DS-Rk for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:33 -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 29E9DFB650 for ; Thu, 1 Mar 2018 08:45:32 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id A36229C04A; Thu, 1 Mar 2018 08:45:28 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:30 +0800 Message-Id: <20180301084438.13594-8-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:45:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:45:32 +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 07/15] qio/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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Since at it, generalize a tcp_chr_net_listener_setup() helper function and clean up the old code a bit. Signed-off-by: Peter Xu --- chardev/char-socket.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 43a2cc2c1c..5cd20cc932 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -410,6 +410,19 @@ static void update_disconnected_filename(SocketChardev *s) s->is_listen, s->is_telnet); } +/* Set enable=true to start net listeners, false to stop them. */ +static void tcp_chr_net_listener_setup(SocketChardev *s, bool enable) +{ + Chardev *chr = CHARDEV(s); + + /* Net listeners' context will follow the Chardev's. */ + qio_net_listener_set_client_func_full(s->listener, + enable ? tcp_chr_accept : NULL, + enable ? chr : NULL, + NULL, + chr->gcontext); +} + /* NB may be called even if tcp_chr_connect has not been * reached, due to TLS or telnet initialization failure, * so can *not* assume s->connected == true @@ -422,8 +435,7 @@ static void tcp_chr_disconnect(Chardev *chr) tcp_chr_free_connection(chr); if (s->listener) { - qio_net_listener_set_client_func(s->listener, tcp_chr_accept, - chr, NULL); + tcp_chr_net_listener_setup(s, true); } update_disconnected_filename(s); if (emit_close) { @@ -559,6 +571,15 @@ static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); + 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. + */ + tcp_chr_net_listener_setup(s, true); + } + if (!s->connected) { return; } @@ -742,7 +763,7 @@ static int tcp_chr_new_client(Chardev *chr, QIOChannelSocket *sioc) qio_channel_set_delay(s->ioc, false); } if (s->listener) { - qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + tcp_chr_net_listener_setup(s, false); } if (s->tls_creds) { @@ -823,7 +844,7 @@ 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); + tcp_chr_net_listener_setup(s, false); object_unref(OBJECT(s->listener)); } if (s->tls_creds) { @@ -979,8 +1000,7 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } if (!s->ioc) { - qio_net_listener_set_client_func(s->listener, tcp_chr_accept, - chr, NULL); + tcp_chr_net_listener_setup(s, true); } } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; From patchwork Thu Mar 1 08:44:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR9p1rM1z9s1X for ; Thu, 1 Mar 2018 19:56:14 +1100 (AEDT) Received: from localhost ([::1]:48976 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erK0a-0008IC-Bz for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:56:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqL-0008Dy-TO for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqK-0007FZ-U4 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:37 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41356 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 1erJqK-0007FF-Mr for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:36 -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 09D27818AB1A for ; Thu, 1 Mar 2018 08:45:36 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8F299C04A; Thu, 1 Mar 2018 08:45:32 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:31 +0800 Message-Id: <20180301084438.13594-9-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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]); Thu, 01 Mar 2018 08:45:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 01 Mar 2018 08:45: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:'' 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 08/15] 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 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 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 5cd20cc932..6c3f1de013 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -59,6 +59,7 @@ typedef struct { bool is_listen; bool is_telnet; bool is_tn3270; + GSource *telnet_source; GSource *reconnect_timer; int64_t reconnect_time; @@ -69,6 +70,7 @@ typedef struct { OBJECT_CHECK(SocketChardev, (obj), TYPE_CHARDEV_SOCKET) static gboolean socket_reconnect_timeout(gpointer opaque); +static void tcp_chr_telnet_init(Chardev *chr); static void tcp_chr_reconn_timer_cancel(SocketChardev *s) { @@ -567,6 +569,15 @@ static void tcp_chr_connect(void *opaque) qemu_chr_be_event(chr, CHR_EVENT_OPENED); } +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 = NULL; + } +} + static void tcp_chr_update_read_handler(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); @@ -580,6 +591,11 @@ static void tcp_chr_update_read_handler(Chardev *chr) tcp_chr_net_listener_setup(s, true); } + if (s->telnet_source) { + tcp_chr_telnet_destroy(s); + tcp_chr_telnet_init(CHARDEV(s)); + } + if (!s->connected) { return; } @@ -604,6 +620,7 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc, gpointer user_data) { TCPChardevTelnetInit *init = user_data; + SocketChardev *s = SOCKET_CHARDEV(init->chr); ssize_t ret; ret = qio_channel_write(ioc, init->buf, init->buflen, NULL); @@ -628,6 +645,8 @@ static gboolean tcp_chr_telnet_init_io(QIOChannel *ioc, end: g_free(init); + g_source_unref(s->telnet_source); + s->telnet_source = NULL; return G_SOURCE_REMOVE; } @@ -667,10 +686,10 @@ static void tcp_chr_telnet_init(Chardev *chr) #undef IACSET - qio_channel_add_watch( - s->ioc, G_IO_OUT, - tcp_chr_telnet_init_io, - init, NULL); + s->telnet_source = qio_channel_add_watch_source(s->ioc, G_IO_OUT, + tcp_chr_telnet_init_io, + init, NULL, + chr->gcontext); } @@ -843,6 +862,7 @@ 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); if (s->listener) { tcp_chr_net_listener_setup(s, false); object_unref(OBJECT(s->listener)); From patchwork Thu Mar 1 08:44:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR5P4YRLz9s1S for ; Thu, 1 Mar 2018 19:52:25 +1100 (AEDT) Received: from localhost ([::1]:48953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJwt-0004gg-Ez for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:52:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqZ-0008Rh-Mr for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqU-0007Jr-PI for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:51 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41606 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 1erJqU-0007Ja-Jr for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:46 -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 24A454084FEC for ; Thu, 1 Mar 2018 08:45:46 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93C399C04A; Thu, 1 Mar 2018 08:45:36 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:32 +0800 Message-Id: <20180301084438.13594-10-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.5]); Thu, 01 Mar 2018 08:45:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 01 Mar 2018 08:45:46 +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 09/15] qio: non-default context for threaded qtask 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qio_task_run_in_thread() allows main thread to run blocking operations in the background. However it has an assumption on that it's always working with the default context. This patch tries to allow the threaded QIO task framework to run with non-default gcontext. Currently no functional change so far, so the QIOTasks are still always running on main context. Signed-off-by: Peter Xu Reviewed-by: Daniel P. Berrangé --- include/io/task.h | 6 ++++-- io/channel-socket.c | 9 ++++++--- io/dns-resolver.c | 3 ++- io/task.c | 20 ++++++++++++++++++-- tests/test-io-task.c | 2 ++ 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/include/io/task.h b/include/io/task.h index 6021f51336..9dbe3758d7 100644 --- a/include/io/task.h +++ b/include/io/task.h @@ -227,15 +227,17 @@ QIOTask *qio_task_new(Object *source, * @worker: the function to invoke in a thread * @opaque: opaque data to pass to @worker * @destroy: function to free @opaque + * @context: the context to run the complete hook * * Run a task in a background thread. When @worker * returns it will call qio_task_complete() in - * the main event thread context. + * the event thread context that provided. */ void qio_task_run_in_thread(QIOTask *task, QIOTaskWorker worker, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); /** * qio_task_complete: diff --git a/io/channel-socket.c b/io/channel-socket.c index 563e297357..4224ce323a 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -187,7 +187,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, qio_task_run_in_thread(task, qio_channel_socket_connect_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddress); + (GDestroyNotify)qapi_free_SocketAddress, + NULL); } @@ -245,7 +246,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *ioc, qio_task_run_in_thread(task, qio_channel_socket_listen_worker, addrCopy, - (GDestroyNotify)qapi_free_SocketAddress); + (GDestroyNotify)qapi_free_SocketAddress, + NULL); } @@ -321,7 +323,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc, qio_task_run_in_thread(task, qio_channel_socket_dgram_worker, data, - qio_channel_socket_dgram_worker_free); + qio_channel_socket_dgram_worker_free, + NULL); } diff --git a/io/dns-resolver.c b/io/dns-resolver.c index c072d121c3..75c2ca9c4a 100644 --- a/io/dns-resolver.c +++ b/io/dns-resolver.c @@ -233,7 +233,8 @@ void qio_dns_resolver_lookup_async(QIODNSResolver *resolver, qio_task_run_in_thread(task, qio_dns_resolver_lookup_worker, data, - qio_dns_resolver_lookup_data_free); + qio_dns_resolver_lookup_data_free, + NULL); } diff --git a/io/task.c b/io/task.c index 1a0a1c7185..2886a2c1bc 100644 --- a/io/task.c +++ b/io/task.c @@ -77,6 +77,7 @@ struct QIOTaskThreadData { QIOTaskWorker worker; gpointer opaque; GDestroyNotify destroy; + GMainContext *context; }; @@ -91,6 +92,10 @@ static gboolean qio_task_thread_result(gpointer opaque) data->destroy(data->opaque); } + if (data->context) { + g_main_context_unref(data->context); + } + g_free(data); return FALSE; @@ -100,6 +105,7 @@ static gboolean qio_task_thread_result(gpointer opaque) static gpointer qio_task_thread_worker(gpointer opaque) { struct QIOTaskThreadData *data = opaque; + GSource *idle; trace_qio_task_thread_run(data->task); data->worker(data->task, data->opaque); @@ -110,7 +116,11 @@ static gpointer qio_task_thread_worker(gpointer opaque) * the worker results */ trace_qio_task_thread_exit(data->task); - g_idle_add(qio_task_thread_result, data); + + idle = g_idle_source_new(); + g_source_set_callback(idle, qio_task_thread_result, data, NULL); + g_source_attach(idle, data->context); + return NULL; } @@ -118,15 +128,21 @@ static gpointer qio_task_thread_worker(gpointer opaque) void qio_task_run_in_thread(QIOTask *task, QIOTaskWorker worker, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { struct QIOTaskThreadData *data = g_new0(struct QIOTaskThreadData, 1); QemuThread thread; + if (context) { + g_main_context_ref(context); + } + data->task = task; data->worker = worker; data->opaque = opaque; data->destroy = destroy; + data->context = context; trace_qio_task_thread_start(task, worker, opaque); qemu_thread_create(&thread, diff --git a/tests/test-io-task.c b/tests/test-io-task.c index 141aa2c55d..bac1bb4e7a 100644 --- a/tests/test-io-task.c +++ b/tests/test-io-task.c @@ -187,6 +187,7 @@ static void test_task_thread_complete(void) qio_task_run_in_thread(task, test_task_thread_worker, &data, + NULL, NULL); g_main_loop_run(data.loop); @@ -228,6 +229,7 @@ static void test_task_thread_failure(void) qio_task_run_in_thread(task, test_task_thread_worker, &data, + NULL, NULL); g_main_loop_run(data.loop); From patchwork Thu Mar 1 08:44:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR8W6BHrz9s1X for ; Thu, 1 Mar 2018 19:55:07 +1100 (AEDT) Received: from localhost ([::1]:48966 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJzV-0007Bn-SB for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:55:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqZ-0008Rg-MI for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqY-0007LY-Jx for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:51 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39652 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 1erJqY-0007LI-E1 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:50 -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 0415B17CEF8 for ; Thu, 1 Mar 2018 08:45:50 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id B11A79C04F; Thu, 1 Mar 2018 08:45:46 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:33 +0800 Message-Id: <20180301084438.13594-11-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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]); Thu, 01 Mar 2018 08:45:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Thu, 01 Mar 2018 08:45:50 +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 10/15] qio: non-default context for async conn 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We have worked on qio_task_run_in_thread() already. Further, let qio_channel_socket_connect_async() pass that context to it. Signed-off-by: Peter Xu --- chardev/char-socket.c | 4 ++-- include/io/channel-socket.h | 4 +++- io/channel-socket.c | 5 +++-- migration/socket.c | 3 ++- tests/test-io-channel-socket.c | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 6c3f1de013..bd90680f5c 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -911,7 +911,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque) tcp_chr_set_client_ioc_name(chr, sioc); qio_channel_socket_connect_async(sioc, s->addr, qemu_chr_socket_connected, - chr, NULL); + chr, NULL, NULL); return false; } @@ -995,7 +995,7 @@ static void qmp_chardev_open_socket(Chardev *chr, tcp_chr_set_client_ioc_name(chr, sioc); qio_channel_socket_connect_async(sioc, s->addr, qemu_chr_socket_connected, - chr, NULL); + chr, NULL, NULL); } else { if (s->is_listen) { char *name; diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index 53801f6042..90f7227397 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -101,6 +101,7 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *ioc, * @callback: the function to invoke on completion * @opaque: user data to pass to @callback * @destroy: the function to free @opaque + * @context: the context to run the async task * * Attempt to connect to the address @addr. This method * will run in the background so the caller will regain @@ -113,7 +114,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); /** diff --git a/io/channel-socket.c b/io/channel-socket.c index 4224ce323a..a843e49939 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -173,7 +173,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task = qio_task_new( OBJECT(ioc), callback, opaque, destroy); @@ -188,7 +189,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc, qio_channel_socket_connect_worker, addrCopy, (GDestroyNotify)qapi_free_SocketAddress, - NULL); + context); } diff --git a/migration/socket.c b/migration/socket.c index 60d732535c..91071b06ef 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -103,7 +103,8 @@ static void socket_start_outgoing_migration(MigrationState *s, saddr, socket_outgoing_migration, data, - socket_connect_data_free); + socket_connect_data_free, + NULL); qapi_free_SocketAddress(saddr); } diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index d357cd2a8e..a67635b9b8 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -200,7 +200,7 @@ static void test_io_channel_setup_async(SocketAddress *listen_addr, qio_channel_socket_connect_async( QIO_CHANNEL_SOCKET(*src), connect_addr, - test_io_channel_complete, &data, NULL); + test_io_channel_complete, &data, NULL, NULL); g_main_loop_run(data.loop); g_main_context_iteration(g_main_context_default(), FALSE); From patchwork Thu Mar 1 08:44:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsQyv3QfPz9s1S for ; Thu, 1 Mar 2018 19:46:47 +1100 (AEDT) Received: from localhost ([::1]:48924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJrR-000064-FE for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:46:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqd-0008VZ-Ok for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqc-0007Nk-LJ for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45:55 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42120 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 1erJqc-0007NS-FM for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:45: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 D492F87ABA for ; Thu, 1 Mar 2018 08:45:53 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F5A59C04F; Thu, 1 Mar 2018 08:45:50 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:34 +0800 Message-Id: <20180301084438.13594-12-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:45:53 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:45: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 11/15] qio: non-default context for TLS handshake 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" qio_channel_tls_handshake_full() is introduced to allow the TLS to be run on a non-default context. Still, no functional change. Signed-off-by: Peter Xu --- include/io/channel-tls.h | 17 ++++++++++++++++ io/channel-tls.c | 51 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h index d157eb10e8..d6f5271088 100644 --- a/include/io/channel-tls.h +++ b/include/io/channel-tls.h @@ -128,6 +128,23 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc, gpointer opaque, GDestroyNotify destroy); +/** + * qio_channel_tls_handshake_full: + * @ioc: the TLS channel object + * @func: the callback to invoke when completed + * @opaque: opaque data to pass to @func + * @destroy: optional callback to free @opaque + * @context: the context that TLS handshake will run with + * + * Similar to qio_channel_tls_handshake(), but allows the task to be + * run on a specific context. + */ +void qio_channel_tls_handshake_full(QIOChannelTLS *ioc, + QIOTaskFunc func, + gpointer opaque, + GDestroyNotify destroy, + GMainContext *context); + /** * qio_channel_tls_get_session: * @ioc: the TLS channel object diff --git a/io/channel-tls.c b/io/channel-tls.c index 6182702dab..4fe03d9c6c 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -140,13 +140,19 @@ qio_channel_tls_new_client(QIOChannel *master, return NULL; } +struct QIOChannelTLSData { + QIOTask *task; + GMainContext *context; +}; +typedef struct QIOChannelTLSData QIOChannelTLSData; static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, GIOCondition condition, gpointer user_data); static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, - QIOTask *task) + QIOTask *task, + GMainContext *context) { Error *err = NULL; QCryptoTLSSessionHandshakeStatus status; @@ -171,6 +177,11 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, qio_task_complete(task); } else { GIOCondition condition; + QIOChannelTLSData *data = g_new0(typeof(*data), 1); + + data->task = task; + data->context = context; + if (status == QCRYPTO_TLS_HANDSHAKE_SENDING) { condition = G_IO_OUT; } else { @@ -178,11 +189,12 @@ static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, } trace_qio_channel_tls_handshake_pending(ioc, status); - qio_channel_add_watch(ioc->master, - condition, - qio_channel_tls_handshake_io, - task, - NULL); + qio_channel_add_watch_full(ioc->master, + condition, + qio_channel_tls_handshake_io, + data, + NULL, + context); } } @@ -191,20 +203,23 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, GIOCondition condition, gpointer user_data) { - QIOTask *task = user_data; + QIOChannelTLSData *data = user_data; + QIOTask *task = data->task; + GMainContext *context = data->context; QIOChannelTLS *tioc = QIO_CHANNEL_TLS( qio_task_get_source(task)); - qio_channel_tls_handshake_task( - tioc, task); + g_free(data); + qio_channel_tls_handshake_task(tioc, task, context); return FALSE; } -void qio_channel_tls_handshake(QIOChannelTLS *ioc, - QIOTaskFunc func, - gpointer opaque, - GDestroyNotify destroy) +void qio_channel_tls_handshake_full(QIOChannelTLS *ioc, + QIOTaskFunc func, + gpointer opaque, + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task; @@ -212,7 +227,15 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc, func, opaque, destroy); trace_qio_channel_tls_handshake_start(ioc); - qio_channel_tls_handshake_task(ioc, task); + qio_channel_tls_handshake_task(ioc, task, context); +} + +void qio_channel_tls_handshake(QIOChannelTLS *ioc, + QIOTaskFunc func, + gpointer opaque, + GDestroyNotify destroy) +{ + qio_channel_tls_handshake_full(ioc, func, opaque, destroy, NULL); } From patchwork Thu Mar 1 08:44:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR2h1lz3z9s1X for ; Thu, 1 Mar 2018 19:50:04 +1100 (AEDT) Received: from localhost ([::1]:48937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJuc-0002eF-7K for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:50:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqr-0000H0-KM for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqm-0007SV-Nk for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:09 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42126 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 1erJqm-0007SH-Hy for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:04 -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 159F887ABA for ; Thu, 1 Mar 2018 08:46:04 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B6E99C04A; Thu, 1 Mar 2018 08:45:54 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:35 +0800 Message-Id: <20180301084438.13594-13-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:46:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:46: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 12/15] 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. This notifier framework will be further leverged by other type of chardevs soon. Signed-off-by: Peter Xu Reviewed-by: Paolo Bonzini --- chardev/char-mux.c | 29 +++++++++++++++++++++++++++++ chardev/char.c | 43 +++++++++++++++++-------------------------- include/chardev/char.h | 2 ++ 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index d48e78103a..1379a9f254 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -347,6 +347,34 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend, mux->chardev = g_strdup(chardev); } +/** + * 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) +{ + /* Set it multiple times won't hurt */ + muxes_realized = true; + + /* 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 = CHARDEV_CLASS(oc); @@ -357,6 +385,7 @@ static void char_mux_class_init(ObjectClass *oc, void *data) cc->chr_accept_input = mux_chr_accept_input; cc->chr_add_watch = mux_chr_add_watch; cc->chr_be_event = mux_chr_be_event; + cc->chr_machine_done = open_muxes; } static const TypeInfo char_mux_type_info = { 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 = { .class_init = char_class_init, }; -/** - * 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 = (Chardev *)child; + ChardevClass *class = CHARDEV_GET_CLASS(chr); + + if (class->chr_machine_done) { + return class->chr_machine_done(chr); } return 0; } -static void muxes_realize_done(Notifier *notifier, void *unused) +static void chardev_machine_done_hook(Notifier *notifier, void *unused) { - muxes_realized = true; - object_child_foreach(get_chardevs_root(), open_muxes, NULL); + int ret = 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); + } } -static Notifier muxes_realize_notify = { - .notify = muxes_realize_done, +static Notifier chardev_machine_done_notify = { + .notify = chardev_machine_done_hook, }; 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 -nographic * is specified */ - qemu_add_machine_init_done_notifier(&muxes_realize_notify); + qemu_add_machine_init_done_notifier(&chardev_machine_done_notify); } 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; Chardev *qemu_chardev_new(const char *id, const char *typename, From patchwork Thu Mar 1 08:44:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsRDK2lFJz9s1X for ; Thu, 1 Mar 2018 19:58:25 +1100 (AEDT) Received: from localhost ([::1]:48984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erK2h-0001dh-Gt for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:58:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJqt-0000Im-BO for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJqs-0007Ud-Cs for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:11 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42128 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 1erJqs-0007UT-7T for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:10 -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 C643287ABA for ; Thu, 1 Mar 2018 08:46:09 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id A59799C04A; Thu, 1 Mar 2018 08:46:04 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:36 +0800 Message-Id: <20180301084438.13594-14-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.1]); Thu, 01 Mar 2018 08:46:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 01 Mar 2018 08:46:09 +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 13/15] char: 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Generalize the function to create the async QIO task connection. Also, fix the context pointer to use the chardev's gcontext. Signed-off-by: Peter Xu Reviewed-by: Paolo Bonzini --- 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 bd90680f5c..cd9db123f2 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -894,11 +894,22 @@ cleanup: object_unref(OBJECT(sioc)); } +static void tcp_chr_connect_async(Chardev *chr) +{ + SocketChardev *s = SOCKET_CHARDEV(chr); + QIOChannelSocket *sioc; + + sioc = 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 = CHARDEV(opaque); SocketChardev *s = SOCKET_CHARDEV(opaque); - QIOChannelSocket *sioc; g_source_unref(s->reconnect_timer); s->reconnect_timer = NULL; @@ -907,11 +918,7 @@ static gboolean socket_reconnect_timeout(gpointer opaque) return false; } - sioc = 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); return false; } @@ -991,11 +998,7 @@ static void qmp_chardev_open_socket(Chardev *chr, } if (s->reconnect_time) { - sioc = 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; From patchwork Thu Mar 1 08:44:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsRC557Pvz9s1X for ; Thu, 1 Mar 2018 19:57:21 +1100 (AEDT) Received: from localhost ([::1]:48980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erK1f-0000lf-Jq for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:57:19 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJrF-0000eP-GV for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJrC-0007m0-R4 for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41614 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 1erJrC-0007lb-Ko for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:30 -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 A339C404084B for ; Thu, 1 Mar 2018 08:46:13 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B2939C04A; Thu, 1 Mar 2018 08:46:10 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:37 +0800 Message-Id: <20180301084438.13594-15-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.5]); Thu, 01 Mar 2018 08:46:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 01 Mar 2018 08:46:20 +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 14/15] 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Peter Xu Reviewed-by: Paolo Bonzini --- 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 cd9db123f2..2b355fc7a8 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -997,9 +997,8 @@ static void qmp_chardev_open_socket(Chardev *chr, s->reconnect_time = reconnect; } - 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 = qio_net_listener_new(); @@ -1128,6 +1127,17 @@ char_socket_get_connected(Object *obj, Error **errp) return s->connected; } +static int tcp_chr_machine_done_hook(Chardev *chr) +{ + SocketChardev *s = 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 = CHARDEV_CLASS(oc); @@ -1143,6 +1153,7 @@ static void char_socket_class_init(ObjectClass *oc, void *data) cc->chr_add_client = tcp_chr_add_client; cc->chr_add_watch = tcp_chr_add_watch; cc->chr_update_read_handler = tcp_chr_update_read_handler; + cc->chr_machine_done = tcp_chr_machine_done_hook; object_class_property_add(oc, "addr", "SocketAddress", char_socket_get_addr, NULL, From patchwork Thu Mar 1 08:44:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 879649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zsR9F6XMmz9s1t for ; Thu, 1 Mar 2018 19:55:45 +1100 (AEDT) Received: from localhost ([::1]:48970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erK07-0007pm-Us for incoming@patchwork.ozlabs.org; Thu, 01 Mar 2018 03:55:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1erJrF-0000eO-GU for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1erJrA-0007k2-KQ for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36958 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 1erJrA-0007jo-FV for qemu-devel@nongnu.org; Thu, 01 Mar 2018 03:46:28 -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 E76DE4026789 for ; Thu, 1 Mar 2018 08:46:27 +0000 (UTC) Received: from xz-mi.redhat.com (ovpn-12-111.pek2.redhat.com [10.72.12.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4566C9C055; Thu, 1 Mar 2018 08:46:13 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Thu, 1 Mar 2018 16:44:38 +0800 Message-Id: <20180301084438.13594-16-peterx@redhat.com> In-Reply-To: <20180301084438.13594-1-peterx@redhat.com> References: <20180301084438.13594-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.6]); Thu, 01 Mar 2018 08:46:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Thu, 01 Mar 2018 08:46:27 +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 15/15] 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: Juan Quintela , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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. If we dynamically add tcp chardev, it won't be affected since we have a new tcp_chr_machine_done flag to know whether we should postpone it or not. Signed-off-by: Peter Xu --- chardev/char-socket.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 2b355fc7a8..13aeca0b27 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -72,6 +72,8 @@ typedef struct { static gboolean socket_reconnect_timeout(gpointer opaque); static void tcp_chr_telnet_init(Chardev *chr); +static bool tcp_chr_machine_done; + static void tcp_chr_reconn_timer_cancel(SocketChardev *s) { if (s->reconnect_timer) { @@ -719,6 +721,11 @@ static void tcp_chr_tls_init(Chardev *chr) Error *err = NULL; gchar *name; + if (!tcp_chr_machine_done) { + /* This will be postponed to machine_done notifier */ + return; + } + if (s->is_listen) { tioc = qio_channel_tls_new_server( s->ioc, s->tls_creds, @@ -1131,10 +1138,17 @@ static int tcp_chr_machine_done_hook(Chardev *chr) { SocketChardev *s = SOCKET_CHARDEV(chr); + /* Set it multiple times won't hurt */ + tcp_chr_machine_done = true; + if (s->reconnect_time) { tcp_chr_connect_async(chr); } + if (s->tls_creds) { + tcp_chr_tls_init(chr); + } + return 0; }