From nobody Sun Apr 28 10:29:08 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506401671150457.87702953057396; Mon, 25 Sep 2017 21:54:31 -0700 (PDT) Received: from localhost ([::1]:45619 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhsl-0003fG-EM for importer@patchew.org; Tue, 26 Sep 2017 00:54:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhrB-0002mB-VO for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwhrB-0000AC-3j for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43426) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dwhrA-00009p-Tj for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E4DDB267DF; Tue, 26 Sep 2017 04:52:27 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA6FB67547; Tue, 26 Sep 2017 04:52:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E4DDB267DF Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 26 Sep 2017 12:52:09 +0800 Message-Id: <1506401532-25274-2-git-send-email-peterx@redhat.com> In-Reply-To: <1506401532-25274-1-git-send-email-peterx@redhat.com> References: <1506401532-25274-1-git-send-email-peterx@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 26 Sep 2017 04:52:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/4] qom: provide root container for internal objs 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: Fam Zheng , Manos Pitsidianakis , Markus Armbruster , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We have object_get_objects_root() to keep user created objects, however no place for objects that will be used internally. Create such a container for internal objects. CC: Andreas F=C3=A4rber CC: Markus Armbruster CC: Paolo Bonzini Suggested-by: Daniel P. Berrange Signed-off-by: Peter Xu --- include/qom/object.h | 10 ++++++++++ qom/object.c | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/qom/object.h b/include/qom/object.h index f3e5cff..f567052 100644 --- a/include/qom/object.h +++ b/include/qom/object.h @@ -1214,6 +1214,16 @@ Object *object_get_root(void); Object *object_get_objects_root(void); =20 /** + * object_get_internal_root: + * + * Get the container object that holds internally used object + * instances. This is the object at path "/internal-objects" + * + * Returns: the internal object container + */ +Object *object_get_internal_root(void); + +/** * object_get_canonical_path_component: * * Returns: The final component in the object's canonical path. The canon= ical diff --git a/qom/object.c b/qom/object.c index 3e18537..6a7bd92 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1370,6 +1370,17 @@ Object *object_get_objects_root(void) return container_get(object_get_root(), "/objects"); } =20 +Object *object_get_internal_root(void) +{ + static Object *internal_root; + + if (!internal_root) { + internal_root =3D object_new("container"); + } + + return internal_root; +} + static void object_get_child_property(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) --=20 2.7.4 From nobody Sun Apr 28 10:29:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506401667694820.3440734312256; Mon, 25 Sep 2017 21:54:27 -0700 (PDT) Received: from localhost ([::1]:45621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhsu-0003lt-HQ for importer@patchew.org; Tue, 26 Sep 2017 00:54:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhrH-0002nP-8l for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwhrG-0000Bk-7C for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dwhrG-0000BS-0u for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 081384A703; Tue, 26 Sep 2017 04:52:33 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6120B67547; Tue, 26 Sep 2017 04:52:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 081384A703 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 26 Sep 2017 12:52:10 +0800 Message-Id: <1506401532-25274-3-git-send-email-peterx@redhat.com> In-Reply-To: <1506401532-25274-1-git-send-email-peterx@redhat.com> References: <1506401532-25274-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 26 Sep 2017 04:52:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 2/4] iothread: provide helpers for internal use 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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" IOThread is a general framework that contains IO loop environment and a real thread behind. It's also good to be used internally inside qemu. Provide some helpers for it to create iothreads to be used internally. Put all the internal used iothreads into the internal object container. Signed-off-by: Peter Xu Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- include/sysemu/iothread.h | 8 ++++++++ iothread.c | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index d2985b3..b07663f 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -46,4 +46,12 @@ AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); GMainContext *iothread_get_g_main_context(IOThread *iothread); =20 +/* + * Helpers used to allocate iothreads for internal use. These + * iothreads will not be seen by monitor clients when query using + * "query-iothreads". + */ +IOThread *iothread_create(const char *id, Error **errp); +void iothread_destroy(IOThread *iothread); + #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 44c8944..33f996e 100644 --- a/iothread.c +++ b/iothread.c @@ -354,3 +354,19 @@ GMainContext *iothread_get_g_main_context(IOThread *io= thread) =20 return iothread->worker_context; } + +IOThread *iothread_create(const char *id, Error **errp) +{ + Object *obj; + + obj =3D object_new_with_props(TYPE_IOTHREAD, + object_get_internal_root(), + id, errp, NULL); + + return IOTHREAD(obj); +} + +void iothread_destroy(IOThread *iothread) +{ + object_unparent(OBJECT(iothread)); +} --=20 2.7.4 From nobody Sun Apr 28 10:29:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506401739327528.0347631618262; Mon, 25 Sep 2017 21:55:39 -0700 (PDT) Received: from localhost ([::1]:45626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhuE-0004q8-Ih for importer@patchew.org; Tue, 26 Sep 2017 00:55:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49836) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhrK-0002pg-HA for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwhrJ-0000Cd-Jy for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dwhrJ-0000CI-Am for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 459757E42A; Tue, 26 Sep 2017 04:52:36 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C90D67547; Tue, 26 Sep 2017 04:52:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 459757E42A Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 26 Sep 2017 12:52:11 +0800 Message-Id: <1506401532-25274-4-git-send-email-peterx@redhat.com> In-Reply-To: <1506401532-25274-1-git-send-email-peterx@redhat.com> References: <1506401532-25274-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 26 Sep 2017 04:52:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 3/4] iothread: export iothread_stop() 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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" So that internal iothread users can explicitly stop one iothread without destroying it. Since at it, fix iothread_stop() to allow it to be called multiple times. Before this patch we may call iothread_stop() more than once on single iothread, while that may not be correct since qemu_thread_join() is not allowed to run twice. From manual of pthread_join(): Joining with a thread that has previously been joined results in undefined behavior. Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- include/sysemu/iothread.h | 1 + iothread.c | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index b07663f..110329b 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -52,6 +52,7 @@ GMainContext *iothread_get_g_main_context(IOThread *iothr= ead); * "query-iothreads". */ IOThread *iothread_create(const char *id, Error **errp); +void iothread_stop(IOThread *iothread); void iothread_destroy(IOThread *iothread); =20 #endif /* IOTHREAD_H */ diff --git a/iothread.c b/iothread.c index 33f996e..b3c092b 100644 --- a/iothread.c +++ b/iothread.c @@ -80,13 +80,10 @@ static void *iothread_run(void *opaque) return NULL; } =20 -static int iothread_stop(Object *object, void *opaque) +void iothread_stop(IOThread *iothread) { - IOThread *iothread; - - iothread =3D (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); - if (!iothread || !iothread->ctx) { - return 0; + if (!iothread->ctx || iothread->stopping) { + return; } iothread->stopping =3D true; aio_notify(iothread->ctx); @@ -94,6 +91,17 @@ static int iothread_stop(Object *object, void *opaque) g_main_loop_quit(iothread->main_loop); } qemu_thread_join(&iothread->thread); +} + +static int iothread_stop_iter(Object *object, void *opaque) +{ + IOThread *iothread; + + iothread =3D (IOThread *)object_dynamic_cast(object, TYPE_IOTHREAD); + if (!iothread) { + return 0; + } + iothread_stop(iothread); return 0; } =20 @@ -108,7 +116,7 @@ static void iothread_instance_finalize(Object *obj) { IOThread *iothread =3D IOTHREAD(obj); =20 - iothread_stop(obj, NULL); + iothread_stop(iothread); qemu_cond_destroy(&iothread->init_done_cond); qemu_mutex_destroy(&iothread->init_done_lock); if (!iothread->ctx) { @@ -328,7 +336,7 @@ void iothread_stop_all(void) aio_context_release(ctx); } =20 - object_child_foreach(container, iothread_stop, NULL); + object_child_foreach(container, iothread_stop_iter, NULL); } =20 static gpointer iothread_g_main_context_init(gpointer opaque) --=20 2.7.4 From nobody Sun Apr 28 10:29:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1506401812145265.1958925417732; Mon, 25 Sep 2017 21:56:52 -0700 (PDT) Received: from localhost ([::1]:45631 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhvK-0005UY-Gx for importer@patchew.org; Tue, 26 Sep 2017 00:56:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwhrT-0002uy-RI for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwhrQ-0000Ed-PJ for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45270) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dwhrQ-0000ER-JR for qemu-devel@nongnu.org; Tue, 26 Sep 2017 00:52:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EBB6C04D2AC; Tue, 26 Sep 2017 04:52:43 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-15-224.nay.redhat.com [10.66.15.224]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE31467547; Tue, 26 Sep 2017 04:52:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8EBB6C04D2AC Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=peterx@redhat.com From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 26 Sep 2017 12:52:12 +0800 Message-Id: <1506401532-25274-5-git-send-email-peterx@redhat.com> In-Reply-To: <1506401532-25274-1-git-send-email-peterx@redhat.com> References: <1506401532-25274-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 26 Sep 2017 04:52:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 4/4] iothread: delay the context release to finalize 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: Fam Zheng , Manos Pitsidianakis , peterx@redhat.com, "Dr . David Alan Gilbert" , Stefan Hajnoczi , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= 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" When gcontext is used with iothread, the context will be destroyed during iothread_stop(). That's not good since sometimes we would like to keep the resources until iothread is destroyed, but we may want to stop the thread before that point. Delay the destruction of gcontext to iothread finalize. Then we can do: iothread_stop(thread); some_cleanup_on_resources(); iothread_destroy(thread); We may need this patch if we want to run chardev IOs in iothreads and hopefully clean them up correctly. For more specific information, please see 2b316774f6 ("qemu-char: do not operate on sources from finalize callbacks"). Reviewed-by: Fam Zheng Reviewed-by: Stefan Hajnoczi Signed-off-by: Peter Xu --- iothread.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iothread.c b/iothread.c index b3c092b..27a4288 100644 --- a/iothread.c +++ b/iothread.c @@ -71,8 +71,6 @@ static void *iothread_run(void *opaque) g_main_loop_unref(loop); =20 g_main_context_pop_thread_default(iothread->worker_context); - g_main_context_unref(iothread->worker_context); - iothread->worker_context =3D NULL; } } =20 @@ -117,6 +115,10 @@ static void iothread_instance_finalize(Object *obj) IOThread *iothread =3D IOTHREAD(obj); =20 iothread_stop(iothread); + if (iothread->worker_context) { + g_main_context_unref(iothread->worker_context); + iothread->worker_context =3D NULL; + } qemu_cond_destroy(&iothread->init_done_cond); qemu_mutex_destroy(&iothread->init_done_lock); if (!iothread->ctx) { --=20 2.7.4