[PATCH 2/5] parallels: implement lookup functions with SDK

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

 



Implement functions parallelsDomainLookupByUUID and
parallelsDomainLookupByName with SDK instead of running prlctl
command.

Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx>
---
 src/parallels/parallels_driver.c | 48 +----------------------
 src/parallels/parallels_sdk.c    | 83 ++++++++++++++++++++++++++++++++++++++++
 src/parallels/parallels_sdk.h    |  4 ++
 3 files changed, 89 insertions(+), 46 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index e4649dc..2617ab9 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1171,57 +1171,13 @@ parallelsDomainLookupByID(virConnectPtr conn, int id)
 static virDomainPtr
 parallelsDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 {
-    parallelsConnPtr privconn = conn->privateData;
-    virDomainPtr ret = NULL;
-    virDomainObjPtr dom;
-
-    parallelsDriverLock(privconn);
-    dom = virDomainObjListFindByUUID(privconn->domains, uuid);
-    parallelsDriverUnlock(privconn);
-
-    if (dom == NULL) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(uuid, uuidstr);
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("no domain with matching uuid '%s'"), uuidstr);
-        goto cleanup;
-    }
-
-    ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
-    if (ret)
-        ret->id = dom->def->id;
-
- cleanup:
-    if (dom)
-        virObjectUnlock(dom);
-    return ret;
+    return prlsdkDomainLookupByUUID(conn, uuid);
 }
 
 static virDomainPtr
 parallelsDomainLookupByName(virConnectPtr conn, const char *name)
 {
-    parallelsConnPtr privconn = conn->privateData;
-    virDomainPtr ret = NULL;
-    virDomainObjPtr dom;
-
-    parallelsDriverLock(privconn);
-    dom = virDomainObjListFindByName(privconn->domains, name);
-    parallelsDriverUnlock(privconn);
-
-    if (dom == NULL) {
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("no domain with matching name '%s'"), name);
-        goto cleanup;
-    }
-
-    ret = virGetDomain(conn, dom->def->name, dom->def->uuid);
-    if (ret)
-        ret->id = dom->def->id;
-
- cleanup:
-    if (dom)
-        virObjectUnlock(dom);
-    return ret;
+    return prlsdkDomainLookupByName(conn, name);
 }
 
 static int
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index 80e3f7b..111c52a 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -482,3 +482,86 @@ prlsdkListAllDomains(virConnectPtr conn,
     PrlHandle_Free(job);
     return -1;
 }
+
+int
+prlsdkSdkDomainLookup(parallelsConnPtr privconn,
+                      const char *id,
+                      unsigned int flags,
+                      PRL_HANDLE *sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+    PRL_HANDLE result = PRL_INVALID_HANDLE;
+    PRL_RESULT pret = PRL_ERR_UNINITIALIZED;
+    int ret = -1;
+
+    job = PrlSrv_GetVmConfig(privconn->server, id, flags);
+    if (!(result = getJobResult(job, privconn->jobTimeout)))
+        goto cleanup;
+
+    pret = PrlResult_GetParamByIndex(result, 0, sdkdom);
+    prlsdkCheckRetGoto(pret, cleanup);
+
+    ret = 0;
+
+ cleanup:
+    PrlHandle_Free(result);
+    return ret;
+}
+
+PRL_HANDLE
+prlsdkSdkDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+{
+    char uuidstr[VIR_UUID_STRING_BUFLEN + 2];
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
+
+    virUUIDFormat(uuid, uuidstr + 1);
+
+    uuidstr[0] = '{';
+    uuidstr[VIR_UUID_STRING_BUFLEN] = '}';
+    uuidstr[VIR_UUID_STRING_BUFLEN + 1] = '\0';
+
+    if (prlsdkSdkDomainLookup(conn->privateData, uuidstr,
+                              PGVC_SEARCH_BY_UUID, &sdkdom) < 0) {
+        virUUIDFormat(uuid, uuidstr);
+        virReportError(VIR_ERR_NO_DOMAIN,
+                       _("no domain with matching uuid '%s'"), uuidstr);
+        return PRL_INVALID_HANDLE;
+    }
+
+    return sdkdom;
+}
+virDomainPtr
+prlsdkDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
+{
+    PRL_HANDLE sdkdom;
+    virDomainPtr dom = NULL;
+
+    sdkdom = prlsdkSdkDomainLookupByUUID(conn, uuid);
+    if (sdkdom == PRL_INVALID_HANDLE)
+        return NULL;
+
+    prlsdkHandleToDomain(conn, sdkdom, &dom);
+    PrlHandle_Free(sdkdom);
+
+    return dom;
+}
+
+virDomainPtr
+prlsdkDomainLookupByName(virConnectPtr conn, const char *name)
+{
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
+    virDomainPtr dom = NULL;
+
+    if (prlsdkSdkDomainLookup(conn->privateData, name,
+                              PGVC_SEARCH_BY_NAME, &sdkdom) < 0) {
+        virReportError(VIR_ERR_NO_DOMAIN,
+                       _("no domain with matching name '%s'"), name);
+        goto cleanup;
+    }
+
+    prlsdkHandleToDomain(conn, sdkdom, &dom);
+
+ cleanup:
+    PrlHandle_Free(sdkdom);
+    return dom;
+}
diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h
index 400c95d..16df5f2 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -31,3 +31,7 @@ void prlsdkDisconnect(parallelsConnPtr privconn);
 int prlsdkListAllDomains(virConnectPtr conn,
                          virDomainPtr **domains,
                          unsigned int flags);
+virDomainPtr
+prlsdkDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
+virDomainPtr
+prlsdkDomainLookupByName(virConnectPtr conn, const char *name);
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]