[PATCH 2/2] qemu: Check if driver is still available in qemuStateStop()

Michal Privoznik mprivozn at redhat.com
Thu Nov 12 18:45:39 UTC 2020


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=1895359

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 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 = NULL;
     g_autofree unsigned int *flags = NULL;
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(qemu_driver);
+    g_autoptr(virQEMUDriverConfig) cfg = NULL;
+
+    if (!qemu_driver)
+        return -1;
+
+    cfg = virQEMUDriverGetConfig(qemu_driver);
 
     if (!(conn = virConnectOpen(cfg->uri)))
         goto cleanup;
-- 
2.26.2




More information about the libvir-list mailing list