mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-31 18:15:25 +00:00
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:
parent
0f7f4b160b
commit
b1029b6f6f
@ -191,6 +191,8 @@ struct _virConnect {
|
||||
virConnectCloseFunc closeCallback;
|
||||
void *closeOpaque;
|
||||
virFreeCallback closeFreeCallback;
|
||||
bool closeDispatch;
|
||||
unsigned closeUnregisterCount;
|
||||
|
||||
int refs; /* reference count */
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user