]> git.ipfire.org Git - thirdparty/libvirt.git/commit
Push nwfilter update locking up to top level
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 22 Jan 2014 17:28:29 +0000 (17:28 +0000)
committerLaine Stump <laine@laine.org>
Thu, 6 Feb 2014 12:48:56 +0000 (14:48 +0200)
commit029bb56e59ff89a0942bdd637b4e2e507c76a755
tree14817e6b45d4e5c62d57440cd532e0d9bfcfd8a4
parent33bbacb0eab8719c03dd1b0ea2b5bd81893541b5
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 6e5c79a1b5a8b3a23e7df7ffe58fb272aa17fbfb)

Conflicts:
src/conf/nwfilter_conf.c
          - virReportOOMError() in context of one hunk.
src/lxc/lxc_driver.c
          - functions renamed, and lxc object locking changed, creating
            a conflict in the context.

(cherry picked from commit 2331e5c8d13ea2352a20c93166a9287e25196353)
src/conf/nwfilter_conf.c
src/conf/nwfilter_conf.h
src/libvirt_private.syms
src/lxc/lxc_driver.c
src/nwfilter/nwfilter_driver.c
src/nwfilter/nwfilter_gentech_driver.c
src/qemu/qemu_driver.c
src/uml/uml_driver.c