libxl: use job functions when cleaning up a domain

When explicitly destroying a domain (libxlDomainDestroyFlags), or
handling an out-of-band domain shutdown event, cleanup the domain
in the context of a job.  Introduce libxlVmCleanupJob to wrap
libxlVmCleanup in a job block.
This commit is contained in:
Jim Fehlig 2014-02-12 16:06:41 -07:00
parent f5bc5bd4df
commit e4a0e900d3

View File

@ -316,6 +316,26 @@ libxlVmCleanup(libxlDriverPrivatePtr driver,
virObjectUnref(cfg); virObjectUnref(cfg);
} }
/*
* Cleanup function for domain that has reached shutoff state.
* Executed in the context of a job.
*
* virDomainObjPtr should be locked on invocation
* Returns true if references remain on virDomainObjPtr, false otherwise.
*/
static bool
libxlVmCleanupJob(libxlDriverPrivatePtr driver,
virDomainObjPtr vm,
virDomainShutoffReason reason)
{
if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_DESTROY) < 0)
return true;
libxlVmCleanup(driver, vm, reason);
return libxlDomainObjEndJob(driver, vm);
}
/* /*
* Handle previously registered event notification from libxenlight. * Handle previously registered event notification from libxenlight.
* *
@ -364,10 +384,11 @@ libxlDomainShutdownThread(void *opaque)
reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN; reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
} }
libxl_domain_destroy(ctx, vm->def->id, NULL); libxl_domain_destroy(ctx, vm->def->id, NULL);
libxlVmCleanup(driver, vm, reason); if (libxlVmCleanupJob(driver, vm, reason)) {
if (!vm->persistent) { if (!vm->persistent) {
virDomainObjListRemove(driver->domains, vm); virDomainObjListRemove(driver->domains, vm);
vm = NULL; vm = NULL;
}
} }
break; break;
case LIBXL_SHUTDOWN_REASON_REBOOT: case LIBXL_SHUTDOWN_REASON_REBOOT:
@ -1561,10 +1582,11 @@ libxlDomainDestroyFlags(virDomainPtr dom,
goto cleanup; goto cleanup;
} }
libxlVmCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED); if (libxlVmCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED)) {
if (!vm->persistent) { if (!vm->persistent) {
virDomainObjListRemove(driver->domains, vm); virDomainObjListRemove(driver->domains, vm);
vm = NULL; vm = NULL;
}
} }
ret = 0; ret = 0;