Convert drivers to thread safe APIs for adding callbacks

* src/libxl/libxl_driver.c, src/lxc/lxc_driver.c,
  src/qemu/qemu_driver.c, src/remote/remote_driver.c,
  src/test/test_driver.c, src/uml/uml_driver.c,
  src/vbox/vbox_tmpl.c, src/xen/xen_driver.c: Convert
  to threadsafe APIs
This commit is contained in:
Daniel P. Berrange 2011-12-13 11:14:46 +00:00
parent 4f5326c315
commit 7b87a30f15
8 changed files with 86 additions and 96 deletions

View File

@ -1115,8 +1115,8 @@ libxlClose(virConnectPtr conn ATTRIBUTE_UNUSED)
libxlDriverPrivatePtr driver = conn->privateData;
libxlDriverLock(driver);
virDomainEventCallbackListRemoveConn(conn,
driver->domainEventState->callbacks);
virDomainEventStateDeregisterConn(conn,
driver->domainEventState);
libxlDriverUnlock(driver);
conn->privateData = NULL;
return 0;
@ -3404,9 +3404,9 @@ libxlDomainEventRegister(virConnectPtr conn,
int ret;
libxlDriverLock(driver);
ret = virDomainEventCallbackListAdd(conn,
driver->domainEventState->callbacks,
callback, opaque, freecb);
ret = virDomainEventStateRegister(conn,
driver->domainEventState,
callback, opaque, freecb);
libxlDriverUnlock(driver);
return ret;
@ -3851,10 +3851,10 @@ libxlDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eventID,
int ret;
libxlDriverLock(driver);
if (virDomainEventCallbackListAddID(conn,
driver->domainEventState->callbacks,
dom, eventID, callback, opaque,
freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn,
driver->domainEventState,
dom, eventID, callback, opaque,
freecb, &ret) < 0)
ret = -1;
libxlDriverUnlock(driver);

View File

@ -179,8 +179,8 @@ static int lxcClose(virConnectPtr conn)
lxc_driver_t *driver = conn->privateData;
lxcDriverLock(driver);
virDomainEventCallbackListRemoveConn(conn,
driver->domainEventState->callbacks);
virDomainEventStateDeregisterConn(conn,
driver->domainEventState);
lxcProcessAutoDestroyRun(driver, conn);
lxcDriverUnlock(driver);
@ -2126,9 +2126,9 @@ lxcDomainEventRegister(virConnectPtr conn,
int ret;
lxcDriverLock(driver);
ret = virDomainEventCallbackListAdd(conn,
driver->domainEventState->callbacks,
callback, opaque, freecb);
ret = virDomainEventStateRegister(conn,
driver->domainEventState,
callback, opaque, freecb);
lxcDriverUnlock(driver);
return ret;
@ -2164,10 +2164,10 @@ lxcDomainEventRegisterAny(virConnectPtr conn,
int ret;
lxcDriverLock(driver);
if (virDomainEventCallbackListAddID(conn,
driver->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn,
driver->domainEventState,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
lxcDriverUnlock(driver);

View File

@ -900,8 +900,8 @@ static int qemudClose(virConnectPtr conn) {
/* Get rid of callbacks registered for this conn */
qemuDriverLock(driver);
virDomainEventCallbackListRemoveConn(conn,
driver->domainEventState->callbacks);
virDomainEventStateDeregisterConn(conn,
driver->domainEventState);
qemuProcessAutoDestroyRun(driver, conn);
qemuDriverUnlock(driver);
@ -7959,9 +7959,9 @@ qemuDomainEventRegister(virConnectPtr conn,
int ret;
qemuDriverLock(driver);
ret = virDomainEventCallbackListAdd(conn,
driver->domainEventState->callbacks,
callback, opaque, freecb);
ret = virDomainEventStateRegister(conn,
driver->domainEventState,
callback, opaque, freecb);
qemuDriverUnlock(driver);
return ret;
@ -7997,10 +7997,10 @@ qemuDomainEventRegisterAny(virConnectPtr conn,
int ret;
qemuDriverLock(driver);
if (virDomainEventCallbackListAddID(conn,
driver->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn,
driver->domainEventState,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
qemuDriverUnlock(driver);

View File

@ -3124,13 +3124,8 @@ static int remoteDomainEventRegister(virConnectPtr conn,
remoteDriverLock(priv);
if (priv->domainEventState->timer < 0) {
remoteError(VIR_ERR_NO_SUPPORT, "%s", _("no event support"));
goto done;
}
if ((count = virDomainEventCallbackListAdd(conn, priv->domainEventState->callbacks,
callback, opaque, freecb)) < 0) {
if ((count = virDomainEventStateRegister(conn, priv->domainEventState,
callback, opaque, freecb)) < 0) {
remoteError(VIR_ERR_RPC, "%s", _("adding cb to list"));
goto done;
}
@ -3155,17 +3150,16 @@ static int remoteDomainEventDeregister(virConnectPtr conn,
{
struct private_data *priv = conn->privateData;
int rv = -1;
int count;
remoteDriverLock(priv);
if (virDomainEventStateDeregister(conn,
priv->domainEventState,
callback) < 0)
if ((count = virDomainEventStateDeregister(conn,
priv->domainEventState,
callback)) < 0)
goto done;
if (virDomainEventCallbackListCountID(conn,
priv->domainEventState->callbacks,
VIR_DOMAIN_EVENT_ID_LIFECYCLE) == 0) {
if (count == 0) {
/* Tell the server when we are the last callback deregistering */
if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
(xdrproc_t) xdr_void, (char *) NULL,
@ -3763,16 +3757,11 @@ static int remoteDomainEventRegisterAny(virConnectPtr conn,
remoteDriverLock(priv);
if (priv->domainEventState->timer < 0) {
remoteError(VIR_ERR_NO_SUPPORT, "%s", _("no event support"));
goto done;
}
if ((count = virDomainEventCallbackListAddID(conn,
priv->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb,
&callbackID)) < 0) {
if ((count = virDomainEventStateRegisterID(conn,
priv->domainEventState,
dom, eventID,
callback, opaque, freecb,
&callbackID)) < 0) {
remoteError(VIR_ERR_RPC, "%s", _("adding cb to list"));
goto done;
}
@ -3785,9 +3774,9 @@ static int remoteDomainEventRegisterAny(virConnectPtr conn,
if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY,
(xdrproc_t) xdr_remote_domain_events_register_any_args, (char *) &args,
(xdrproc_t) xdr_void, (char *)NULL) == -1) {
virDomainEventCallbackListRemoveID(conn,
priv->domainEventState->callbacks,
callbackID);
virDomainEventStateDeregisterID(conn,
priv->domainEventState,
callbackID);
goto done;
}
}
@ -3807,27 +3796,28 @@ static int remoteDomainEventDeregisterAny(virConnectPtr conn,
int rv = -1;
remote_domain_events_deregister_any_args args;
int eventID;
int count;
remoteDriverLock(priv);
if ((eventID = virDomainEventCallbackListEventID(conn,
priv->domainEventState->callbacks,
callbackID)) < 0) {
if ((eventID = virDomainEventStateEventID(conn,
priv->domainEventState,
callbackID)) < 0) {
remoteError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
goto done;
}
if (virDomainEventStateDeregisterID(conn,
priv->domainEventState,
callbackID) < 0)
if ((count = virDomainEventStateDeregisterID(conn,
priv->domainEventState,
callbackID)) < 0) {
remoteError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID);
goto done;
}
/* If that was the last callback for this eventID, we need to disable
* events on the server */
if (virDomainEventCallbackListCountID(conn,
priv->domainEventState->callbacks,
eventID) == 0) {
args.eventID = eventID;
if (count == 0) {
args.eventID = callbackID;
if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY,
(xdrproc_t) xdr_remote_domain_events_deregister_any_args, (char *) &args,

View File

@ -5404,9 +5404,9 @@ testDomainEventRegister(virConnectPtr conn,
int ret;
testDriverLock(driver);
ret = virDomainEventCallbackListAdd(conn,
driver->domainEventState->callbacks,
callback, opaque, freecb);
ret = virDomainEventStateRegister(conn,
driver->domainEventState,
callback, opaque, freecb);
testDriverUnlock(driver);
return ret;
@ -5442,10 +5442,10 @@ testDomainEventRegisterAny(virConnectPtr conn,
int ret;
testDriverLock(driver);
if (virDomainEventCallbackListAddID(conn,
driver->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn,
driver->domainEventState,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
testDriverUnlock(driver);

View File

@ -1194,8 +1194,8 @@ static int umlClose(virConnectPtr conn) {
struct uml_driver *driver = conn->privateData;
umlDriverLock(driver);
virDomainEventCallbackListRemoveConn(conn,
driver->domainEventState->callbacks);
virDomainEventStateDeregisterConn(conn,
driver->domainEventState);
umlProcessAutoDestroyRun(driver, conn);
umlDriverUnlock(driver);
@ -2447,9 +2447,9 @@ umlDomainEventRegister(virConnectPtr conn,
int ret;
umlDriverLock(driver);
ret = virDomainEventCallbackListAdd(conn,
driver->domainEventState->callbacks,
callback, opaque, freecb);
ret = virDomainEventStateRegister(conn,
driver->domainEventState,
callback, opaque, freecb);
umlDriverUnlock(driver);
return ret;
@ -2483,10 +2483,10 @@ umlDomainEventRegisterAny(virConnectPtr conn,
int ret;
umlDriverLock(driver);
if (virDomainEventCallbackListAddID(conn,
driver->domainEventState->callbacks,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn,
driver->domainEventState,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
umlDriverUnlock(driver);

View File

@ -7188,12 +7188,12 @@ static int vboxDomainEventRegister (virConnectPtr conn,
* later you can iterate over them
*/
ret = virDomainEventCallbackListAdd(conn, data->domainEvents->callbacks,
callback, opaque, freecb);
VIR_DEBUG("virDomainEventCallbackListAdd (ret = %d) ( conn: %p, "
"data->domainEvents->callbacks: %p, callback: %p, opaque: %p, "
"freecb: %p )", ret, conn, data->domainEvents->callbacks, callback,
opaque, freecb);
ret = virDomainEventStateRegister(conn, data->domainEvents,
callback, opaque, freecb);
VIR_DEBUG("virDomainEventStateRegister (ret = %d) ( conn: %p, "
"callback: %p, opaque: %p, "
"freecb: %p )", ret, conn, callback,
opaque, freecb);
}
}
@ -7280,13 +7280,13 @@ static int vboxDomainEventRegisterAny(virConnectPtr conn,
* later you can iterate over them
*/
if (virDomainEventCallbackListAddID(conn, data->domainEvents->callbacks,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
if (virDomainEventStateRegisterID(conn, data->domainEvents,
dom, eventID,
callback, opaque, freecb, &ret) < 0)
ret = -1;
VIR_DEBUG("virDomainEventCallbackListAddID (ret = %d) ( conn: %p, "
"data->domainEvents->callbacks: %p, callback: %p, opaque: %p, "
"freecb: %p )", ret, conn, data->domainEvents->callbacks, callback,
VIR_DEBUG("virDomainEventStateRegisterID (ret = %d) ( conn: %p, "
"callback: %p, opaque: %p, "
"freecb: %p )", ret, conn, callback,
opaque, freecb);
}
}

View File

@ -1847,8 +1847,8 @@ xenUnifiedDomainEventRegister(virConnectPtr conn,
return -1;
}
ret = virDomainEventCallbackListAdd(conn, priv->domainEvents->callbacks,
callback, opaque, freefunc);
ret = virDomainEventStateRegister(conn, priv->domainEvents,
callback, opaque, freefunc);
xenUnifiedUnlock(priv);
return (ret);
@ -1897,9 +1897,9 @@ xenUnifiedDomainEventRegisterAny(virConnectPtr conn,
return -1;
}
if (virDomainEventCallbackListAddID(conn, priv->domainEvents->callbacks,
dom, eventID,
callback, opaque, freefunc, &ret) < 0)
if (virDomainEventStateRegisterID(conn, priv->domainEvents,
dom, eventID,
callback, opaque, freefunc, &ret) < 0)
ret = -1;
xenUnifiedUnlock(priv);