Fix deadlock in QEMU close callback APIs
Fix deadlock in QEMU close callback APIs

There is a lock ordering problem in the QEMU close callback
APIs.

When starting a guest we have a lock on the VM. We then
set a autodestroy callback, which acquires a lock on the
close callbacks.

When running auto-destroy, we obtain a lock on the close
callbacks, then run each callbacks - which obtains a lock
on the VM.

This causes deadlock if anyone tries to start a VM, while
autodestroy is taking place.

The fix is to do autodestroy in 2 phases. First obtain
all the callbacks and remove them from the list under
the close callback lock. Then invoke each callback
from outside the close callback lock.

Signed-off-by: Daniel P. Berrange <bb938cf255e055ff3507f2627d214e8e62118fcf@redhat.com>

VenkatDatta/libvirt,jardasgit/libvirt,shugaoye/libvirt,rlaager/libvirt,zippy2/libvirt,VenkatDatta/libvirt,siboulet/libvirt-openvz,siboulet/libvirt-openvz,andreabolognani/libvirt,taget/libvirt,zhlcindy/libvirt-1.1.4-maintain,shugaoye/libvirt,olafhering/libvirt,jfehlig/libvirt,jfehlig/libvirt,crobinso/libvirt,eskultety/libvirt,agx/libvirt,fabianfreyer/libvirt,fabianfreyer/libvirt,libvirt/libvirt,fabianfreyer/libvirt,crobinso/libvirt,nertpinx/libvirt,fabianfreyer/libvirt,jfehlig/libvirt,jardasgit/libvirt,libvirt/libvirt,VenkatDatta/libvirt,andreabolognani/libvirt,taget/libvirt,datto/libvirt,fabianfreyer/libvirt,libvirt/libvirt,andreabolognani/libvirt,eskultety/libvirt,zippy2/libvirt,cbosdo/libvirt,shugaoye/libvirt,siboulet/libvirt-openvz,andreabolognani/libvirt,datto/libvirt,taget/libvirt,elmarco/libvirt,siboulet/libvirt-openvz,andreabolognani/libvirt,nertpinx/libvirt,jardasgit/libvirt,eskultety/libvirt,elmarco/libvirt,datto/libvirt,elmarco/libvirt,cbosdo/libvirt,zippy2/libvirt,eskultety/libvirt,nertpinx/libvirt,nertpinx/libvirt,olafhering/libvirt,VenkatDatta/libvirt,agx/libvirt,taget/libvirt,zhlcindy/libvirt-1.1.4-maintain,shugaoye/libvirt,cbosdo/libvirt,agx/libvirt,cbosdo/libvirt,olafhering/libvirt,shugaoye/libvirt,cbosdo/libvirt,agx/libvirt,elmarco/libvirt,agx/libvirt,VenkatDatta/libvirt,olafhering/libvirt,zhlcindy/libvirt-1.1.4-maintain,rlaager/libvirt,zippy2/libvirt,datto/libvirt,taget/libvirt,datto/libvirt,zhlcindy/libvirt-1.1.4-maintain,jardasgit/libvirt,libvirt/libvirt,nertpinx/libvirt,jardasgit/libvirt,rlaager/libvirt,jfehlig/libvirt,eskultety/libvirt,siboulet/libvirt-openvz,rlaager/libvirt,elmarco/libvirt,zhlcindy/libvirt-1.1.4-maintain,rlaager/libvirt,crobinso/libvirt,crobinso/libvirt