[PATCH v2] qemu_shim: Don't hang if failed to start domain

Michal Privoznik posted 1 patch 3 years, 1 month ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/2f898f8b46b6fedac6b5489ad3a03e5cc306fd47.1615561573.git.mprivozn@redhat.com
src/qemu/qemu_shim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] qemu_shim: Don't hang if failed to start domain
Posted by Michal Privoznik 3 years, 1 month ago
The qemu shim spawns a separate thread in which the event loop is
ran. The virEventRunDefaultImpl() call is wrapped in a while()
loop, just like it should. There are few lines of code around
which try to ensure that domain is destroyed (when quitting) and
that the last round of event loop is ran after the
virDomainDestroy() call. Only after that the loop is quit from
and the thread quits.

However, if domain creation fails, there is no @dom to call
destroy over, the @quit flag is never set and while() never
exits. Set the flag regardless of @dom pointer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1920337
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

v2 of:

https://listman.redhat.com/archives/libvir-list/2021-March/msg00011.html

Thanks to Andrea who made me realize that this can be written better.

diff to v1:
- Instead of exiting from while() early, let the event loop run another
  iteration (it should be no-op anyway).

 src/qemu/qemu_shim.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c
index d85497bd3a..8b3afd0324 100644
--- a/src/qemu/qemu_shim.c
+++ b/src/qemu/qemu_shim.c
@@ -45,9 +45,9 @@ qemuShimEventLoop(void *opaque G_GNUC_UNUSED)
     while (!quit) {
         g_mutex_lock(&eventLock);
         if (eventQuitFlag && !eventPreventQuitFlag) {
+            quit = true;
             if (dom) {
                 virDomainDestroy(dom);
-                quit = true;
             }
         }
         g_mutex_unlock(&eventLock);
-- 
2.26.2