File 0dda594d-libvirtd-shutdown-deadlock.patch of Package libvirt

commit 0dda594da99aede7621018a3705e7cf4c13b1606
Author: Jim Fehlig <>
Date:   Thu Jun 21 09:21:44 2012 -0600

    Fix deadlock on libvirtd shutdown
    When shutting down libvirtd, the virNetServer shutdown can deadlock
    if there are in-flight jobs being handled by virNetServerHandleJob().
    virNetServerFree() will acquire the virNetServer lock and call
    virThreadPoolFree() to terminate the workers, waiting for the workers
    to finish.  But in-flight workers will attempt to acquire the
    virNetServer lock, resulting in deadlock.
    Fix the deadlock by unlocking the virNetServer lock before calling
    virThreadPoolFree().  This is safe since the virNetServerPtr object
    is ref-counted and only decrementing the ref count needs to be
    protected.  Additionally, there is no need to re-acquire the lock
    after virThreadPoolFree() completes as all the workers have

Index: libvirt-
--- libvirt-
+++ libvirt-
@@ -801,10 +801,9 @@ void virNetServerFree(virNetServerPtr sr
     VIR_DEBUG("srv=%p refs=%d", srv, srv->refs);
-    if (srv->refs > 0) {
-        virNetServerUnlock(srv);
+    virNetServerUnlock(srv);
+    if (srv->refs > 0)
-    }
     for (i = 0 ; i < srv->nservices ; i++)
         virNetServerServiceToggle(srv->services[i], false);
@@ -845,7 +844,6 @@ void virNetServerFree(virNetServerPtr sr
-    virNetServerUnlock(srv);