]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemu: avoid rare race when undefining domain
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 11 Dec 2014 10:14:08 +0000 (11:14 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Sat, 13 Dec 2014 09:01:31 +0000 (10:01 +0100)
commitc7d1c139ca3402e875002753952e80ce8054374e
tree81d3be147d5fd6adff834077c5fab4aa0e90fece
parentf6f4bd10b2fcfddad59affe33ba9962dcdd98ff3
qemu: avoid rare race when undefining domain

When one domain is being undefined and at the same time started, for
example, there is a possibility of a rare problem occuring.

 - Thread 1 does virDomainUndefine(), has the lock, checks that the
   domain is active and because it's not, calls
   virDomainObjListRemove().

 - Thread 2 does virDomainCreate() and tries to lock the domain.

 - Thread 1 needs to lock domain list in order to remove the domain from
   it, but must unlock domain first (proper order is to lock domain list
   first and the domain itself second).

 - Thread 2 grabs the lock, starts the domain and releases the lock.

 - Thread 1 grabs the lock and removes the domain from list.

With this patch:

 - The undefining domain gets marked as "to undefine" before it is
    unlocked.

 - If domain is found in any of the search APIs, it's returned only if
   it is not marked as "to undefine".  The check is done while the
   domain is locked.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1150505

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/conf/domain_conf.c
src/conf/domain_conf.h