[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH RESEND] vz: make more accurate closing connection to sdk



Current code for example can call unsubscribe if connection
succeeds but subscribing fails. This will probabaly lead
only to spurious error messages without any actual inconsistencies
but nevertheless.
---
 src/vz/vz_driver.c |  9 ++------
 src/vz/vz_sdk.c    | 65 +++++++++++++++++++++++++++---------------------------
 src/vz/vz_sdk.h    |  2 --
 3 files changed, 34 insertions(+), 42 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 6aade90..4408591 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -163,11 +163,7 @@ static void vzDriverDispose(void * obj)
 {
     vzDriverPtr driver = obj;
 
-    if (driver->server) {
-        prlsdkUnsubscribeFromPCSEvents(driver);
-        prlsdkDisconnect(driver);
-    }
-
+    prlsdkDisconnect(driver);
     virObjectUnref(driver->domains);
     virObjectUnref(driver->caps);
     virObjectUnref(driver->xmlopt);
@@ -348,8 +344,7 @@ vzDriverObjNew(void)
         !(driver->domains = virDomainObjListNew()) ||
         !(driver->domainEventState = virObjectEventStateNew()) ||
         (vzInitVersion(driver) < 0) ||
-        (prlsdkConnect(driver) < 0) ||
-        (prlsdkSubscribeToPCSEvents(driver) < 0)) {
+        (prlsdkConnect(driver) < 0)) {
         virObjectUnref(driver);
         return NULL;
     }
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 3f46de7..4c6c3a2 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -43,6 +43,8 @@ static int
 prlsdkUUIDParse(const char *uuidstr, unsigned char *uuid);
 static void
 prlsdkConvertError(PRL_RESULT pret);
+static PRL_RESULT
+prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque);
 
 VIR_LOG_INIT("parallels.sdk");
 
@@ -363,41 +365,62 @@ prlsdkConnect(vzDriverPtr driver)
     job = PrlSrv_LoginLocalEx(driver->server, NULL, 0,
                               PSL_HIGH_SECURITY, PACF_NON_INTERACTIVE_MODE);
     if (PRL_FAILED(getJobResult(job, &result)))
-        goto cleanup;
+        goto destroy;
 
     pret = PrlResult_GetParam(result, &response);
-    prlsdkCheckRetGoto(pret, cleanup);
+    prlsdkCheckRetGoto(pret, logoff);
 
     pret = prlsdkGetStringParamBuf(PrlLoginResponse_GetSessionUuid,
                                    response, session_uuid, sizeof(session_uuid));
-    prlsdkCheckRetGoto(pret, cleanup);
+    prlsdkCheckRetGoto(pret, logoff);
 
     if (prlsdkUUIDParse(session_uuid, driver->session_uuid) < 0)
-        goto cleanup;
+        goto logoff;
+
+    pret = PrlSrv_RegEventHandler(driver->server,
+                                  prlsdkEventsHandler,
+                                  driver);
+    prlsdkCheckRetGoto(pret, logoff);
 
     ret = 0;
 
  cleanup:
-    if (ret < 0) {
-        PrlHandle_Free(driver->server);
-        driver->server = PRL_INVALID_HANDLE;
-    }
-
     PrlHandle_Free(result);
     PrlHandle_Free(response);
 
     return ret;
+
+ logoff:
+    job = PrlSrv_Logoff(driver->server);
+    waitJob(job);
+
+ destroy:
+    PrlHandle_Free(driver->server);
+    driver->server = PRL_INVALID_HANDLE;
+
+    goto cleanup;
 }
 
 void
 prlsdkDisconnect(vzDriverPtr driver)
 {
     PRL_HANDLE job;
+    PRL_RESULT ret;
+
+    if (driver->server == PRL_INVALID_HANDLE)
+        return;
+
+    ret = PrlSrv_UnregEventHandler(driver->server,
+                                   prlsdkEventsHandler,
+                                   driver);
+    if (PRL_FAILED(ret))
+        logPrlError(ret);
 
     job = PrlSrv_Logoff(driver->server);
     waitJob(job);
 
     PrlHandle_Free(driver->server);
+    driver->server = PRL_INVALID_HANDLE;
 }
 
 static int
@@ -2334,30 +2357,6 @@ prlsdkEventsHandler(PRL_HANDLE prlEvent, PRL_VOID_PTR opaque)
     return PRL_ERR_SUCCESS;
 }
 
-int prlsdkSubscribeToPCSEvents(vzDriverPtr driver)
-{
-    PRL_RESULT pret = PRL_ERR_UNINITIALIZED;
-
-    pret = PrlSrv_RegEventHandler(driver->server,
-                                  prlsdkEventsHandler,
-                                  driver);
-    prlsdkCheckRetGoto(pret, error);
-    return 0;
-
- error:
-    return -1;
-}
-
-void prlsdkUnsubscribeFromPCSEvents(vzDriverPtr driver)
-{
-    PRL_RESULT ret = PRL_ERR_UNINITIALIZED;
-    ret = PrlSrv_UnregEventHandler(driver->server,
-                                   prlsdkEventsHandler,
-                                   driver);
-    if (PRL_FAILED(ret))
-        logPrlError(ret);
-}
-
 int prlsdkStart(virDomainObjPtr dom)
 {
     PRL_HANDLE job = PRL_INVALID_HANDLE;
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index 7e34cbf..f8da2ad 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -35,8 +35,6 @@ prlsdkAddDomainByUUID(vzDriverPtr driver, const unsigned char *uuid);
 virDomainObjPtr
 prlsdkAddDomainByName(vzDriverPtr driver, const char *name);
 int prlsdkUpdateDomain(vzDriverPtr driver, virDomainObjPtr dom);
-int prlsdkSubscribeToPCSEvents(vzDriverPtr driver);
-void prlsdkUnsubscribeFromPCSEvents(vzDriverPtr driver);
 
 int prlsdkStart(virDomainObjPtr dom);
 int prlsdkKill(virDomainObjPtr dom);
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]