540c339 qemu: completely rework reference counting

Authored and Committed by mkletzan 9 years ago
    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>
    
        
file modified
+19 -21
file modified
+27 -22
file modified
+6 -6
file modified
+248 -461
file modified
+36 -75
file modified
+5 -5
file modified
+28 -47
file modified
+6 -1