Libvirt provides a portable, long term stable C API for managing the virtualization technologies provided by many operating systems. It includes support for QEMU, KVM, Xen, LXC, bhyve, Virtuozzo, VMware vCenter and ESX, VMware Desktop, Hyper-V, VirtualBox and the POWER Hypervisor.
Go to file
Daniel P. Berrange 720e945e3b Push nwfilter update locking up to top level
The NWFilter code has as a deadlock race condition between
the virNWFilter{Define,Undefine} APIs and starting of guest
VMs due to mis-matched lock ordering.

In the virNWFilter{Define,Undefine} codepaths the lock ordering
is

  1. nwfilter driver lock
  2. virt driver lock
  3. nwfilter update lock
  4. domain object lock

In the VM guest startup paths the lock ordering is

  1. virt driver lock
  2. domain object lock
  3. nwfilter update lock

As can be seen the domain object and nwfilter update locks are
not acquired in a consistent order.

The fix used is to push the nwfilter update lock upto the top
level resulting in a lock ordering for virNWFilter{Define,Undefine}
of

  1. nwfilter driver lock
  2. nwfilter update lock
  3. virt driver lock
  4. domain object lock

and VM start using

  1. nwfilter update lock
  2. virt driver lock
  3. domain object lock

This has the effect of serializing VM startup once again, even if
no nwfilters are applied to the guest. There is also the possibility
of deadlock due to a call graph loop via virNWFilterInstantiate
and virNWFilterInstantiateFilterLate.

These two problems mean the lock must be turned into a read/write
lock instead of a plain mutex at the same time. The lock is used to
serialize changes to the "driver->nwfilters" hash, so the write lock
only needs to be held by the define/undefine methods. All other
methods can rely on a read lock which allows good concurrency.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 6e5c79a1b5)

Conflicts:
  src/conf/nwfilter_conf.c
   - virReportOOMError() in context of one hunk.
  src/lxc/lxc_driver.c
   - trivial date conflict in copyright line
   - functions renamed, and lxc object locking changed, creating
     a conflict in the context.
  src/qemu/qemu_driver.c
   - qemuDomainStartWithFlags (called qemuDomainCreateWithFlags
     upstream) gets the domain object using
     qemuDomObjFromDomain() upstream, but
     virDomainObjListFindByUUID() in 1.0.4. This creates a
     small conflict in context.
2014-02-06 15:58:39 +02:00
.gnulib@92f3a4c8e5 maint: update to latest gnulib 2013-09-18 15:04:36 -06:00
build-aux Document bracket whitespace rules & add syntax-check rule 2012-11-02 14:00:32 +00:00
daemon Fix crash in remoteDispatchDomainMemoryStats (CVE-2013-4296) 2013-09-18 15:08:35 -06:00
docs Release of libvirt 1.0.3 2013-03-05 12:00:53 +08:00
examples hellolibvirt: Adjust code to use new APIs 2013-03-04 17:36:03 -05:00
gnulib maint: update to latest gnulib 2013-01-02 09:38:30 -07:00
include Introduce virDomainMigrate*CompressionCache APIs 2013-02-22 17:35:59 +01:00
m4 Fix typo in configure.ac causing $LIBS to gain a copy of $CFLAGS 2013-02-05 18:04:16 +00:00
po Release of libvirt 1.0.3 2013-03-05 12:00:53 +08:00
python python: fix fd leak in generator.py 2013-03-01 15:49:07 +08:00
src Push nwfilter update locking up to top level 2014-02-06 15:58:39 +02:00
tests Remove virConnectPtr arg from virNWFilterDefParse* 2014-02-06 15:46:27 +02:00
tools build: use proper pod for nested bulleted VIRSH_DEBUG list 2014-01-15 11:01:46 -07:00
.dir-locals.el build: avoid tabs that failed syntax-check 2012-09-06 09:43:46 -06:00
.gitignore Add autogenerated lxc_protocol.[ch] to gitignore 2013-02-18 08:57:57 -06:00
.gitmodules make .gnulib a submodule 2009-07-08 16:17:51 +02:00
.mailmap Autogenerate AUTHORS 2012-10-19 12:44:56 -04:00
AUTHORS.in Add John Ferlan to the committers list 2013-02-05 10:59:32 -05:00
autobuild.sh Switch automated builds to use Mingw64 toolchain instead of Mingw32 2012-06-25 10:41:10 +01:00
autogen.sh build: fix incremental autogen.sh when no AUTHORS is present 2012-12-03 14:59:09 -07:00
bootstrap maint: update to latest gnulib 2013-09-18 15:04:30 -06:00
bootstrap.conf build: more mingw fixes 2013-02-15 15:45:52 -07:00
cfg.mk util: portably check for unchanged uid 2013-03-15 14:47:39 -06:00
ChangeLog-old virterror.c: Fix several spelling mistakes 2012-02-03 11:32:51 -07:00
configure.ac Add support for using 3-arg pkcheck syntax for process (CVE-2013-4311) 2013-09-18 17:44:15 +01:00
COPYING.LIB remove all trailing blank lines 2009-07-16 15:06:42 +02:00
HACKING Turn virSecurityManager into a virObjectLockable 2013-02-11 12:33:41 +00:00
libvirt.pc.in build: silence warning from autoconf 2012-05-30 09:22:02 -06:00
libvirt.spec.in Add support for using 3-arg pkcheck syntax for process (CVE-2013-4311) 2013-09-18 17:44:15 +01:00
Makefile.am build: Fix AUTHORS generation 2012-12-17 21:17:55 +01:00
Makefile.nonreentrant Ban use of all inet_* functions 2010-10-22 11:59:23 +01:00
mingw-libvirt.spec.in spec: indent %if to make it easier to see conditions 2013-01-21 10:36:14 -07:00
README Correct typos in the documentation (Atsushi SAKAI) 2008-01-24 10:15:13 +00:00
README-hacking maint: relax git minimum version 2010-02-24 14:29:27 -05:00
run.in run: license as LGPL 2013-02-23 14:03:19 -07:00
TODO Update todo list file to point at bugzilla/website 2010-10-13 16:45:26 +01:00

         LibVirt : simple API for virtualization

  Libvirt is a C toolkit to interact with the virtualization capabilities
of recent versions of Linux (and other OSes). It is free software
available under the GNU Lesser General Public License. Virtualization of
the Linux Operating System means the ability to run multiple instances of
Operating Systems concurrently on a single hardware system where the basic
resources are driven by a Linux instance. The library aim at providing
long term stable C API initially for the Xen paravirtualization but
should be able to integrate other virtualization mechanisms if needed.

Daniel Veillard <veillard@redhat.com>