VIR_FREE(state);
}
+
+static void virDomainEventStateFlush(virDomainEventStatePtr state);
+
+static void
+virDomainEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
+{
+ virDomainEventStatePtr state = opaque;
+
+ virDomainEventStateFlush(state);
+}
+
/**
* virDomainEventStateNew:
- * @timeout_cb: virEventTimeoutCallback to call when timer expires
- * @timeout_opaque: Data for timeout_cb
- * @timeout_free: Optional virFreeCallback for freeing timeout_opaque
* @requireTimer: If true, return an error if registering the timer fails.
* This is fatal for drivers that sit behind the daemon
* (qemu, lxc), since there should always be a event impl
* registered.
*/
virDomainEventStatePtr
-virDomainEventStateNew(virEventTimeoutCallback timeout_cb,
- void *timeout_opaque,
- virFreeCallback timeout_free,
- bool requireTimer)
+virDomainEventStateNew(bool requireTimer)
{
virDomainEventStatePtr state = NULL;
}
if ((state->timer = virEventAddTimeout(-1,
- timeout_cb,
- timeout_opaque,
- timeout_free)) < 0) {
+ virDomainEventTimer,
+ state,
+ NULL)) < 0) {
if (requireTimer == false) {
VIR_DEBUG("virEventAddTimeout failed: No addTimeoutImpl defined. "
"continuing without events.");
}
-void virDomainEventDispatchDefaultFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque ATTRIBUTE_UNUSED)
+typedef void (*virDomainEventDispatchFunc)(virConnectPtr conn,
+ virDomainEventPtr event,
+ virConnectDomainEventGenericCallback cb,
+ void *cbopaque,
+ void *opaque);
+
+
+static void
+virDomainEventDispatchDefaultFunc(virConnectPtr conn,
+ virDomainEventPtr event,
+ virConnectDomainEventGenericCallback cb,
+ void *cbopaque,
+ void *opaque ATTRIBUTE_UNUSED)
{
virDomainPtr dom = virGetDomain(conn, event->dom.name, event->dom.uuid);
if (!dom)
}
}
-void virDomainEventDispatch(virDomainEventPtr event,
- virDomainEventCallbackListPtr callbacks,
- virDomainEventDispatchFunc dispatch,
- void *opaque)
+
+static void
+virDomainEventDispatch(virDomainEventPtr event,
+ virDomainEventCallbackListPtr callbacks,
+ virDomainEventDispatchFunc dispatch,
+ void *opaque)
{
int i;
/* Cache this now, since we may be dropping the lock,
}
-void virDomainEventQueueDispatch(virDomainEventQueuePtr queue,
- virDomainEventCallbackListPtr callbacks,
- virDomainEventDispatchFunc dispatch,
- void *opaque)
+static void
+virDomainEventQueueDispatch(virDomainEventQueuePtr queue,
+ virDomainEventCallbackListPtr callbacks,
+ virDomainEventDispatchFunc dispatch,
+ void *opaque)
{
int i;
virDomainEventStateUnlock(state);
}
-void
-virDomainEventStateFlush(virDomainEventStatePtr state,
- virDomainEventDispatchFunc dispatchFunc,
- void *opaque)
+
+static void
+virDomainEventStateDispatchFunc(virConnectPtr conn,
+ virDomainEventPtr event,
+ virConnectDomainEventGenericCallback cb,
+ void *cbopaque,
+ void *opaque)
+{
+ virDomainEventStatePtr state = opaque;
+
+ /* Drop the lock whle dispatching, for sake of re-entrancy */
+ virDomainEventStateUnlock(state);
+ virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
+ virDomainEventStateLock(state);
+}
+
+
+static void
+virDomainEventStateFlush(virDomainEventStatePtr state)
{
virDomainEventQueue tempQueue;
virDomainEventQueueDispatch(&tempQueue,
state->callbacks,
- dispatchFunc,
- opaque);
+ virDomainEventStateDispatchFunc,
+ state);
/* Purge any deleted callbacks */
virDomainEventStateLock(state);
*
* Returns: the number of lifecycle callbacks now registered, or -1 on error
*/
-int virDomainEventStateRegister(virConnectPtr conn,
- virDomainEventStatePtr state,
- virConnectDomainEventCallback callback,
- void *opaque,
- virFreeCallback freecb)
+int
+virDomainEventStateRegister(virConnectPtr conn,
+ virDomainEventStatePtr state,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
{
int ret;
virDomainEventStateLock(state);
*
* Returns: the number of callbacks now registered, or -1 on error
*/
-int virDomainEventStateRegisterID(virConnectPtr conn,
- virDomainEventStatePtr state,
- virDomainPtr dom,
- int eventID,
- virConnectDomainEventGenericCallback cb,
- void *opaque,
- virFreeCallback freecb,
- int *callbackID)
+int
+virDomainEventStateRegisterID(virConnectPtr conn,
+ virDomainEventStatePtr state,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback cb,
+ void *opaque,
+ virFreeCallback freecb,
+ int *callbackID)
{
int ret;
virDomainEventStateLock(state);
void virDomainEventStateFree(virDomainEventStatePtr state);
virDomainEventStatePtr
-virDomainEventStateNew(virEventTimeoutCallback timeout_cb,
- void *timeout_opaque,
- virFreeCallback timeout_free,
- bool requireTimer)
- ATTRIBUTE_NONNULL(1);
-
-typedef void (*virDomainEventDispatchFunc)(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque);
-void virDomainEventDispatchDefaultFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque);
-
-void virDomainEventDispatch(virDomainEventPtr event,
- virDomainEventCallbackListPtr cbs,
- virDomainEventDispatchFunc dispatch,
- void *opaque);
-void virDomainEventQueueDispatch(virDomainEventQueuePtr queue,
- virDomainEventCallbackListPtr cbs,
- virDomainEventDispatchFunc dispatch,
- void *opaque);
-
+virDomainEventStateNew(bool requireTimer);
void
virDomainEventStateQueue(virDomainEventStatePtr state,
virDomainEventPtr event)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-void
-virDomainEventStateFlush(virDomainEventStatePtr state,
- virDomainEventDispatchFunc dispatchFunc,
- void *opaque)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virDomainEventStateRegister(virConnectPtr conn,
virDomainEventStatePtr state,
virConnectDomainEventCallback callback,
virDomainEventControlErrorNewFromObj;
virDomainEventDiskChangeNewFromDom;
virDomainEventDiskChangeNewFromObj;
-virDomainEventDispatch;
-virDomainEventDispatchDefaultFunc;
virDomainEventFree;
virDomainEventGraphicsNewFromDom;
virDomainEventGraphicsNewFromObj;
virDomainEventStateEventID;
virDomainEventStateRegister;
virDomainEventStateRegisterID;
-virDomainEventStateFlush;
virDomainEventStateFree;
virDomainEventStateNew;
virDomainEventStateQueue;
VIR_FREE(priv);
}
-static void
-libxlDomainEventDispatchFunc(virConnectPtr conn, virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque, void *opaque)
-{
- libxlDriverPrivatePtr driver = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- libxlDriverUnlock(driver);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- libxlDriverLock(driver);
-}
-
-static void
-libxlDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- libxlDriverPrivatePtr driver = opaque;
-
- libxlDriverLock(driver);
- virDomainEventStateFlush(driver->domainEventState,
- libxlDomainEventDispatchFunc,
- driver);
- libxlDriverUnlock(driver);
-}
/* driver must be locked before calling */
static void
}
VIR_FREE(log_file);
- libxl_driver->domainEventState = virDomainEventStateNew(
- libxlDomainEventFlush,
- libxl_driver,
- NULL,
- false);
+ libxl_driver->domainEventState = virDomainEventStateNew(true);
if (!libxl_driver->domainEventState)
goto error;
}
-static void lxcDomainEventFlush(int timer, void *opaque);
static void lxcDomainEventQueue(lxc_driver_t *driver,
virDomainEventPtr event);
}
-static void lxcDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- lxc_driver_t *driver = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- lxcDriverUnlock(driver);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- lxcDriverLock(driver);
-}
-
-
-static void lxcDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- lxc_driver_t *driver = opaque;
-
- lxcDriverLock(driver);
- virDomainEventStateFlush(driver->domainEventState,
- lxcDomainEventDispatchFunc,
- driver);
- lxcDriverUnlock(driver);
-}
-
-
/* driver must be locked before calling */
static void lxcDomainEventQueue(lxc_driver_t *driver,
virDomainEventPtr event)
if (virDomainObjListInit(&lxc_driver->domains) < 0)
goto cleanup;
- lxc_driver->domainEventState = virDomainEventStateNew(lxcDomainEventFlush,
- lxc_driver,
- NULL,
- true);
+ lxc_driver->domainEventState = virDomainEventStateNew(true);
if (!lxc_driver->domainEventState)
goto cleanup;
return -1;
}
-static void qemuDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- struct qemud_driver *driver = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- qemuDriverUnlock(driver);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- qemuDriverLock(driver);
-}
-
-void qemuDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- struct qemud_driver *driver = opaque;
-
- qemuDriverLock(driver);
- virDomainEventStateFlush(driver->domainEventState,
- qemuDomainEventDispatchFunc,
- driver);
- qemuDriverUnlock(driver);
-}
-
/* driver must be locked before calling */
void qemuDomainEventQueue(struct qemud_driver *driver,
goto out_of_memory;
/* Init domain events */
- qemu_driver->domainEventState = virDomainEventStateNew(qemuDomainEventFlush,
- qemu_driver,
- NULL,
- true);
+ qemu_driver->domainEventState = virDomainEventStateNew(true);
if (!qemu_driver->domainEventState)
goto error;
static void make_nonnull_secret (remote_nonnull_secret *secret_dst, virSecretPtr secret_src);
static void make_nonnull_nwfilter (remote_nonnull_nwfilter *nwfilter_dst, virNWFilterPtr nwfilter_src);
static void make_nonnull_domain_snapshot (remote_nonnull_domain_snapshot *snapshot_dst, virDomainSnapshotPtr snapshot_src);
-static void remoteDomainEventQueueFlush(int timer, void *opaque);
static void remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event);
/*----------------------------------------------------------------------*/
}
}
- if (!(priv->domainEventState = virDomainEventStateNew(remoteDomainEventQueueFlush,
- conn,
- NULL,
- false)))
+ if (!(priv->domainEventState = virDomainEventStateNew(false)))
goto failed;
/* Successful. */
}
-static void remoteDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- struct private_data *priv = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- remoteDriverUnlock(priv);
- VIR_DEBUG("Dispatch event %p %p", event, conn);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- remoteDriverLock(priv);
-}
-
-static void
-remoteDomainEventQueueFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- virConnectPtr conn = opaque;
- struct private_data *priv = conn->privateData;
-
-
- remoteDriverLock(priv);
- VIR_DEBUG("Event queue flush %p", conn);
-
- virDomainEventStateFlush(priv->domainEventState,
- remoteDomainEventDispatchFunc,
- priv);
- remoteDriverUnlock(priv);
-}
-
static void
remoteDomainEventQueue(struct private_data *priv, virDomainEventPtr event)
{
__FUNCTION__, __LINE__, __VA_ARGS__)
static int testClose(virConnectPtr conn);
-static void testDomainEventFlush(int timer, void *opaque);
static void testDomainEventQueue(testConnPtr driver,
virDomainEventPtr event);
privconn = conn->privateData;
testDriverLock(privconn);
- privconn->domainEventState = virDomainEventStateNew(testDomainEventFlush,
- privconn,
- NULL,
- false);
+ privconn->domainEventState = virDomainEventStateNew(false);
if (!privconn->domainEventState) {
testDriverUnlock(privconn);
testClose(conn);
}
-static void testDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- testConnPtr driver = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- testDriverUnlock(driver);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- testDriverLock(driver);
-}
-
-static void testDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- testConnPtr driver = opaque;
-
- testDriverLock(driver);
- virDomainEventStateFlush(driver->domainEventState,
- testDomainEventDispatchFunc,
- driver);
- testDriverUnlock(driver);
-}
-
-
/* driver must be locked before calling */
static void testDomainEventQueue(testConnPtr driver,
virDomainEventPtr event)
virDomainObjPtr vm);
static int umlReadPidFile(struct uml_driver *driver,
virDomainObjPtr vm);
-static void umlDomainEventFlush(int timer, void *opaque);
static void umlDomainEventQueue(struct uml_driver *driver,
virDomainEventPtr event);
if (virDomainObjListInit(¨_driver->domains) < 0)
goto error;
- uml_driver->domainEventState = virDomainEventStateNew(umlDomainEventFlush,
- uml_driver,
- NULL,
- true);
+ uml_driver->domainEventState = virDomainEventStateNew(true);
if (!uml_driver->domainEventState)
goto error;
}
-static void umlDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- struct uml_driver *driver = opaque;
-
- /* Drop the lock whle dispatching, for sake of re-entrancy */
- umlDriverUnlock(driver);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- umlDriverLock(driver);
-}
-
-
-static void umlDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- struct uml_driver *driver = opaque;
-
- umlDriverLock(driver);
- virDomainEventStateFlush(driver->domainEventState,
- umlDomainEventDispatchFunc,
- driver);
- umlDriverUnlock(driver);
-}
-
-
/* driver must be locked before calling */
static void umlDomainEventQueue(struct uml_driver *driver,
virDomainEventPtr event)
}
-#if VBOX_API_VERSION == 2002
- /* No domainEventCallbacks in 2.2.* version */
-#else /* !(VBOX_API_VERSION == 2002) */
-
-static void
-vboxDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- vboxGlobalData *data = opaque;
-
- /*
- * Release the lock while the callback is running so that
- * we're re-entrant safe for callback work - the callback
- * may want to invoke other virt functions & we have already
- * protected the one piece of state we have - the callback
- * list
- */
- vboxDriverUnlock(data);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- vboxDriverLock(data);
-}
-
-
-static void vboxDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- virConnectPtr conn = opaque;
- vboxGlobalData *data = conn->privateData;
-
- vboxDriverLock(data);
- virDomainEventStateFlush(data->domainEvents,
- vboxDomainEventDispatchFunc,
- data);
- vboxDriverUnlock(data);
-}
-#endif /* !(VBOX_API_VERSION == 2002) */
-
-
static virDrvOpenStatus vboxOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
unsigned int flags)
#else /* !(VBOX_API_VERSION == 2002) */
- if (!(data->domainEvents = virDomainEventStateNew(vboxDomainEventFlush,
- data,
- NULL,
- true))) {
+ if (!(data->domainEvents = virDomainEventStateNew(true))) {
vboxUninitialize(data);
return VIR_DRV_OPEN_ERROR;
}
xenUnifiedDomainGetVcpus (virDomainPtr dom,
virVcpuInfoPtr info, int maxinfo,
unsigned char *cpumaps, int maplen);
-static void xenDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque);
/* The five Xen drivers below us. */
return VIR_DRV_OPEN_ERROR;
}
- if (!(priv->domainEvents = virDomainEventStateNew(xenDomainEventFlush,
- priv,
- NULL,
- false))) {
+ if (!(priv->domainEvents = virDomainEventStateNew(true))) {
virMutexDestroy(&priv->lock);
VIR_FREE(priv);
return VIR_DRV_OPEN_ERROR;
}
-static void
-xenUnifiedDomainEventDispatchFunc(virConnectPtr conn,
- virDomainEventPtr event,
- virConnectDomainEventGenericCallback cb,
- void *cbopaque,
- void *opaque)
-{
- xenUnifiedPrivatePtr priv = opaque;
-
- /*
- * Release the lock while the callback is running so that
- * we're re-entrant safe for callback work - the callback
- * may want to invoke other virt functions & we have already
- * protected the one piece of state we have - the callback
- * list
- */
- xenUnifiedUnlock(priv);
- virDomainEventDispatchDefaultFunc(conn, event, cb, cbopaque, NULL);
- xenUnifiedLock(priv);
-}
-
-static void xenDomainEventFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
-{
- virConnectPtr conn = opaque;
- xenUnifiedPrivatePtr priv = conn->privateData;
-
- xenUnifiedLock(priv);
- virDomainEventStateFlush(priv->domainEvents,
- xenUnifiedDomainEventDispatchFunc,
- priv);
- xenUnifiedUnlock(priv);
-}
-
-
/**
* xenUnifiedDomainEventDispatch:
* @priv: the connection to dispatch events on