Update remote driver to support the connection close callbacks

Update the remote driver to use the virNetClient close callback
to trigger the virConnectPtr close callbacks

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-07-19 15:58:38 +01:00
parent 0f7f4b160b
commit b1029b6f6f
3 changed files with 35 additions and 1 deletions

View File

@ -191,6 +191,8 @@ struct _virConnect {
virConnectCloseFunc closeCallback;
void *closeOpaque;
virFreeCallback closeFreeCallback;
bool closeDispatch;
unsigned closeUnregisterCount;
int refs; /* reference count */
};

View File

@ -18723,7 +18723,8 @@ int virConnectUnregisterCloseCallback(virConnectPtr conn,
}
conn->closeCallback = NULL;
if (conn->closeFreeCallback)
conn->closeUnregisterCount++;
if (!conn->closeDispatch && conn->closeFreeCallback)
conn->closeFreeCallback(conn->closeOpaque);
conn->closeFreeCallback = NULL;
conn->closeOpaque = NULL;

View File

@ -320,6 +320,32 @@ enum virDrvOpenRemoteFlags {
};
static void remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED,
int reason,
void *opaque)
{
virConnectPtr conn = opaque;
virMutexLock(&conn->lock);
if (conn->closeCallback) {
virConnectCloseFunc closeCallback = conn->closeCallback;
void *closeOpaque = conn->closeOpaque;
virFreeCallback closeFreeCallback = conn->closeFreeCallback;
unsigned closeUnregisterCount = conn->closeUnregisterCount;
VIR_DEBUG("Triggering connection close callback %p reason=%d",
conn->closeCallback, reason);
conn->closeDispatch = true;
virMutexUnlock(&conn->lock);
closeCallback(conn, reason, closeOpaque);
virMutexLock(&conn->lock);
conn->closeDispatch = false;
if (conn->closeUnregisterCount != closeUnregisterCount)
closeFreeCallback(closeOpaque);
}
virMutexUnlock(&conn->lock);
}
/*
* URIs that this driver needs to handle:
*
@ -667,6 +693,11 @@ doRemoteOpen (virConnectPtr conn,
#endif /* WIN32 */
} /* switch (transport) */
virNetClientSetCloseCallback(priv->client,
remoteClientCloseFunc,
conn, NULL);
if (!(priv->remoteProgram = virNetClientProgramNew(REMOTE_PROGRAM,
REMOTE_PROTOCOL_VERSION,
remoteDomainEvents,