]> xenbits.xensource.com Git - libvirt.git/commit
qemu: completely rework reference counting
authorMartin Kletzander <mkletzan@redhat.com>
Thu, 4 Dec 2014 13:41:36 +0000 (14:41 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Sun, 21 Dec 2014 09:48:56 +0000 (10:48 +0100)
commit540c339a2535ec30d79e5ef84d8f50a17bc60723
tree941528231fe7d40a26fdc72f3b0e85e500c2ca1e
parent3b0f05573fbf385cca554d3383fad0089ed080cf
qemu: completely rework reference counting

There is one problem that causes various errors in the daemon.  When
domain is waiting for a job, it is unlocked while waiting on the
condition.  However, if that domain is for example transient and being
removed in another API (e.g. cancelling incoming migration), it get's
unref'd.  If the first call, that was waiting, fails to get the job, it
unref's the domain object, and because it was the last reference, it
causes clearing of the whole domain object.  However, when finishing the
call, the domain must be unlocked, but there is no way for the API to
know whether it was cleaned or not (unless there is some ugly temporary
variable, but let's scratch that).

The root cause is that our APIs don't ref the objects they are using and
all use the implicit reference that the object has when it is in the
domain list.  That reference can be removed when the API is waiting for
a job.  And because each domain doesn't do its ref'ing, it results in
the ugly checking of the return value of virObjectUnref() that we have
everywhere.

This patch changes qemuDomObjFromDomain() to ref the domain (using
virDomainObjListFindByUUIDRef()) and adds qemuDomObjEndAPI() which
should be the only function in which the return value of
virObjectUnref() is checked.  This makes all reference counting
deterministic and makes the code a bit clearer.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/THREADS.txt
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c
src/qemu/qemu_migration.c
src/qemu/qemu_migration.h
src/qemu/qemu_process.c
src/util/virclosecallbacks.c