mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
lxc: switch to virCloseCallbacks API
This commit is contained in:
parent
4deeb74d01
commit
c86950533a
@ -1206,6 +1206,7 @@ virCgroupSetMemSwapHardLimit;
|
|||||||
|
|
||||||
# util/virclosecallbacks.h
|
# util/virclosecallbacks.h
|
||||||
virCloseCallbacksGet;
|
virCloseCallbacksGet;
|
||||||
|
virCloseCallbacksGetConn;
|
||||||
virCloseCallbacksNew;
|
virCloseCallbacksNew;
|
||||||
virCloseCallbacksRun;
|
virCloseCallbacksRun;
|
||||||
virCloseCallbacksSet;
|
virCloseCallbacksSet;
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
# include "vircgroup.h"
|
# include "vircgroup.h"
|
||||||
# include "virsysinfo.h"
|
# include "virsysinfo.h"
|
||||||
# include "virusb.h"
|
# include "virusb.h"
|
||||||
|
# include "virclosecallbacks.h"
|
||||||
|
|
||||||
# define LXC_DRIVER_NAME "LXC"
|
# define LXC_DRIVER_NAME "LXC"
|
||||||
|
|
||||||
@ -101,11 +102,8 @@ struct _virLXCDriver {
|
|||||||
/* Immutable pointer. self-locking APIs */
|
/* Immutable pointer. self-locking APIs */
|
||||||
virSecurityManagerPtr securityManager;
|
virSecurityManagerPtr securityManager;
|
||||||
|
|
||||||
/* Mapping of 'char *uuidstr' -> virConnectPtr
|
/* Immutable pointer, self-locking APIs */
|
||||||
* of guests which will be automatically killed
|
virCloseCallbacksPtr closeCallbacks;
|
||||||
* when the virConnectPtr is closed.
|
|
||||||
* Immutable pointer. Unsafe APIs. XXX */
|
|
||||||
virHashTablePtr autodestroy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virLXCDriverConfigPtr virLXCDriverConfigNew(void);
|
virLXCDriverConfigPtr virLXCDriverConfigNew(void);
|
||||||
|
@ -163,7 +163,7 @@ static int lxcConnectClose(virConnectPtr conn)
|
|||||||
virLXCDriverPtr driver = conn->privateData;
|
virLXCDriverPtr driver = conn->privateData;
|
||||||
|
|
||||||
lxcDriverLock(driver);
|
lxcDriverLock(driver);
|
||||||
virLXCProcessAutoDestroyRun(driver, conn);
|
virCloseCallbacksRun(driver->closeCallbacks, conn, driver->domains, driver);
|
||||||
lxcDriverUnlock(driver);
|
lxcDriverUnlock(driver);
|
||||||
|
|
||||||
conn->privateData = NULL;
|
conn->privateData = NULL;
|
||||||
@ -1591,7 +1591,7 @@ static int lxcStateInitialize(bool privileged,
|
|||||||
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit()))
|
if (!(lxc_driver->xmlopt = lxcDomainXMLConfInit()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virLXCProcessAutoDestroyInit(lxc_driver) < 0)
|
if (!(lxc_driver->closeCallbacks = virCloseCallbacksNew()))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Get all the running persistent or transient configs first */
|
/* Get all the running persistent or transient configs first */
|
||||||
@ -1681,7 +1681,7 @@ static int lxcStateCleanup(void)
|
|||||||
virObjectUnref(lxc_driver->domains);
|
virObjectUnref(lxc_driver->domains);
|
||||||
virDomainEventStateFree(lxc_driver->domainEventState);
|
virDomainEventStateFree(lxc_driver->domainEventState);
|
||||||
|
|
||||||
virLXCProcessAutoDestroyShutdown(lxc_driver);
|
virObjectUnref(lxc_driver->closeCallbacks);
|
||||||
|
|
||||||
virSysinfoDefFree(lxc_driver->hostsysinfo);
|
virSysinfoDefFree(lxc_driver->hostsysinfo);
|
||||||
|
|
||||||
|
@ -54,122 +54,45 @@
|
|||||||
|
|
||||||
#define START_POSTFIX ": starting up\n"
|
#define START_POSTFIX ": starting up\n"
|
||||||
|
|
||||||
int virLXCProcessAutoDestroyInit(virLXCDriverPtr driver)
|
static virDomainObjPtr
|
||||||
|
lxcProcessAutoDestroy(virDomainObjPtr dom,
|
||||||
|
virConnectPtr conn,
|
||||||
|
void *opaque)
|
||||||
{
|
{
|
||||||
if (!(driver->autodestroy = virHashCreate(5, NULL)))
|
virLXCDriverPtr driver = opaque;
|
||||||
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;
|
|
||||||
virDomainEventPtr event = NULL;
|
virDomainEventPtr event = NULL;
|
||||||
virLXCDomainObjPrivatePtr priv;
|
virLXCDomainObjPrivatePtr priv;
|
||||||
|
|
||||||
VIR_DEBUG("conn=%p uuidstr=%s thisconn=%p", conn, uuidstr, data->conn);
|
VIR_DEBUG("driver=%p dom=%s conn=%p", driver, dom->def->name, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv = dom->privateData;
|
priv = dom->privateData;
|
||||||
VIR_DEBUG("Killing domain");
|
VIR_DEBUG("Killing domain");
|
||||||
virLXCProcessStop(data->driver, dom, VIR_DOMAIN_SHUTOFF_DESTROYED);
|
virLXCProcessStop(driver, dom, 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);
|
||||||
priv->doneStopEvent = true;
|
priv->doneStopEvent = true;
|
||||||
|
|
||||||
if (dom && !dom->persistent)
|
if (dom && !dom->persistent) {
|
||||||
virDomainObjListRemove(data->driver->domains, dom);
|
virDomainObjListRemove(driver->domains, dom);
|
||||||
|
dom = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (dom)
|
|
||||||
virObjectUnlock(dom);
|
|
||||||
if (event)
|
if (event)
|
||||||
virDomainEventStateQueue(data->driver->domainEventState, event);
|
virDomainEventStateQueue(driver->domainEventState, event);
|
||||||
virHashRemoveEntry(data->driver->autodestroy, uuidstr);
|
|
||||||
|
return dom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Precondition: driver is locked
|
* 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
|
static int
|
||||||
virLXCProcessReboot(virLXCDriverPtr driver,
|
virLXCProcessReboot(virLXCDriverPtr driver,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
virConnectPtr conn = virLXCProcessAutoDestroyGetConn(driver, vm);
|
virConnectPtr conn = virCloseCallbacksGetConn(driver->closeCallbacks, vm);
|
||||||
int reason = vm->state.reason;
|
int reason = vm->state.reason;
|
||||||
bool autodestroy = false;
|
bool autodestroy = false;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -243,7 +166,8 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Stop autodestroy in case guest is restarted */
|
/* Stop autodestroy in case guest is restarted */
|
||||||
virLXCProcessAutoDestroyRemove(driver, vm);
|
virCloseCallbacksUnset(driver->closeCallbacks, vm,
|
||||||
|
lxcProcessAutoDestroy);
|
||||||
|
|
||||||
if (priv->monitor) {
|
if (priv->monitor) {
|
||||||
virLXCMonitorClose(priv->monitor);
|
virLXCMonitorClose(priv->monitor);
|
||||||
@ -1299,7 +1223,8 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (autoDestroy &&
|
if (autoDestroy &&
|
||||||
virLXCProcessAutoDestroyAdd(driver, vm, conn) < 0)
|
virCloseCallbacksSet(driver->closeCallbacks, vm,
|
||||||
|
conn, lxcProcessAutoDestroy) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virDomainObjSetDefTransient(driver->caps, driver->xmlopt,
|
if (virDomainObjSetDefTransient(driver->caps, driver->xmlopt,
|
||||||
|
@ -34,7 +34,6 @@ int virLXCProcessStop(virLXCDriverPtr driver,
|
|||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainShutoffReason reason);
|
virDomainShutoffReason reason);
|
||||||
|
|
||||||
int virLXCProcessAutoDestroyInit(virLXCDriverPtr driver);
|
|
||||||
void virLXCProcessAutoDestroyRun(virLXCDriverPtr driver,
|
void virLXCProcessAutoDestroyRun(virLXCDriverPtr driver,
|
||||||
virConnectPtr conn);
|
virConnectPtr conn);
|
||||||
void virLXCProcessAutoDestroyShutdown(virLXCDriverPtr driver);
|
void virLXCProcessAutoDestroyShutdown(virLXCDriverPtr driver);
|
||||||
|
@ -208,6 +208,30 @@ virCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks,
|
|||||||
return cb;
|
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 struct _virCloseCallbacksListEntry virCloseCallbacksListEntry;
|
||||||
typedef virCloseCallbacksListEntry *virCloseCallbacksListEntryPtr;
|
typedef virCloseCallbacksListEntry *virCloseCallbacksListEntryPtr;
|
||||||
struct _virCloseCallbacksListEntry {
|
struct _virCloseCallbacksListEntry {
|
||||||
|
@ -45,6 +45,9 @@ virCloseCallback
|
|||||||
virCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks,
|
virCloseCallbacksGet(virCloseCallbacksPtr closeCallbacks,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virConnectPtr conn);
|
virConnectPtr conn);
|
||||||
|
virConnectPtr
|
||||||
|
virCloseCallbacksGetConn(virCloseCallbacksPtr closeCallbacks,
|
||||||
|
virDomainObjPtr vm);
|
||||||
void
|
void
|
||||||
virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks,
|
virCloseCallbacksRun(virCloseCallbacksPtr closeCallbacks,
|
||||||
virConnectPtr conn,
|
virConnectPtr conn,
|
||||||
|
Loading…
Reference in New Issue
Block a user