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:
Michal Privoznik 2022-02-10 16:10:13 +01:00
parent 3d13f6abcd
commit 22a96eac7c
3 changed files with 22 additions and 8 deletions

View File

@ -136,6 +136,15 @@ virCHDomainObjEndJob(virDomainObj *obj)
virCondSignal(&priv->job.cond);
}
void
virCHDomainRemoveInactive(virCHDriver *driver,
virDomainObj *vm)
{
if (vm->persistent) {
virDomainObjListRemove(driver->domains, vm);
}
}
static void *
virCHDomainObjPrivateAlloc(void *opaque)
{

View File

@ -88,6 +88,10 @@ virCHDomainObjBeginJob(virDomainObj *obj, enum virCHDomainJob job)
void
virCHDomainObjEndJob(virDomainObj *obj);
void
virCHDomainRemoveInactive(virCHDriver *driver,
virDomainObj *vm);
int
virCHDomainRefreshThreadInfo(virDomainObj *vm);

View File

@ -237,7 +237,7 @@ chDomainCreateXML(virConnectPtr conn,
cleanup:
if (vm && !dom) {
virDomainObjListRemove(driver->domains, vm);
virCHDomainRemoveInactive(driver, vm);
}
virDomainObjEndAPI(&vm);
return dom;
@ -342,10 +342,9 @@ chDomainUndefineFlags(virDomainPtr dom,
goto cleanup;
}
if (virDomainObjIsActive(vm)) {
vm->persistent = 0;
} else {
virDomainObjListRemove(driver->domains, vm);
vm->persistent = 0;
if (!virDomainObjIsActive(vm)) {
virCHDomainRemoveInactive(driver, vm);
}
ret = 0;
@ -608,12 +607,14 @@ chDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
if (virDomainObjCheckActive(vm) < 0)
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:
virCHDomainObjEndJob(vm);
if (!vm->persistent)
virDomainObjListRemove(driver->domains, vm);
cleanup:
virDomainObjEndAPI(&vm);