提交 527d867a 编写于 作者: J Jiri Denemark

qemu: Make autodestroy utilize connection close callbacks

上级 79127360
......@@ -141,11 +141,6 @@ struct qemud_driver {
virLockManagerPluginPtr lockManager;
/* Mapping of 'char *uuidstr' -> virConnectPtr
* of guests which will be automatically killed
* when the virConnectPtr is closed*/
virHashTablePtr autodestroy;
/* Mapping of 'char *uuidstr' -> qemuDriverCloseDefPtr of domains
* which want a specific cleanup to be done when a connection is
* closed. Such cleanup may be to automatically destroy the
......
......@@ -659,9 +659,6 @@ qemudStartup(int privileged) {
qemu_driver->hugepage_path = mempath;
}
if (qemuProcessAutoDestroyInit(qemu_driver) < 0)
goto error;
if (qemuDriverCloseCallbackInit(qemu_driver) < 0)
goto error;
......@@ -803,7 +800,6 @@ qemudShutdown(void) {
virSysinfoDefFree(qemu_driver->hostsysinfo);
qemuProcessAutoDestroyShutdown(qemu_driver);
qemuDriverCloseCallbackShutdown(qemu_driver);
VIR_FREE(qemu_driver->configDir);
......@@ -925,7 +921,6 @@ static int qemudClose(virConnectPtr conn) {
qemuDriverLock(driver);
virDomainEventStateDeregisterConn(conn,
driver->domainEventState);
qemuProcessAutoDestroyRun(driver, conn);
qemuDriverCloseCallbackRunAll(driver, conn);
qemuDriverUnlock(driver);
......
......@@ -4120,124 +4120,65 @@ cleanup:
}
int qemuProcessAutoDestroyInit(struct qemud_driver *driver)
static virDomainObjPtr
qemuProcessAutoDestroy(struct qemud_driver *driver,
virDomainObjPtr dom,
virConnectPtr conn)
{
if (!(driver->autodestroy = virHashCreate(5, NULL)))
return -1;
return 0;
}
struct qemuProcessAutoDestroyData {
struct qemud_driver *driver;
virConnectPtr conn;
};
static void qemuProcessAutoDestroyDom(void *payload,
const void *name,
void *opaque)
{
struct qemuProcessAutoDestroyData *data = opaque;
virConnectPtr conn = payload;
const char *uuidstr = name;
unsigned char uuid[VIR_UUID_BUFLEN];
virDomainObjPtr dom;
qemuDomainObjPrivatePtr priv;
qemuDomainObjPrivatePtr priv = dom->privateData;
virDomainEventPtr event = NULL;
VIR_DEBUG("conn=%p uuidstr=%s thisconn=%p", conn, uuidstr, data->conn);
VIR_DEBUG("vm=%s, conn=%p", dom->def->name, conn);
if (data->conn != conn)
return;
if (virUUIDParse(uuidstr, uuid) < 0) {
VIR_WARN("Failed to parse %s", uuidstr);
return;
}
if (!(dom = virDomainFindByUUID(&data->driver->domains,
uuid))) {
VIR_DEBUG("No domain object to kill");
return;
}
priv = dom->privateData;
if (priv->job.asyncJob) {
VIR_DEBUG("vm=%s has long-term job active, cancelling",
dom->def->name);
qemuDomainObjDiscardAsyncJob(data->driver, dom);
qemuDomainObjDiscardAsyncJob(driver, dom);
}
if (qemuDomainObjBeginJobWithDriver(data->driver, dom,
if (qemuDomainObjBeginJobWithDriver(driver, dom,
QEMU_JOB_DESTROY) < 0)
goto cleanup;
VIR_DEBUG("Killing domain");
qemuProcessStop(data->driver, dom, 1, VIR_DOMAIN_SHUTOFF_DESTROYED);
qemuProcessStop(driver, dom, 1, VIR_DOMAIN_SHUTOFF_DESTROYED);
virDomainAuditStop(dom, "destroyed");
event = virDomainEventNewFromObj(dom,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
if (qemuDomainObjEndJob(data->driver, dom) == 0)
if (qemuDomainObjEndJob(driver, dom) == 0)
dom = NULL;
if (dom && !dom->persistent)
qemuDomainRemoveInactive(data->driver, dom);
cleanup:
if (dom)
virDomainObjUnlock(dom);
qemuDomainRemoveInactive(driver, dom);
if (event)
qemuDomainEventQueue(data->driver, event);
virHashRemoveEntry(data->driver->autodestroy, uuidstr);
}
/*
* Precondition: driver is locked
*/
void qemuProcessAutoDestroyRun(struct qemud_driver *driver, virConnectPtr conn)
{
struct qemuProcessAutoDestroyData data = {
driver, conn
};
VIR_DEBUG("conn=%p", conn);
virHashForEach(driver->autodestroy, qemuProcessAutoDestroyDom, &data);
}
qemuDomainEventQueue(driver, event);
void qemuProcessAutoDestroyShutdown(struct qemud_driver *driver)
{
virHashFree(driver->autodestroy);
cleanup:
return dom;
}
int qemuProcessAutoDestroyAdd(struct qemud_driver *driver,
virDomainObjPtr vm,
virConnectPtr conn)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(vm->def->uuid, uuidstr);
VIR_DEBUG("vm=%s uuid=%s conn=%p", vm->def->name, uuidstr, conn);
if (virHashAddEntry(driver->autodestroy, uuidstr, conn) < 0)
return -1;
return 0;
VIR_DEBUG("vm=%s, conn=%p", vm->def->name, conn);
return qemuDriverCloseCallbackSet(driver, vm, conn,
qemuProcessAutoDestroy);
}
int qemuProcessAutoDestroyRemove(struct qemud_driver *driver,
virDomainObjPtr vm)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(vm->def->uuid, uuidstr);
VIR_DEBUG("vm=%s uuid=%s", vm->def->name, uuidstr);
if (virHashRemoveEntry(driver->autodestroy, uuidstr) < 0)
return -1;
return 0;
VIR_DEBUG("vm=%s", vm->def->name);
return qemuDriverCloseCallbackUnset(driver, vm, qemuProcessAutoDestroy);
}
bool qemuProcessAutoDestroyActive(struct qemud_driver *driver,
virDomainObjPtr vm)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(vm->def->uuid, uuidstr);
VIR_DEBUG("vm=%s uuid=%s", vm->def->name, uuidstr);
if (virHashLookup(driver->autodestroy, uuidstr) != NULL)
return true;
return false;
qemuDriverCloseCallback cb;
VIR_DEBUG("vm=%s", vm->def->name);
cb = qemuDriverCloseCallbackGet(driver, vm, NULL);
return cb == qemuProcessAutoDestroy;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册