libxl: find virDomainObj in libxlDomainShutdownThread
libxl: find virDomainObj in libxlDomainShutdownThread

libxl events are delivered to libvirt via the libxlDomainEventHandler
callback registered with libxl. Documenation in
$xensrc/tools/libxl/libxl_event.h states that the callback "may occur
on any thread in which the application calls libxl". This can result
in deadlock since many of the libvirt callees of libxl hold a lock on
the virDomainObj they are working on. When the callback is invoked, it
attempts to find a virDomainObj corresponding to the domain ID provided
by libxl. Searching the domain obj list results in locking each obj
before checking if it is active, and its ID equals the requested ID.
Deadlock is possible when attempting to lock an obj that is already
locked further up the call stack. Indeed, Max Ustermann reported an
instance of this deadlock

https://www.redhat.com/archives/libvir-list/2015-November/msg00130.html

Guido Rossmueller also recently stumbled across it

https://www.redhat.com/archives/libvir-list/2016-September/msg00287.html

Fix the deadlock by moving the lookup of virDomainObj to the
libxlDomainShutdownThread. After this patch, libxl events are
enqueued on the libvirt side and processed by dedicated thread,
avoiding the described deadlock.

Reported-by: Max Ustermann <409fe1b747b8548ee0a7567789af6024398e5fa7@web.de>
Reported-by: Guido Rossmueller <c2206c4c0d20419e2b731007a89712836a35821d@gdata.de>

nertpinx/libvirt,taget/libvirt,jfehlig/libvirt,libvirt/libvirt,libvirt/libvirt,fabianfreyer/libvirt,andreabolognani/libvirt,nertpinx/libvirt,VenkatDatta/libvirt,jfehlig/libvirt,jardasgit/libvirt,olafhering/libvirt,libvirt/libvirt,andreabolognani/libvirt,jfehlig/libvirt,jardasgit/libvirt,jardasgit/libvirt,zippy2/libvirt,VenkatDatta/libvirt,taget/libvirt,datto/libvirt,crobinso/libvirt,fabianfreyer/libvirt,eskultety/libvirt,zippy2/libvirt,fabianfreyer/libvirt,jardasgit/libvirt,nertpinx/libvirt,VenkatDatta/libvirt,olafhering/libvirt,jardasgit/libvirt,nertpinx/libvirt,fabianfreyer/libvirt,VenkatDatta/libvirt,olafhering/libvirt,fabianfreyer/libvirt,crobinso/libvirt,eskultety/libvirt,olafhering/libvirt,eskultety/libvirt,nertpinx/libvirt,eskultety/libvirt,eskultety/libvirt,zippy2/libvirt,jfehlig/libvirt,andreabolognani/libvirt,VenkatDatta/libvirt,crobinso/libvirt,andreabolognani/libvirt,datto/libvirt,datto/libvirt,datto/libvirt,andreabolognani/libvirt,taget/libvirt,libvirt/libvirt,crobinso/libvirt,taget/libvirt,taget/libvirt,zippy2/libvirt,datto/libvirt