From nobody Sat May 4 23:13:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1615912258; cv=none; d=zohomail.com; s=zohoarc; b=ERpSOTAuSZCebFh/zaPSEaqNMyzqBX+Imfdoc3wPLfNtAMgIaYqjNRzeyg7LAqi/3PItt544ztUySYApqwAR4RiHT7oSddkuhGym18euN4V33qX1kAPNZPx5T4qN7lIKCFXgcJhpTFxW2rmtqu+z/hEspZPNMCoBfQ7Kzm1ZWdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615912258; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=gSDEZbjlbEt/77BrJ8theRMbxp6SrlD4tjXOMP+4Qes=; b=i5J7x+qpTSZDqDPUlDpCoF0qSWSiqG9ueWEIvvQktEccH2kzLXWrOmmKjReE4JgrL/aXgsLzF9bhiiATP9VC6sPKQFpv91Esb0EJ9BGV4g3eIdgaBB4+n7HFo0GAI9YPouj0f8PEYjgUeNCPkbdm5oT14Tfimva22vsEFh085VQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1615912258577308.7032403774415; Tue, 16 Mar 2021 09:30:58 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-385-_UtI0VX8OUiUP4-aivJdBQ-1; Tue, 16 Mar 2021 12:30:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D18DD69724; Tue, 16 Mar 2021 16:30:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 886D260C13; Tue, 16 Mar 2021 16:30:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9C1BD57DC1; Tue, 16 Mar 2021 16:30:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12GGUboe003277 for ; Tue, 16 Mar 2021 12:30:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3F52B1001281; Tue, 16 Mar 2021 16:30:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-185.ams2.redhat.com [10.36.115.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F10A10023B5; Tue, 16 Mar 2021 16:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615912257; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=gSDEZbjlbEt/77BrJ8theRMbxp6SrlD4tjXOMP+4Qes=; b=PlT8/BHiv8g8qTOdQHTMAPDDIU2y/vFgCbBOGhOl9ziT+eP7tBT5ghV0fEcl/z/vHtzFnk pUvfQUILvcto1ZWTVtBowHDYmdFPInlUlVJ7gaUIDPUoqQXWi4XroIc8S94e5GhKlTEDdG 9ZA+yZVnUu3tvov01XiIU+kl+E11Qvo= X-MC-Unique: _UtI0VX8OUiUP4-aivJdBQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH] src: ensure GSource background unref happens in correct event loop Date: Tue, 16 Mar 2021 16:30:32 +0000 Message-Id: <20210316163032.148029-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The g_idle_add function adds a callback to the primary GMainContext. To workaround the GSource unref bugs, we need to add our callbacks to the GMainContext that is associated with the GSource being unref'd. Thus code using the per-VM virEventThread must use its private GMainContext. Signed-off-by: Daniel P. Berrang=C3=A9 --- meson.build | 3 --- src/libvirt_glib_crash_workaround.syms | 11 ----------- src/libvirt_private.syms | 1 + src/meson.build | 7 ------- src/qemu/qemu_agent.c | 2 +- src/qemu/qemu_monitor.c | 2 +- src/util/glibcompat.c | 20 ++++++++++++++++++-- src/util/glibcompat.h | 11 +---------- src/util/vireventglib.c | 12 ++++++------ 9 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 src/libvirt_glib_crash_workaround.syms diff --git a/meson.build b/meson.build index 69a7b4c88e..ea93a2a8ec 100644 --- a/meson.build +++ b/meson.build @@ -1049,9 +1049,6 @@ if host_machine.system() =3D=3D 'windows' else gio_dep =3D dependency('gio-unix-2.0', version: '>=3D' + glib_version) endif -# GLib event loop race workaround in glibcompat.h, remove when minimum req= uired -# glib is >=3D 2.64.0 -glib_crash_workaround =3D glib_dep.version().version_compare('<2.64.0') glib_dep =3D declare_dependency( dependencies: [ glib_dep, gobject_dep, gio_dep ], ) diff --git a/src/libvirt_glib_crash_workaround.syms b/src/libvirt_glib_cras= h_workaround.syms deleted file mode 100644 index 249058b65b..0000000000 --- a/src/libvirt_glib_crash_workaround.syms +++ /dev/null @@ -1,11 +0,0 @@ -# -# Private symbols specific for pre-2.64.0 GLib workaround -# - -# util/glibcompat.h -virEventGLibSourceUnrefIdle; - -# Let emacs know we want case-insensitive sorting -# Local Variables: -# sort-fold-case: t -# End: diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 767d665613..526dcee11a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1733,6 +1733,7 @@ virStorageSourceUpdatePhysicalSize; # util/glibcompat.h vir_g_canonicalize_filename; vir_g_fsync; +vir_g_source_unref; vir_g_strdup_printf; vir_g_strdup_vprintf; =20 diff --git a/src/meson.build b/src/meson.build index 70a5a83eea..c7ff9e978c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -124,13 +124,6 @@ else sym_files +=3D 'libvirt_libssh2.syms' endif =20 -if glib_crash_workaround - used_sym_files +=3D 'libvirt_glib_crash_workaround.syms' -else - sym_files +=3D 'libvirt_glib_crash_workaround.syms' -endif - - # variables filled by subdirectories =20 libvirt_libs =3D [] diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 01ba2c78c1..787a7bb41c 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -533,7 +533,7 @@ qemuAgentUnregister(qemuAgentPtr agent) { if (agent->watch) { g_source_destroy(agent->watch); - g_vir_source_unref_safe(agent->watch); + vir_g_source_unref(agent->watch, agent->context); agent->watch =3D NULL; } } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index b4f2641504..f6cd9d9eda 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -862,7 +862,7 @@ qemuMonitorUnregister(qemuMonitorPtr mon) { if (mon->watch) { g_source_destroy(mon->watch); - g_vir_source_unref_safe(mon->watch); + vir_g_source_unref(mon->watch, mon->context); mon->watch =3D NULL; } } diff --git a/src/util/glibcompat.c b/src/util/glibcompat.c index fe19ffa87b..eb6dcc0111 100644 --- a/src/util/glibcompat.c +++ b/src/util/glibcompat.c @@ -231,9 +231,14 @@ vir_g_strdup_vprintf(const char *msg, va_list args) * * Drop when min glib >=3D 2.64.0 */ -#if GLIB_CHECK_VERSION(2, 64, 0) !=3D TRUE +#if GLIB_CHECK_VERSION(2, 64, 0) +void vir_g_source_unref(GSource *src, GMainContext *ctx G_GNUC_UNUSED) +{ + g_source_unref(src); +} +#else =20 -gboolean +static gboolean virEventGLibSourceUnrefIdle(gpointer data) { GSource *src =3D data; @@ -243,4 +248,15 @@ virEventGLibSourceUnrefIdle(gpointer data) return FALSE; } =20 +void vir_g_source_unref(GSource *src, GMainContext *ctx) +{ + GSource *idle =3D g_idle_source_new(); + + g_source_set_callback(idle, virEventGLibSourceUnrefIdle, src, NULL); + + g_source_attach(idle, ctx); + + g_source_unref(idle); +} + #endif diff --git a/src/util/glibcompat.h b/src/util/glibcompat.h index 9c52843274..697687b967 100644 --- a/src/util/glibcompat.h +++ b/src/util/glibcompat.h @@ -85,13 +85,4 @@ char *vir_g_strdup_vprintf(const char *msg, va_list args) #undef g_fsync #define g_fsync vir_g_fsync =20 -/* Drop when min glib >=3D 2.64.0 */ -#if GLIB_CHECK_VERSION(2, 64, 0) -# define g_vir_source_unref_safe(source) g_source_unref(source) -#else -# define g_vir_source_unref_safe(source) g_idle_add(virEventGLibSourceUnre= fIdle, source) - -gboolean -virEventGLibSourceUnrefIdle(gpointer data); - -#endif +void vir_g_source_unref(GSource *src, GMainContext *ctx); diff --git a/src/util/vireventglib.c b/src/util/vireventglib.c index 88e3ec6d5d..f3e5a344b0 100644 --- a/src/util/vireventglib.c +++ b/src/util/vireventglib.c @@ -214,7 +214,7 @@ virEventGLibHandleUpdate(int watch, if (data->source !=3D NULL) { VIR_DEBUG("Removed old handle source=3D%p", data->source); g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); } =20 data->source =3D virEventGLibAddSocketWatch( @@ -228,7 +228,7 @@ virEventGLibHandleUpdate(int watch, =20 VIR_DEBUG("Removed old handle source=3D%p", data->source); g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); data->source =3D NULL; data->events =3D 0; } @@ -277,7 +277,7 @@ virEventGLibHandleRemove(int watch) =20 if (data->source !=3D NULL) { g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); data->source =3D NULL; data->events =3D 0; } @@ -410,7 +410,7 @@ virEventGLibTimeoutUpdate(int timer, if (interval >=3D 0) { if (data->source !=3D NULL) { g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); } =20 data->interval =3D interval; @@ -420,7 +420,7 @@ virEventGLibTimeoutUpdate(int timer, goto cleanup; =20 g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); data->source =3D NULL; } =20 @@ -469,7 +469,7 @@ virEventGLibTimeoutRemove(int timer) =20 if (data->source !=3D NULL) { g_source_destroy(data->source); - g_vir_source_unref_safe(data->source); + vir_g_source_unref(data->source, NULL); data->source =3D NULL; } =20 --=20 2.30.2