From nobody Wed Dec 17 21:49:13 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1507058230311466.31457364734786; Tue, 3 Oct 2017 12:17:10 -0700 (PDT) Received: from localhost ([::1]:59953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzSgT-0004p3-JF for importer@patchew.org; Tue, 03 Oct 2017 15:16:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzScz-00023Z-M9 for qemu-devel@nongnu.org; Tue, 03 Oct 2017 15:13:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzScv-0005xC-01 for qemu-devel@nongnu.org; Tue, 03 Oct 2017 15:13:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37154) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dzScu-0005wJ-Qn for qemu-devel@nongnu.org; Tue, 03 Oct 2017 15:13:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 048A3C059B67; Tue, 3 Oct 2017 19:13:08 +0000 (UTC) Received: from localhost (ovpn-117-57.ams2.redhat.com [10.36.117.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id A06D917AA9; Tue, 3 Oct 2017 19:13:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 048A3C059B67 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=stefanha@redhat.com From: Stefan Hajnoczi To: Date: Tue, 3 Oct 2017 15:12:26 -0400 Message-Id: <20171003191227.11845-5-stefanha@redhat.com> In-Reply-To: <20171003191227.11845-1-stefanha@redhat.com> References: <20171003191227.11845-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 03 Oct 2017 19:13:08 +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] [PULL 4/5] 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: Peter Maydell , Stefan Hajnoczi , Peter Xu 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" From: Peter Xu 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 Message-id: 20170928025958.1420-5-peterx@redhat.com Signed-off-by: Stefan Hajnoczi --- iothread.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iothread.c b/iothread.c index b3c092b2d7..27a4288578 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.13.6