提交 4b4fbfe4 编写于 作者: N Nikolay Shirokovskiy 提交者: Daniel P. Berrange

vz: implement connection close notification

Signed-off-by: NNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
上级 f484310a
...@@ -254,6 +254,9 @@ vzOpenDefault(virConnectPtr conn) ...@@ -254,6 +254,9 @@ vzOpenDefault(virConnectPtr conn)
if (prlsdkSubscribeToPCSEvents(privconn)) if (prlsdkSubscribeToPCSEvents(privconn))
goto error; goto error;
if (!(privconn->closeCallback = virNewConnectCloseCallbackData()))
goto error;
conn->privateData = privconn; conn->privateData = privconn;
if (prlsdkLoadDomains(privconn)) if (prlsdkLoadDomains(privconn))
...@@ -262,6 +265,8 @@ vzOpenDefault(virConnectPtr conn) ...@@ -262,6 +265,8 @@ vzOpenDefault(virConnectPtr conn)
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
error: error:
virObjectUnref(privconn->closeCallback);
privconn->closeCallback = NULL;
virObjectUnref(privconn->domains); virObjectUnref(privconn->domains);
virObjectUnref(privconn->caps); virObjectUnref(privconn->caps);
virObjectEventStateFree(privconn->domainEventState); virObjectEventStateFree(privconn->domainEventState);
...@@ -329,6 +334,8 @@ vzConnectClose(virConnectPtr conn) ...@@ -329,6 +334,8 @@ vzConnectClose(virConnectPtr conn)
virObjectUnref(privconn->caps); virObjectUnref(privconn->caps);
virObjectUnref(privconn->xmlopt); virObjectUnref(privconn->xmlopt);
virObjectUnref(privconn->domains); virObjectUnref(privconn->domains);
virObjectUnref(privconn->closeCallback);
privconn->closeCallback = NULL;
virObjectEventStateFree(privconn->domainEventState); virObjectEventStateFree(privconn->domainEventState);
prlsdkDisconnect(privconn); prlsdkDisconnect(privconn);
conn->privateData = NULL; conn->privateData = NULL;
...@@ -1470,6 +1477,56 @@ vzNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED) ...@@ -1470,6 +1477,56 @@ vzNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
return freeMem; return freeMem;
} }
static int
vzConnectRegisterCloseCallback(virConnectPtr conn,
virConnectCloseFunc cb,
void *opaque,
virFreeCallback freecb)
{
vzConnPtr privconn = conn->privateData;
int ret = -1;
vzDriverLock(privconn);
if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != NULL) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A close callback is already registered"));
goto cleanup;
}
virConnectCloseCallbackDataRegister(privconn->closeCallback, conn, cb,
opaque, freecb);
ret = 0;
cleanup:
vzDriverUnlock(privconn);
return ret;
}
static int
vzConnectUnregisterCloseCallback(virConnectPtr conn, virConnectCloseFunc cb)
{
vzConnPtr privconn = conn->privateData;
int ret = -1;
vzDriverLock(privconn);
if (virConnectCloseCallbackDataGetCallback(privconn->closeCallback) != cb) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("A different callback was requested"));
goto cleanup;
}
virConnectCloseCallbackDataUnregister(privconn->closeCallback, cb);
ret = 0;
cleanup:
vzDriverUnlock(privconn);
return ret;
}
static virHypervisorDriver vzDriver = { static virHypervisorDriver vzDriver = {
.name = "vz", .name = "vz",
.connectOpen = vzConnectOpen, /* 0.10.0 */ .connectOpen = vzConnectOpen, /* 0.10.0 */
...@@ -1532,6 +1589,8 @@ static virHypervisorDriver vzDriver = { ...@@ -1532,6 +1589,8 @@ static virHypervisorDriver vzDriver = {
.domainBlockStatsFlags = vzDomainBlockStatsFlags, /* 1.2.17 */ .domainBlockStatsFlags = vzDomainBlockStatsFlags, /* 1.2.17 */
.domainInterfaceStats = vzDomainInterfaceStats, /* 1.2.17 */ .domainInterfaceStats = vzDomainInterfaceStats, /* 1.2.17 */
.domainMemoryStats = vzDomainMemoryStats, /* 1.2.17 */ .domainMemoryStats = vzDomainMemoryStats, /* 1.2.17 */
.connectRegisterCloseCallback = vzConnectRegisterCloseCallback, /* 1.3.2 */
.connectUnregisterCloseCallback = vzConnectUnregisterCloseCallback, /* 1.3.2 */
}; };
static virConnectDriver vzConnectDriver = { static virConnectDriver vzConnectDriver = {
......
...@@ -1710,6 +1710,10 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) ...@@ -1710,6 +1710,10 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
/* above function takes own of event */ /* above function takes own of event */
prlEvent = PRL_INVALID_HANDLE; prlEvent = PRL_INVALID_HANDLE;
break; break;
case PET_DSP_EVT_DISP_CONNECTION_CLOSED:
virConnectCloseCallbackDataCall(privconn->closeCallback,
VIR_CONNECT_CLOSE_REASON_EOF);
break;
default: default:
VIR_DEBUG("Skipping event of type %d", prlEventType); VIR_DEBUG("Skipping event of type %d", prlEventType);
} }
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
# include "conf/virdomainobjlist.h" # include "conf/virdomainobjlist.h"
# include "conf/domain_event.h" # include "conf/domain_event.h"
# include "virthread.h" # include "virthread.h"
# include "datatypes.h"
# define vzParseError() \ # define vzParseError() \
virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__, \ virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__, \
...@@ -59,6 +60,8 @@ struct _vzConn { ...@@ -59,6 +60,8 @@ struct _vzConn {
virDomainXMLOptionPtr xmlopt; virDomainXMLOptionPtr xmlopt;
virObjectEventStatePtr domainEventState; virObjectEventStatePtr domainEventState;
const char *drivername; const char *drivername;
/* Immutable pointer, self-locking APIs */
virConnectCloseCallbackDataPtr closeCallback;
}; };
typedef struct _vzConn vzConn; typedef struct _vzConn vzConn;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册