From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520232323899385.675673272483; Sun, 4 Mar 2018 22:45:23 -0800 (PST) Received: from localhost ([::1]:47407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjs6-0003hq-MB for importer@patchew.org; Mon, 05 Mar 2018 01:45:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqZ-0002je-60 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqU-0005oJ-AN for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:43 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:36512 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 1esjqU-0005nc-60 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:38 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C1174040852 for ; Mon, 5 Mar 2018 06:43:37 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7007C2024CAB; Mon, 5 Mar 2018 06:43:34 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:19 +0800 Message-Id: <20180305064324.9238-2-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:43:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 05 Mar 2018 06:43:37 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 1/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It 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 { }; =20 =20 -static gboolean gio_task_thread_result(gpointer opaque) +static gboolean qio_task_thread_result(gpointer opaque) { struct QIOTaskThreadData *data =3D opaque; =20 @@ -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; } =20 --=20 2.14.3 From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520232323953732.9662319230306; Sun, 4 Mar 2018 22:45:23 -0800 (PST) Received: from localhost ([::1]:47406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjs5-0003g5-LN for importer@patchew.org; Mon, 05 Mar 2018 01:45:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqZ-0002jf-5z for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqX-0005rb-Ji for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:43 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53390 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 1esjqX-0005r9-Ea for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0866B40FB64A for ; Mon, 5 Mar 2018 06:43:41 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 055B12024CAB; Mon, 5 Mar 2018 06:43:37 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:20 +0800 Message-Id: <20180305064324.9238-3-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:41 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 2/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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); =20 +/** + * 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); =20 /** * 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); } =20 -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, =20 g_source_set_callback(source, (GSourceFunc)func, user_data, notify); =20 - id =3D g_source_attach(source, NULL); + id =3D g_source_attach(source, context); g_source_unref(source); =20 return id; } =20 +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 =3D qio_channel_add_watch_full(ioc, condition, func, + user_data, notify, context); + source =3D g_main_context_find_source_by_id(context, id); + g_source_ref(source); + return source; +} + =20 int qio_channel_shutdown(QIOChannel *ioc, QIOChannelShutdown how, --=20 2.14.3 From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520232447315382.14823527434544; Sun, 4 Mar 2018 22:47:27 -0800 (PST) Received: from localhost ([::1]:47421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esju7-0005GS-45 for importer@patchew.org; Mon, 05 Mar 2018 01:47:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqc-0002l7-BQ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqb-0005va-7k for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:46 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35398 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 1esjqb-0005v2-1p for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:45 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EC928D6C7 for ; Mon, 5 Mar 2018 06:43:44 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 865B52026E03; Mon, 5 Mar 2018 06:43:41 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:21 +0800 Message-Id: <20180305064324.9238-4-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:43:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 05 Mar 2018 06:43:44 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 3/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- include/io/net-listener.h | 22 ++++++++++++++++-- io/net-listener.c | 58 +++++++++++++++++++++++++++++--------------= ---- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/include/io/net-listener.h b/include/io/net-listener.h index 56d6da7a76..8081ac58a2 100644 --- a/include/io/net-listener.h +++ b/include/io/net-listener.h @@ -53,7 +53,7 @@ struct QIONetListener { =20 char *name; QIOChannelSocket **sioc; - gulong *io_tag; + GSource **io_source; size_t nsioc; =20 bool connected; @@ -120,17 +120,35 @@ void qio_net_listener_add(QIONetListener *listener, QIOChannelSocket *sioc); =20 /** - * 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. If %NULL, + * the default context will be used. * * 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 de38dfae99..555e8acaa4 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -118,29 +118,32 @@ void qio_net_listener_add(QIONetListener *listener, =20 listener->sioc =3D g_renew(QIOChannelSocket *, listener->sioc, listener->nsioc + 1); - listener->io_tag =3D g_renew(gulong, listener->io_tag, listener->nsioc= + 1); + listener->io_source =3D g_renew(typeof(listener->io_source[0]), + listener->io_source, + listener->nsioc + 1); listener->sioc[listener->nsioc] =3D sioc; - listener->io_tag[listener->nsioc] =3D 0; + listener->io_source[listener->nsioc] =3D NULL; =20 object_ref(OBJECT(sioc)); listener->connected =3D true; =20 if (listener->io_func !=3D NULL) { object_ref(OBJECT(listener)); - listener->io_tag[listener->nsioc] =3D qio_channel_add_watch( + listener->io_source[listener->nsioc] =3D qio_channel_add_watch_sou= rce( QIO_CHANNEL(listener->sioc[listener->nsioc]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + listener, (GDestroyNotify)object_unref, NULL); } =20 listener->nsioc++; } =20 =20 -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) { size_t i; =20 @@ -152,23 +155,32 @@ void qio_net_listener_set_client_func(QIONetListener = *listener, listener->io_notify =3D notify; =20 for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] =3D 0; + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] =3D NULL; } } =20 if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); - listener->io_tag[i] =3D qio_channel_add_watch( + listener->io_source[i] =3D qio_channel_add_watch_source( QIO_CHANNEL(listener->sioc[i]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + listener, (GDestroyNotify)object_unref, context); } } } =20 +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); +} =20 struct QIONetListenerClientWaitData { QIOChannelSocket *sioc; @@ -211,9 +223,10 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONetL= istener *listener) size_t i; =20 for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] =3D 0; + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] =3D NULL; } } =20 @@ -241,10 +254,10 @@ QIOChannelSocket *qio_net_listener_wait_client(QIONet= Listener *listener) if (listener->io_func !=3D NULL) { for (i =3D 0; i < listener->nsioc; i++) { object_ref(OBJECT(listener)); - listener->io_tag[i] =3D qio_channel_add_watch( + listener->io_source[i] =3D qio_channel_add_watch_source( QIO_CHANNEL(listener->sioc[i]), G_IO_IN, qio_net_listener_channel_func, - listener, (GDestroyNotify)object_unref); + listener, (GDestroyNotify)object_unref, NULL); } } =20 @@ -260,9 +273,10 @@ void qio_net_listener_disconnect(QIONetListener *liste= ner) } =20 for (i =3D 0; i < listener->nsioc; i++) { - if (listener->io_tag[i]) { - g_source_remove(listener->io_tag[i]); - listener->io_tag[i] =3D 0; + if (listener->io_source[i]) { + g_source_destroy(listener->io_source[i]); + g_source_unref(listener->io_source[i]); + listener->io_source[i] =3D NULL; } qio_channel_close(QIO_CHANNEL(listener->sioc[i]), NULL); } @@ -285,7 +299,7 @@ static void qio_net_listener_finalize(Object *obj) for (i =3D 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); } --=20 2.14.3 From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152023253351123.373269975434823; Sun, 4 Mar 2018 22:48:53 -0800 (PST) Received: from localhost ([::1]:47428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjvY-0006FY-PM for importer@patchew.org; Mon, 05 Mar 2018 01:48:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqf-0002oa-Ve for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqe-00062c-Pn for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:50 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33754 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 1esjqe-00061J-K7 for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:48 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 19CC6814DF4C for ; Mon, 5 Mar 2018 06:43:48 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18A242024CAB; Mon, 5 Mar 2018 06:43:44 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:22 +0800 Message-Id: <20180305064324.9238-5-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 05 Mar 2018 06:43:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 05 Mar 2018 06:43:48 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 4/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Daniel P. Berrange Signed-off-by: Peter Xu --- include/io/task.h | 7 +++++-- io/channel-socket.c | 9 ++++++--- io/dns-resolver.c | 3 ++- io/task.c | 20 ++++++++++++++++++-- tests/test-io-task.c | 2 ++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/io/task.h b/include/io/task.h index 6021f51336..9e09b95b2e 100644 --- a/include/io/task.h +++ b/include/io/task.h @@ -227,15 +227,18 @@ 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. If %NULL, the + * default context will be used. * * 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); =20 /** * 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); } =20 =20 @@ -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); } =20 =20 @@ -321,7 +323,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *i= oc, 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); } =20 =20 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 *reso= lver, 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); } =20 =20 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; }; =20 =20 @@ -91,6 +92,10 @@ static gboolean qio_task_thread_result(gpointer opaque) data->destroy(data->opaque); } =20 + if (data->context) { + g_main_context_unref(data->context); + } + g_free(data); =20 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 =3D opaque; + GSource *idle; =20 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 =3D g_idle_source_new(); + g_source_set_callback(idle, qio_task_thread_result, data, NULL); + g_source_attach(idle, data->context); + return NULL; } =20 @@ -118,15 +128,21 @@ static gpointer qio_task_thread_worker(gpointer opaqu= e) void qio_task_run_in_thread(QIOTask *task, QIOTaskWorker worker, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { struct QIOTaskThreadData *data =3D g_new0(struct QIOTaskThreadData, 1); QemuThread thread; =20 + if (context) { + g_main_context_ref(context); + } + data->task =3D task; data->worker =3D worker; data->opaque =3D opaque; data->destroy =3D destroy; + data->context =3D context; =20 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); =20 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); =20 g_main_loop_run(data.loop); --=20 2.14.3 From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520232607608780.7648371861337; Sun, 4 Mar 2018 22:50:07 -0800 (PST) Received: from localhost ([::1]:47431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjwk-00071S-RI for importer@patchew.org; Mon, 05 Mar 2018 01:50:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqo-00034c-So for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:44:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqi-00068C-MJ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53396 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 1esjqi-00067b-Gw for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17D8B40FB64A for ; Mon, 5 Mar 2018 06:43:52 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9901C2024CAB; Mon, 5 Mar 2018 06:43:48 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:23 +0800 Message-Id: <20180305064324.9238-6-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 5/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We have worked on qio_task_run_in_thread() already. Further, let all the qio channel APIs use that context. Signed-off-by: Peter Xu --- chardev/char-socket.c | 4 ++-- include/io/channel-socket.h | 15 ++++++++++++--- io/channel-socket.c | 15 +++++++++------ migration/socket.c | 3 ++- tests/test-io-channel-socket.c | 4 ++-- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index bdd6cff5f6..754d82679a 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -866,7 +866,7 @@ static gboolean socket_reconnect_timeout(gpointer opaqu= e) 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); =20 return false; } @@ -950,7 +950,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..d7134d2cd6 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -101,6 +101,8 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *i= oc, * @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. If %NULL, the default + * context will be used. * * Attempt to connect to the address @addr. This method * will run in the background so the caller will regain @@ -113,7 +115,8 @@ void qio_channel_socket_connect_async(QIOChannelSocket = *ioc, SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); =20 =20 /** @@ -138,6 +141,8 @@ int qio_channel_socket_listen_sync(QIOChannelSocket *io= c, * @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. If %NULL, the default + * context will be used. * * Attempt to listen to the address @addr. This method * will run in the background so the caller will regain @@ -150,7 +155,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *= ioc, SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); =20 =20 /** @@ -179,6 +185,8 @@ int qio_channel_socket_dgram_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. If %NULL, the default + * context will be used. * * Attempt to initialize a datagram socket bound to * @localAddr and communicating with peer @remoteAddr. @@ -194,7 +202,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *i= oc, SocketAddress *remoteAddr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); =20 =20 /** diff --git a/io/channel-socket.c b/io/channel-socket.c index 4224ce323a..18c139c365 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 =3D 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); } =20 =20 @@ -233,7 +234,8 @@ void qio_channel_socket_listen_async(QIOChannelSocket *= ioc, SocketAddress *addr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task =3D qio_task_new( OBJECT(ioc), callback, opaque, destroy); @@ -247,7 +249,7 @@ void qio_channel_socket_listen_async(QIOChannelSocket *= ioc, qio_channel_socket_listen_worker, addrCopy, (GDestroyNotify)qapi_free_SocketAddress, - NULL); + context); } =20 =20 @@ -309,7 +311,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *i= oc, SocketAddress *remoteAddr, QIOTaskFunc callback, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task =3D qio_task_new( OBJECT(ioc), callback, opaque, destroy); @@ -324,7 +327,7 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *i= oc, qio_channel_socket_dgram_worker, data, qio_channel_socket_dgram_worker_free, - NULL); + context); } =20 =20 diff --git a/migration/socket.c b/migration/socket.c index e090097077..8a93fb1af5 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -103,7 +103,8 @@ static void socket_start_outgoing_migration(MigrationSt= ate *s, saddr, socket_outgoing_migration, data, - socket_connect_data_free); + socket_connect_data_free, + NULL); qapi_free_SocketAddress(saddr); } =20 diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index d357cd2a8e..b273fd3ba2 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -179,7 +179,7 @@ static void test_io_channel_setup_async(SocketAddress *= listen_addr, lioc =3D qio_channel_socket_new(); qio_channel_socket_listen_async( lioc, listen_addr, - test_io_channel_complete, &data, NULL); + test_io_channel_complete, &data, NULL, NULL); =20 g_main_loop_run(data.loop); g_main_context_iteration(g_main_context_default(), FALSE); @@ -200,7 +200,7 @@ static void test_io_channel_setup_async(SocketAddress *= listen_addr, =20 qio_channel_socket_connect_async( QIO_CHANNEL_SOCKET(*src), connect_addr, - test_io_channel_complete, &data, NULL); + test_io_channel_complete, &data, NULL, NULL); =20 g_main_loop_run(data.loop); g_main_context_iteration(g_main_context_default(), FALSE); --=20 2.14.3 From nobody Wed Oct 22 04:13:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520232446349873.6189782613678; Sun, 4 Mar 2018 22:47:26 -0800 (PST) Received: from localhost ([::1]:47422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esju9-0005IT-G7 for importer@patchew.org; Mon, 05 Mar 2018 01:47:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esjqo-00034Z-Rv for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:44:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1esjqm-0006BS-MJ for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:58 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:53400 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 1esjqm-0006B8-Gn for qemu-devel@nongnu.org; Mon, 05 Mar 2018 01:43:56 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1523340FB64A for ; Mon, 5 Mar 2018 06:43:56 +0000 (UTC) Received: from xz-mi.nay.redhat.com (dhcp-14-151.nay.redhat.com [10.66.14.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 979202024CAB; Mon, 5 Mar 2018 06:43:52 +0000 (UTC) From: Peter Xu To: qemu-devel@nongnu.org Date: Mon, 5 Mar 2018 14:43:24 +0800 Message-Id: <20180305064324.9238-7-peterx@redhat.com> In-Reply-To: <20180305064324.9238-1-peterx@redhat.com> References: <20180305064324.9238-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 05 Mar 2018 06:43:56 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 v3 6/6] 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=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A new parameter "context" is added to qio_channel_tls_handshake() is to allow the TLS to be run on a non-default context. Still, no functional change. Signed-off-by: Peter Xu --- chardev/char-socket.c | 1 + include/io/channel-tls.h | 5 ++++- io/channel-tls.c | 45 ++++++++++++++++++++++++++++++++++-------= ---- migration/tls.c | 2 ++ nbd/client.c | 1 + nbd/server.c | 1 + tests/test-io-channel-tls.c | 2 ++ ui/vnc-auth-vencrypt.c | 1 + ui/vnc-ws.c | 1 + 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 754d82679a..113feaf948 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -702,6 +702,7 @@ static void tcp_chr_tls_init(Chardev *chr) qio_channel_tls_handshake(tioc, tcp_chr_tls_handshake, chr, + NULL, NULL); } =20 diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h index d157eb10e8..87fcaf9146 100644 --- a/include/io/channel-tls.h +++ b/include/io/channel-tls.h @@ -116,6 +116,8 @@ qio_channel_tls_new_client(QIOChannel *master, * @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. If %NULL, + * the default context will be used * * Perform the TLS session handshake. This method * will return immediately and the handshake will @@ -126,7 +128,8 @@ qio_channel_tls_new_client(QIOChannel *master, void qio_channel_tls_handshake(QIOChannelTLS *ioc, QIOTaskFunc func, gpointer opaque, - GDestroyNotify destroy); + GDestroyNotify destroy, + GMainContext *context); =20 /** * qio_channel_tls_get_session: diff --git a/io/channel-tls.c b/io/channel-tls.c index 6182702dab..9628e6fa47 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -140,13 +140,19 @@ qio_channel_tls_new_client(QIOChannel *master, return NULL; } =20 +struct QIOChannelTLSData { + QIOTask *task; + GMainContext *context; +}; +typedef struct QIOChannelTLSData QIOChannelTLSData; =20 static gboolean qio_channel_tls_handshake_io(QIOChannel *ioc, GIOCondition condition, gpointer user_data); =20 static void qio_channel_tls_handshake_task(QIOChannelTLS *ioc, - QIOTask *task) + QIOTask *task, + GMainContext *context) { Error *err =3D NULL; QCryptoTLSSessionHandshakeStatus status; @@ -171,6 +177,15 @@ static void qio_channel_tls_handshake_task(QIOChannelT= LS *ioc, qio_task_complete(task); } else { GIOCondition condition; + QIOChannelTLSData *data =3D g_new0(typeof(*data), 1); + + data->task =3D task; + data->context =3D context; + + if (context) { + g_main_context_ref(context); + } + if (status =3D=3D QCRYPTO_TLS_HANDSHAKE_SENDING) { condition =3D G_IO_OUT; } else { @@ -178,11 +193,12 @@ static void qio_channel_tls_handshake_task(QIOChannel= TLS *ioc, } =20 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); } } =20 @@ -191,12 +207,18 @@ static gboolean qio_channel_tls_handshake_io(QIOChann= el *ioc, GIOCondition condition, gpointer user_data) { - QIOTask *task =3D user_data; + QIOChannelTLSData *data =3D user_data; + QIOTask *task =3D data->task; + GMainContext *context =3D data->context; QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS( qio_task_get_source(task)); =20 - qio_channel_tls_handshake_task( - tioc, task); + g_free(data); + qio_channel_tls_handshake_task(tioc, task, context); + + if (context) { + g_main_context_unref(context); + } =20 return FALSE; } @@ -204,7 +226,8 @@ static gboolean qio_channel_tls_handshake_io(QIOChannel= *ioc, void qio_channel_tls_handshake(QIOChannelTLS *ioc, QIOTaskFunc func, gpointer opaque, - GDestroyNotify destroy) + GDestroyNotify destroy, + GMainContext *context) { QIOTask *task; =20 @@ -212,7 +235,7 @@ void qio_channel_tls_handshake(QIOChannelTLS *ioc, func, opaque, destroy); =20 trace_qio_channel_tls_handshake_start(ioc); - qio_channel_tls_handshake_task(ioc, task); + qio_channel_tls_handshake_task(ioc, task, context); } =20 =20 diff --git a/migration/tls.c b/migration/tls.c index a29b35b33c..3b9e8c9263 100644 --- a/migration/tls.c +++ b/migration/tls.c @@ -105,6 +105,7 @@ void migration_tls_channel_process_incoming(MigrationSt= ate *s, qio_channel_tls_handshake(tioc, migration_tls_incoming_handshake, NULL, + NULL, NULL); } =20 @@ -159,5 +160,6 @@ void migration_tls_channel_connect(MigrationState *s, qio_channel_tls_handshake(tioc, migration_tls_outgoing_handshake, s, + NULL, NULL); } diff --git a/nbd/client.c b/nbd/client.c index 9c3fe4aaa6..dcad23a053 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -579,6 +579,7 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc, qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, + NULL, NULL); =20 if (!data.complete) { diff --git a/nbd/server.c b/nbd/server.c index 4990a5826e..e714bfe6a1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -599,6 +599,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, qio_channel_tls_handshake(tioc, nbd_tls_handshake, &data, + NULL, NULL); =20 if (!data.complete) { diff --git a/tests/test-io-channel-tls.c b/tests/test-io-channel-tls.c index a210d01ba5..32743b2c96 100644 --- a/tests/test-io-channel-tls.c +++ b/tests/test-io-channel-tls.c @@ -203,10 +203,12 @@ static void test_io_channel_tls(const void *opaque) qio_channel_tls_handshake(clientChanTLS, test_tls_handshake_done, &clientHandshake, + NULL, NULL); qio_channel_tls_handshake(serverChanTLS, test_tls_handshake_done, &serverHandshake, + NULL, NULL); =20 /* diff --git a/ui/vnc-auth-vencrypt.c b/ui/vnc-auth-vencrypt.c index 7833631275..d99ea362c1 100644 --- a/ui/vnc-auth-vencrypt.c +++ b/ui/vnc-auth-vencrypt.c @@ -128,6 +128,7 @@ static int protocol_client_vencrypt_auth(VncState *vs, = uint8_t *data, size_t len qio_channel_tls_handshake(tls, vnc_tls_handshake_done, vs, + NULL, NULL); } return 0; diff --git a/ui/vnc-ws.c b/ui/vnc-ws.c index 6ccad22cef..950f1cd2ac 100644 --- a/ui/vnc-ws.c +++ b/ui/vnc-ws.c @@ -81,6 +81,7 @@ gboolean vncws_tls_handshake_io(QIOChannel *ioc G_GNUC_UN= USED, qio_channel_tls_handshake(tls, vncws_tls_handshake_done, vs, + NULL, NULL); =20 return TRUE; --=20 2.14.3