]> xenbits.xensource.com Git - libvirt.git/commitdiff
vz: implement connection close notification
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Wed, 17 Feb 2016 12:15:03 +0000 (15:15 +0300)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 1 Mar 2016 14:18:16 +0000 (14:18 +0000)
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
src/vz/vz_driver.c
src/vz/vz_sdk.c
src/vz/vz_utils.h

index f7a861765f7c1b04c888b52f60f94e232e79e6b8..eb9b17230aa77063a6c49ec05a241c96d6457b8f 100644 (file)
@@ -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;
@@ -1470,6 +1477,56 @@ 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);
+
+    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 = {
     .name = "vz",
     .connectOpen = vzConnectOpen,            /* 0.10.0 */
@@ -1532,6 +1589,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 = {
index 92bb7c52d86cbdfc581a9cc29fce3a28e820fa87..de73c31edfc64c8871d6729b6e1b6caa1a7bb7e1 100644 (file)
@@ -1710,6 +1710,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);
     }
index 09761935481c7a3be365204149e565f5dc5e75e5..ed100ac46bfe057584984ff0f6ee7ba9340b7333 100644 (file)
@@ -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;