From nobody Sun May 5 12:08:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1605206768; cv=none; d=zohomail.com; s=zohoarc; b=CZ7rB9GryXRBwvWv8emS2DA98ducaqtrwqzFdJaYa/LbXr2tOFBau+XWcDCml4JmTP7p8GFNfVdRZzv3nx1lxG0aWFzSeHlSwG7MCY+xAqmYLaqtRY4ZKjxDFLBKcv+E+wZlUXH7iWI2KG2DqvssA14KW1VuUlksQBI6QYHB9mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605206768; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hGsTYRScptjeuNvAPwheaa1zoiduqRFmHipazYM+Xvs=; b=K9bnRBzscK4P5bXLsUSdSvfr1UPu9qtqkUxUQMZWGI0A4YyiSmwc3j30hEVdpAIwaSf0z/ji1UF8W/7ztK7ibArjUaOFWGsclr0m9Uh0aH3HDIkVXuM8NnzuSNmQfbuiEfrcmSB+zvVif7KnU/SfzUwuu8AisBw+a23CxpQuDW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605206768490322.45534190376316; Thu, 12 Nov 2020 10:46:08 -0800 (PST) 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-282-yVKBqM_XOXq7kSQyPTOAug-1; Thu, 12 Nov 2020 13:46:05 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 135D26415F; Thu, 12 Nov 2020 18:46:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA9A21002C0D; Thu, 12 Nov 2020 18:45:59 +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 2F697181A06B; Thu, 12 Nov 2020 18:45:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ACIjnSZ018107 for ; Thu, 12 Nov 2020 13:45:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 669475D9E4; Thu, 12 Nov 2020 18:45:49 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9EFE5D9E8 for ; Thu, 12 Nov 2020 18:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605206767; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=hGsTYRScptjeuNvAPwheaa1zoiduqRFmHipazYM+Xvs=; b=Gfc6OupDzZn77Vo4soIpXa13Q7VbN+q8EIU6R033sagXSYrvjV5piZ2tN7OuYUE5/9jDBK zaFwCNoAZ+ZZnihaUOP24PFboOwJyGdwGe8xCh2BL7inzE/IWujj87SOzY16q3K2lI0g+w K2UWPvcUzWPhS6rgdpovFapVwEgq25o= X-MC-Unique: yVKBqM_XOXq7kSQyPTOAug-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] DO NOT MERGE Date: Thu, 12 Nov 2020 19:45:38 +0100 Message-Id: <8c5a7b21aeabb18ca82a12f19800a87a00710c01.1605206706.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.22 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This is to help reproduce the race. Build and attach gdb and: handle SIGUSR1 nostop pass handle SIGINT nostop pass and then: kill -SIGUSR1 $(pgrep libvirtd); sleep 1; kill -SIGINT $(pgrep libvirtd) Signed-off-by: Michal Privoznik --- src/remote/remote_daemon.c | 64 +++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 7607da94be..5b68c9d2f9 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -483,6 +483,37 @@ static void daemonReloadHandler(virNetDaemonPtr dmn G_= GNUC_UNUSED, } } =20 + +static void daemonStopWorker(void *opaque) +{ + virNetDaemonPtr dmn =3D opaque; + + sleep(10); + + VIR_DEBUG("Begin stop dmn=3D%p", dmn); + + ignore_value(virStateStop()); + + VIR_DEBUG("Completed stop dmn=3D%p", dmn); + + /* Exit daemon cleanly */ + virNetDaemonQuit(dmn); +} + + +/* We do this in a thread to not block the main loop */ +static void daemonStop(virNetDaemonPtr dmn, + siginfo_t *sig G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + virThread thr; + virObjectRef(dmn); + if (virThreadCreateFull(&thr, false, daemonStopWorker, + "daemon-stop", false, dmn) < 0) + virObjectUnref(dmn); +} + + static int daemonSetupSignals(virNetDaemonPtr dmn) { if (virNetDaemonAddSignalHandler(dmn, SIGINT, daemonShutdownHandler, N= ULL) < 0) @@ -493,6 +524,8 @@ static int daemonSetupSignals(virNetDaemonPtr dmn) return -1; if (virNetDaemonAddSignalHandler(dmn, SIGHUP, daemonReloadHandler, NUL= L) < 0) return -1; + if (virNetDaemonAddSignalHandler(dmn, SIGUSR1, daemonStop, NULL) < 0) + return -1; return 0; } =20 @@ -511,32 +544,6 @@ static void daemonInhibitCallback(bool inhibit, void *= opaque) static GDBusConnection *sessionBus; static GDBusConnection *systemBus; =20 -static void daemonStopWorker(void *opaque) -{ - virNetDaemonPtr dmn =3D opaque; - - VIR_DEBUG("Begin stop dmn=3D%p", dmn); - - ignore_value(virStateStop()); - - VIR_DEBUG("Completed stop dmn=3D%p", dmn); - - /* Exit daemon cleanly */ - virNetDaemonQuit(dmn); -} - - -/* We do this in a thread to not block the main loop */ -static void daemonStop(virNetDaemonPtr dmn) -{ - virThread thr; - virObjectRef(dmn); - if (virThreadCreateFull(&thr, false, daemonStopWorker, - "daemon-stop", false, dmn) < 0) - virObjectUnref(dmn); -} - - static GDBusMessage * handleSessionMessageFunc(GDBusConnection *connection G_GNUC_UNUSED, GDBusMessage *message, @@ -550,7 +557,7 @@ handleSessionMessageFunc(GDBusConnection *connection G_= GNUC_UNUSED, if (virGDBusMessageIsSignal(message, "org.freedesktop.DBus.Local", "Disconnected")) - daemonStop(dmn); + daemonStop(dmn, NULL, NULL); =20 return message; } @@ -569,7 +576,7 @@ handleSystemMessageFunc(GDBusConnection *connection G_G= NUC_UNUSED, =20 VIR_DEBUG("dmn=3D%p", dmn); =20 - daemonStop(dmn); + daemonStop(dmn, NULL, NULL); } =20 =20 @@ -1247,5 +1254,6 @@ int main(int argc, char **argv) { VIR_FREE(remote_config_file); daemonConfigFree(config); =20 + sleep(10); return ret; } --=20 2.26.2 From nobody Sun May 5 12:08:50 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=1605206803; cv=none; d=zohomail.com; s=zohoarc; b=jIbJvLTxmbcxC5tG/Ho0F5EG9qy72wOPv576M8SmFfzR+eZyifkP1zehJLhWWnPk9B6OfdBDRuSjguMcJNi3lFIEjYhh9bHOJbl0Ps7lpEfY1zhPkfHHq+BZ9vWMMqChkD4Z9aeKkHkDtln7mWaJ3s7KLvhvkvY/dXpnfBrU9iU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605206803; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f/6v8Z3ImYinGhgEZijLINPwXcjqLp/9rZ5jFmpcOdI=; b=BnjVnHdHuJswUBcLN5brOgcBE/fk6027LzU1IUCoKZ9qfmib2MbvctVtNBMpwv04PaaIoEdWNj+58OOE9vZ7N9wLjXm9NXlcMjUzWJw070bcPeGe8b+D57aQjTz0RqvtkyPX2lc4muj6w781tSSOwVeumc5OIOn6BgCGQnsksXU= 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 1605206803685580.335463734819; Thu, 12 Nov 2020 10:46:43 -0800 (PST) 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-551-nqf5k2gAPX-SqhIbPa8Ddg-1; Thu, 12 Nov 2020 13:46:40 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DC51107B275; Thu, 12 Nov 2020 18:46:34 +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 38EA31002D7A; Thu, 12 Nov 2020 18:46:34 +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 CD6945810D; Thu, 12 Nov 2020 18:46:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ACIjoak018113 for ; Thu, 12 Nov 2020 13:45:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 477D85D9E8; Thu, 12 Nov 2020 18:45:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA3085D9E4 for ; Thu, 12 Nov 2020 18:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1605206802; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=f/6v8Z3ImYinGhgEZijLINPwXcjqLp/9rZ5jFmpcOdI=; b=HD0av3uEMIZMtCMSSB0yGVWVdyh+78hRnGeCvJI/LDsIp502qvfPoKbDOhaZW+jwU4ohTp HaOtjiCkQ4R5Grx+6KjhEI7dSGBSYspiV5IaJIGGNxkppjre3nWuJIUIPYxAdPTKvy4VPE 7rRrzKOIeOPlqSvgqLXpe5kE9bsCOeU= X-MC-Unique: nqf5k2gAPX-SqhIbPa8Ddg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] qemu: Check if driver is still available in qemuStateStop() Date: Thu, 12 Nov 2020 19:45:39 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.22 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" When the host is shutting down then we get PrepareForShutdown signal on DBus to which we react by creating a thread which runs virStateStop() and thus qemuStateStop(). But if scheduling the thread is delayed just a but it may happen that we receive SIGTERM (sent by systemd) to which we respond by quitting our event loop and cleaning up everything (including drivers). And only after that the thread gets to run only to find qemu_driver being NULL. At this point there is nothing left to do anyways, the event loop is gone so no API call that qemuStateStop() does in attempt to save running domains can ever succeed. But to be fair, if there was a domain running we would have registered shutdown inhibitor so we would not get killed by signal. So there is nothing left to do for qemuStateStop() anyway. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1895359 Signed-off-by: Michal Privoznik --- src/qemu/qemu_driver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 05f8eb2cb7..9aa0ce4ec8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1046,7 +1046,12 @@ qemuStateStop(void) int state; virDomainPtr *domains =3D NULL; g_autofree unsigned int *flags =3D NULL; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(qemu_dri= ver); + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + + if (!qemu_driver) + return -1; + + cfg =3D virQEMUDriverGetConfig(qemu_driver); =20 if (!(conn =3D virConnectOpen(cfg->uri))) goto cleanup; --=20 2.26.2