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

qemu: Make autodestroy utilize connection close callbacks

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