Fix a deadlock in bi-directional p2p concurrent migration.
Fix a deadlock in bi-directional p2p concurrent migration.

If you try to execute two concurrent migrations p2p
from A->B and B->A, the two libvirtd's will deadlock
trying to perform the migrations.  The reason for this is
that in p2p migration, the libvirtd's are responsible for
making the RPC Prepare, Migrate, and Finish calls.  However,
they are currently holding the driver lock while doing so,
which basically guarantees deadlock in this scenario.

This patch fixes the situation by adding
qemuDomainObjEnterRemoteWithDriver and
qemuDomainObjExitRemoteWithDriver helper methods.  The Enter
take an additional object reference, then drops both the
domain object lock and the driver lock.  The Exit takes
both the driver and domain object lock, then drops the
reference.  Adding calls to these Enter and Exit helpers
around remote calls in the various migration methods
seems to fix the problem for me in testing.

This should make the situation safe. The additional domain
object reference ensures that the domain object won't disappear
while this operation is happening.  The BeginJob that is called
inside of qemudDomainMigratePerform ensures that we can't execute a
second migrate (or shutdown, or save, etc) job while the
migration is active.  Finally, the additional check on the state
of the vm after we reacquire the locks ensures that we can't
be surprised by an external event (domain crash, etc).

Signed-off-by: Chris Lalancette <60b62644009db6b194cc0445b64e9b27bb26433a@redhat.com>

jardasgit/libvirt,usc-isi/libvirt,crobinso/libvirt,iam-TJ/libvirt,rmarwaha/libvirt1,danwent/libvirt-ovs,VenkatDatta/libvirt,shugaoye/libvirt,trainstack/libvirt,crobinso/libvirt,warewolf/libvirt,elmarco/libvirt,leilihh/libvirt,jeckersb/libvirt,andreabolognani/libvirt,kantai/libvirt-vfork,dumbbell/libvirt,elmarco/libvirt,taget/libvirt,fabianfreyer/libvirt,rbu/libvirt,crobinso/libvirt,siboulet/libvirt-openvz,foomango/libvirt,shugaoye/libvirt,warewolf/libvirt,nertpinx/libvirt,leilihh/libvirt,siboulet/libvirt-openvz,usc-isi/libvirt,danwent/libvirt-ovs,rlaager/libvirt,zippy2/libvirt,libvirt/libvirt,novel/fbsd-libvirt,warewolf/libvirt,trainstack/libvirt,libvirt/libvirt,amery/libvirt-vserver,jfehlig/libvirt,iam-TJ/libvirt,leilihh/libvirt,kantai/libvirt-vfork,rmarwaha/libvirt,emaste/libvirt,soulxu/libvirt-xuhj,VenkatDatta/libvirt,usc-isi/libvirt,leilihh/libvirt,dumbbell/libvirt,libvirt/libvirt,amery/libvirt-vserver,warewolf/libvirt,danwent/libvirt-ovs,jardasgit/libvirt,rmarwaha/libvirt1,novel/fbsd-libvirt,bjzhang/libvirt,rbu/libvirt,soulxu/libvirt-xuhj,libvirt/libvirt,rmarwaha/libvirt,jeckersb/libvirt,andreabolognani/libvirt,zhlcindy/libvirt-1.1.4-maintain,nertpinx/libvirt,datto/libvirt,amery/libvirt-vserver,jfehlig/libvirt,taget/libvirt,wiedi/libvirt,zhlcindy/libvirt-1.1.4-maintain,dumbbell/libvirt,taget/libvirt,foomango/libvirt,novel/fbsd-libvirt,bjzhang/libvirt,emaste/libvirt,jeckersb/libvirt,shugaoye/libvirt,emaste/libvirt,usc-isi/libvirt,sshah-solarflare/Libvirt-PCI-passthrough-,rmarwaha/libvirt1,eskultety/libvirt,soulxu/libvirt-xuhj,andreabolognani/libvirt,datto/libvirt,siboulet/libvirt-openvz,novel/fbsd-libvirt,jardasgit/libvirt,agx/libvirt,olafhering/libvirt,eskultety/libvirt,leilihh/libvirt,zhlcindy/libvirt-1.1.4-maintain,warewolf/libvirt,emaste/libvirt,datto/libvirt,taget/libvirt,jfehlig/libvirt,rmarwaha/libvirt,VenkatDatta/libvirt,foomango/libvirt,fabianfreyer/libvirt,VenkatDatta/libvirt,sshah-solarflare/Libvirt-PCI-passthrough-,datto/libvirt,danwent/libvirt-ovs,cbosdo/libvirt,nertpinx/libvirt,elmarco/libvirt,sshah-solarflare/Libvirt-PCI-passthrough-,rlaager/libvirt,rbu/libvirt,dumbbell/libvirt,rmarwaha/libvirt,foomango/libvirt,wiedi/libvirt,leilihh/libvirt,eskultety/libvirt,jeckersb/libvirt,zhlcindy/libvirt-1.1.4-maintain,jeckersb/libvirt,jfehlig/libvirt,amery/libvirt-vserver,novel/fbsd-libvirt,rmarwaha/libvirt1,agx/libvirt,VenkatDatta/libvirt,trainstack/libvirt,novel/fbsd-libvirt,trainstack/libvirt,iam-TJ/libvirt,emaste/libvirt,fabianfreyer/libvirt,emaste/libvirt,amery/libvirt-vserver,taget/libvirt,zippy2/libvirt,andreabolognani/libvirt,wiedi/libvirt,shugaoye/libvirt,iam-TJ/libvirt,trainstack/libvirt,soulxu/libvirt-xuhj,usc-isi/libvirt,rmarwaha/libvirt1,zhlcindy/libvirt-1.1.4-maintain,zippy2/libvirt,datto/libvirt,agx/libvirt,jeckersb/libvirt,iam-TJ/libvirt,olafhering/libvirt,olafhering/libvirt,nertpinx/libvirt,dumbbell/libvirt,nertpinx/libvirt,rbu/libvirt,trainstack/libvirt,rlaager/libvirt,crobinso/libvirt,rbu/libvirt,rlaager/libvirt,rmarwaha/libvirt1,sshah-solarflare/Libvirt-PCI-passthrough-,elmarco/libvirt,iam-TJ/libvirt,fabianfreyer/libvirt,warewolf/libvirt,trainstack/libvirt,dumbbell/libvirt,eskultety/libvirt,jardasgit/libvirt,foomango/libvirt,cbosdo/libvirt,cbosdo/libvirt,danwent/libvirt-ovs,agx/libvirt,soulxu/libvirt-xuhj,jardasgit/libvirt,jeckersb/libvirt,sshah-solarflare/Libvirt-PCI-passthrough-,novel/fbsd-libvirt,siboulet/libvirt-openvz,cbosdo/libvirt,novel/fbsd-libvirt,andreabolognani/libvirt,olafhering/libvirt,kantai/libvirt-vfork,emaste/libvirt,wiedi/libvirt,bjzhang/libvirt,agx/libvirt,bjzhang/libvirt,elmarco/libvirt,shugaoye/libvirt,kantai/libvirt-vfork,warewolf/libvirt,novel/fbsd-libvirt,iam-TJ/libvirt,wiedi/libvirt,siboulet/libvirt-openvz,zippy2/libvirt,eskultety/libvirt,bjzhang/libvirt,rmarwaha/libvirt,kantai/libvirt-vfork,rmarwaha/libvirt,wiedi/libvirt,fabianfreyer/libvirt,wiedi/libvirt,rlaager/libvirt,cbosdo/libvirt