--- src/libvirt_private.syms | 1 + src/lxc/lxc_conf.h | 5 +- src/lxc/lxc_driver.c | 6 +-- src/lxc/lxc_process.c | 113 ++++++++----------------------------------- src/lxc/lxc_process.h | 1 - src/util/virclosecallbacks.c | 24 +++++++++ src/util/virclosecallbacks.h | 3 ++ 7 files changed, 53 insertions(+), 100 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 53b1153..f55ab57 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1206,6 +1206,7 @@ virCgroupSetMemSwapHardLimit; # util/virclosecallbacks.h virCloseCallbacksGet; +virCloseCallbacksGetConn; virCloseCallbacksNew; virCloseCallbacksRun; virCloseCallbacksSet; diff --git a/src/lxc/lxc_conf.h b/src/lxc/lxc_conf.h index 831e3e5..6c81368 100644 --- a/src/lxc/lxc_conf.h +++ b/src/lxc/lxc_conf.h @@ -35,6 +35,7 @@ # include "vircgroup.h" # include "virsysinfo.h" # include "virusb.h" +# include "virclosecallbacks.h" # define LXC_DRIVER_NAME "LXC" @@ -103,8 +104,8 @@ struct _virLXCDriver { /* Immutable pointer. self-locking APIs */ virSecurityManagerPtr securityManager; - /* Immutable pointer. Unsafe APIs. XXX */ - virHashTablePtr autodestroy; + /* Immutable pointer, self-locking APIs */ + virCloseCallbacksPtr closeCallbacks; }; virLXCDriverConfigPtr virLXCDriverConfigNew(void); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 855dad3..60d21e3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -163,7 +163,7 @@ static int lxcConnectClose(virConnectPtr conn) virLXCDriverPtr driver = conn->privateData; lxcDriverLock(driver); - virLXCProcessAutoDestroyRun(driver, conn); + virCloseCallbacksRun(driver->closeCallbacks, conn, driver->domains, driver); lxcDriverUnlock(driver); conn->privateData = NULL; @@ -1563,7 +1563,7 @@ static int lxcStateInitialize(bool privileged, if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit())) goto cleanup; - if (virLXCProcessAutoDestroyInit(lxc_driver) < 0) + if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew())) goto cleanup; /* Get all the running persistent or transient configs first */ @@ -1653,7 +1653,7 @@ static int lxcStateCleanup(void) virObjectUnref(lxc_driver->domains); virDomainEventStateFree(lxc_driver->domainEventState); - virLXCProcessAutoDestroyShutdown(lxc_driver); + virObjectUnref(lxc_driver->closeCallbacks); virSysinfoDefFree(lxc_driver->hostsysinfo); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 4b83729..931aee9 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -54,122 +54,45 @@ #define START_POSTFIX ": starting up\n" -int virLXCProcessAutoDestroyInit(virLXCDriverPtr driver) +static virDomainObjPtr +lxcProcessAutoDestroy(void *drv, + virDomainObjPtr dom, + virConnectPtr conn) { - if (!(driver->autodestroy = virHashCreate(5, NULL))) - return -1; - - return 0; -} - -struct virLXCProcessAutoDestroyData { - virLXCDriverPtr driver; - virConnectPtr conn; -}; - -static void virLXCProcessAutoDestroyDom(void *payload, - const void *name, - void *opaque) -{ - struct virLXCProcessAutoDestroyData *data = opaque; - virConnectPtr conn = payload; - const char *uuidstr = name; - unsigned char uuid[VIR_UUID_BUFLEN]; - virDomainObjPtr dom; + virLXCDriverPtr driver = drv; virDomainEventPtr event = NULL; virLXCDomainObjPrivatePtr priv; - VIR_DEBUG("conn=%p uuidstr=%s thisconn=%p", conn, uuidstr, data->conn); - - if (data->conn != conn) - return; - - if (virUUIDParse(uuidstr, uuid) < 0) { - VIR_WARN("Failed to parse %s", uuidstr); - return; - } - - if (!(dom = virDomainObjListFindByUUID(data->driver->domains, - uuid))) { - VIR_DEBUG("No domain object to kill"); - return; - } + VIR_DEBUG("driver=%p dom=%s conn=%p", driver, dom->def->name, conn); priv = dom->privateData; VIR_DEBUG("Killing domain"); - virLXCProcessStop(data->driver, dom, VIR_DOMAIN_SHUTOFF_DESTROYED); + virLXCProcessStop(driver, dom, VIR_DOMAIN_SHUTOFF_DESTROYED); virDomainAuditStop(dom, "destroyed"); event = virDomainEventNewFromObj(dom, VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED_DESTROYED); priv->doneStopEvent = true; - if (dom && !dom->persistent) - virDomainObjListRemove(data->driver->domains, dom); + if (dom && !dom->persistent) { + virDomainObjListRemove(driver->domains, dom); + dom = NULL; + } - if (dom) - virObjectUnlock(dom); if (event) - virDomainEventStateQueue(data->driver->domainEventState, event); - virHashRemoveEntry(data->driver->autodestroy, uuidstr); + virDomainEventStateQueue(driver->domainEventState, event); + + return dom; } /* * Precondition: driver is locked */ -void virLXCProcessAutoDestroyRun(virLXCDriverPtr driver, virConnectPtr conn) -{ - struct virLXCProcessAutoDestroyData data = { - driver, conn - }; - VIR_DEBUG("conn=%p", conn); - virHashForEach(driver->autodestroy, virLXCProcessAutoDestroyDom, &data); -} - -void virLXCProcessAutoDestroyShutdown(virLXCDriverPtr driver) -{ - virHashFree(driver->autodestroy); -} - -int virLXCProcessAutoDestroyAdd(virLXCDriverPtr 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; -} - -int virLXCProcessAutoDestroyRemove(virLXCDriverPtr 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; -} - -static virConnectPtr -virLXCProcessAutoDestroyGetConn(virLXCDriverPtr driver, - virDomainObjPtr vm) -{ - char uuidstr[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(vm->def->uuid, uuidstr); - VIR_DEBUG("vm=%s uuid=%s", vm->def->name, uuidstr); - return virHashLookup(driver->autodestroy, uuidstr); -} - - static int virLXCProcessReboot(virLXCDriverPtr driver, virDomainObjPtr vm) { - virConnectPtr conn = virLXCProcessAutoDestroyGetConn(driver, vm); + virConnectPtr conn = virCloseCallbacksGetConn(driver->closeCallbacks, vm); int reason = vm->state.reason; bool autodestroy = false; int ret = -1; @@ -242,7 +165,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, } /* Stop autodestroy in case guest is restarted */ - virLXCProcessAutoDestroyRemove(driver, vm); + virCloseCallbacksUnset(driver->closeCallbacks, vm, + lxcProcessAutoDestroy); if (priv->monitor) { virLXCMonitorClose(priv->monitor); @@ -1288,7 +1212,8 @@ int virLXCProcessStart(virConnectPtr conn, } if (autoDestroy && - virLXCProcessAutoDestroyAdd(driver, vm, conn) < 0) + virCloseCallbacksSet(driver->closeCallbacks, vm, + conn, lxcProcessAutoDestroy) < 0) goto error; if (virDomainObjSetDefTransient(driver->caps, driver->xmlopt, diff --git a/src/lxc/lxc_process.h b/src/lxc/lxc_process.h index 779cc5f..4403ae8 100644 --- a/src/lxc/lxc_process.h +++ b/src/lxc/lxc_process.h @@ -33,7 +33,6 @@ int virLXCProcessStop(virLXCDriverPtr driver, virDomainObjPtr vm, virDomainShutoffReason reason); -int virLXCProcessAutoDestroyInit(virLXCDriverPtr driver); void virLXCProcessAutoDestroyRun(virLXCDriverPtr driver, virConnectPtr conn); void virLXCProcessAutoDestroyShutdown(virLXCDriverPtr driver); diff --git a/src/util/virclosecallbacks.c b/src/util/virclosecallbacks.c index a926456..1de822d 100644 --- a/src/util/virclosecallbacks.c +++ b/src/util/virclosecallbacks.c @@ -208,6 +208,30 @@ virCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks, return cb; } +virConnectPtr +virCloseCallbacksGetConn(virCloseCallbacksPtr closeCallbacks, + virDomainObjPtr vm) +{ + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDriverCloseDefPtr closeDef; + virConnectPtr conn = NULL; + + virUUIDFormat(vm->def->uuid, uuidstr); + VIR_DEBUG("vm=%s, uuid=%s", vm->def->name, uuidstr); + + virObjectLock(closeCallbacks); + + closeDef = virHashLookup(closeCallbacks->list, uuidstr); + if (closeDef) + conn = closeDef->conn; + + virObjectUnlock(closeCallbacks); + + VIR_DEBUG("conn=%p", conn); + return conn; +} + + typedef struct _virCloseCallbacksListEntry virCloseCallbacksListEntry; typedef virCloseCallbacksListEntry *virCloseCallbacksListEntryPtr; struct _virCloseCallbacksListEntry { diff --git a/src/util/virclosecallbacks.h b/src/util/virclosecallbacks.h index 9db641f..ca02e5c 100644 --- a/src/util/virclosecallbacks.h +++ b/src/util/virclosecallbacks.h @@ -45,6 +45,9 @@ virCloseCallback virCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks, virDomainObjPtr vm, virConnectPtr conn); +virConnectPtr +virCloseCallbacksGetConn(virCloseCallbacksPtr closeCallbacks, + virDomainObjPtr vm); void virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks, virConnectPtr conn, -- 1.8.1.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list