mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
ch_driver: Introduce and use virCHDomainRemoveInactive()
There are few places where a call to virDomainObjListRemove() is guarded with !vm->persistent check. And there are some places which are missing this check completely (leading us to losing a domain). To prevent such mistakes introduce virCHDomainRemoveInactive() which does the check for us. Also replace all occurrences of virDomainObjListRemove() with the call to the new function. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
This commit is contained in:
parent
3d13f6abcd
commit
22a96eac7c
@ -136,6 +136,15 @@ virCHDomainObjEndJob(virDomainObj *obj)
|
|||||||
virCondSignal(&priv->job.cond);
|
virCondSignal(&priv->job.cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
virCHDomainRemoveInactive(virCHDriver *driver,
|
||||||
|
virDomainObj *vm)
|
||||||
|
{
|
||||||
|
if (vm->persistent) {
|
||||||
|
virDomainObjListRemove(driver->domains, vm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
virCHDomainObjPrivateAlloc(void *opaque)
|
virCHDomainObjPrivateAlloc(void *opaque)
|
||||||
{
|
{
|
||||||
|
@ -88,6 +88,10 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDomainJob job)
|
|||||||
void
|
void
|
||||||
virCHDomainObjEndJob(virDomainObj *obj);
|
virCHDomainObjEndJob(virDomainObj *obj);
|
||||||
|
|
||||||
|
void
|
||||||
|
virCHDomainRemoveInactive(virCHDriver *driver,
|
||||||
|
virDomainObj *vm);
|
||||||
|
|
||||||
int
|
int
|
||||||
virCHDomainRefreshThreadInfo(virDomainObj *vm);
|
virCHDomainRefreshThreadInfo(virDomainObj *vm);
|
||||||
|
|
||||||
|
@ -237,7 +237,7 @@ chDomainCreateXML(virConnectPtr conn,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm && !dom) {
|
if (vm && !dom) {
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
virCHDomainRemoveInactive(driver, vm);
|
||||||
}
|
}
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
return dom;
|
return dom;
|
||||||
@ -342,10 +342,9 @@ chDomainUndefineFlags(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virDomainObjIsActive(vm)) {
|
vm->persistent = 0;
|
||||||
vm->persistent = 0;
|
if (!virDomainObjIsActive(vm)) {
|
||||||
} else {
|
virCHDomainRemoveInactive(driver, vm);
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -608,12 +607,14 @@ chDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
|
|||||||
if (virDomainObjCheckActive(vm) < 0)
|
if (virDomainObjCheckActive(vm) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
ret = virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
if (virCHProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED) < 0)
|
||||||
|
goto endjob;
|
||||||
|
|
||||||
|
virCHDomainRemoveInactive(driver, vm);
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
endjob:
|
endjob:
|
||||||
virCHDomainObjEndJob(vm);
|
virCHDomainObjEndJob(vm);
|
||||||
if (!vm->persistent)
|
|
||||||
virDomainObjListRemove(driver->domains, vm);
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
|
Loading…
Reference in New Issue
Block a user