Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx> --- src/vz/vz_driver.c | 39 +++++++++++++++++++++++++++++++++++++++ src/vz/vz_sdk.c | 4 ++++ src/vz/vz_utils.h | 3 +++ 3 files changed, 46 insertions(+) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f73f8ef..f48c7c9 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -254,6 +254,9 @@ vzOpenDefault(virConnectPtr conn) if (prlsdkSubscribeToPCSEvents(privconn)) goto error; + if (!(privconn->closeCallback = virNewConnectCloseCallbackData())) + goto error; + conn->privateData = privconn; if (prlsdkLoadDomains(privconn)) @@ -262,6 +265,8 @@ vzOpenDefault(virConnectPtr conn) return VIR_DRV_OPEN_SUCCESS; error: + virObjectUnref(privconn->closeCallback); + privconn->closeCallback = NULL; virObjectUnref(privconn->domains); virObjectUnref(privconn->caps); virObjectEventStateFree(privconn->domainEventState); @@ -329,6 +334,8 @@ vzConnectClose(virConnectPtr conn) virObjectUnref(privconn->caps); virObjectUnref(privconn->xmlopt); virObjectUnref(privconn->domains); + virObjectUnref(privconn->closeCallback); + privconn->closeCallback = NULL; virObjectEventStateFree(privconn->domainEventState); prlsdkDisconnect(privconn); conn->privateData = NULL; @@ -1460,6 +1467,36 @@ vzNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED) return freeMem; } +static int +vzConnectRegisterCloseCallback(virConnectPtr conn, + virConnectCloseFunc cb, + void *opaque, + virFreeCallback freecb) +{ + vzConnPtr privconn = conn->privateData; + int ret = -1; + + vzDriverLock(privconn); + ret = virConnectCloseCallbackDataRegister(privconn->closeCallback, conn, cb, + opaque, freecb); + vzDriverUnlock(privconn); + + return ret; +} + +static int +vzConnectUnregisterCloseCallback(virConnectPtr conn, virConnectCloseFunc cb) +{ + vzConnPtr privconn = conn->privateData; + int ret = -1; + + vzDriverLock(privconn); + ret = virConnectCloseCallbackDataUnregister(privconn->closeCallback, cb); + vzDriverUnlock(privconn); + + return ret; +} + static virHypervisorDriver vzDriver = { .name = "vz", .connectOpen = vzConnectOpen, /* 0.10.0 */ @@ -1522,6 +1559,8 @@ static virHypervisorDriver vzDriver = { .domainBlockStatsFlags = vzDomainBlockStatsFlags, /* 1.2.17 */ .domainInterfaceStats = vzDomainInterfaceStats, /* 1.2.17 */ .domainMemoryStats = vzDomainMemoryStats, /* 1.2.17 */ + .connectRegisterCloseCallback = vzConnectRegisterCloseCallback, /* 1.3.2 */ + .connectUnregisterCloseCallback = vzConnectUnregisterCloseCallback, /* 1.3.2 */ }; static virConnectDriver vzConnectDriver = { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index d610979..0836e18 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -1751,6 +1751,10 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque) /* above function takes own of event */ prlEvent = PRL_INVALID_HANDLE; break; + case PET_DSP_EVT_DISP_CONNECTION_CLOSED: + virConnectCloseCallbackDataCall(privconn->closeCallback, + VIR_CONNECT_CLOSE_REASON_EOF); + break; default: VIR_DEBUG("Skipping event of type %d", prlEventType); } diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h index b7a4c81..a2468b4 100644 --- a/src/vz/vz_utils.h +++ b/src/vz/vz_utils.h @@ -30,6 +30,7 @@ # include "conf/virdomainobjlist.h" # include "conf/domain_event.h" # include "virthread.h" +# include "datatypes.h" # define vzParseError() \ virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__, \ @@ -59,6 +60,8 @@ struct _vzConn { virDomainXMLOptionPtr xmlopt; virObjectEventStatePtr domainEventState; const char *drivername; + /* Immutable pointer, self-locking APIs */ + virConnectCloseCallbackDataPtr closeCallback; }; typedef struct _vzConn vzConn; -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list