[PATCH 5/5] parallels: change domains state with SDK

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

 



Implement functions, which change domain state with SDK.

We have to keep stored domains list up-to-date, so
update domain info after calling prlsdkDomain*.

When we remove cached domain list, we can remove
functions parallelsDomain*, because they will be
just calling corresponding functions from parallels_sdk.c

Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx>
---
 src/parallels/parallels_driver.c | 114 +++++++--------------------------------
 src/parallels/parallels_sdk.c    |  88 ++++++++++++++++++++++++++++++
 src/parallels/parallels_sdk.h    |   5 ++
 3 files changed, 113 insertions(+), 94 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index ac192a0..bbed9dc 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1333,118 +1333,44 @@ parallelsDomainGetAutostart(virDomainPtr domain, int *autostart)
     return ret;
 }
 
-typedef int (*parallelsChangeStateFunc)(virDomainObjPtr privdom);
-#define PARALLELS_UUID(x)     (((parallelsDomObjPtr)(x->privateData))->uuid)
-
-static int
-parallelsDomainChangeState(virDomainPtr domain,
-                           virDomainState req_state, const char *req_state_name,
-                           parallelsChangeStateFunc chstate,
-                           virDomainState new_state, int reason)
+int parallelsDomainSuspend(virDomainPtr domain)
 {
-    parallelsConnPtr privconn = domain->conn->privateData;
-    virDomainObjPtr privdom;
-    int state;
-    int ret = -1;
-
-    parallelsDriverLock(privconn);
-    privdom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
-    parallelsDriverUnlock(privconn);
-
-    if (privdom == NULL) {
-        parallelsDomNotFoundError(domain);
-        goto cleanup;
-    }
-
-    state = virDomainObjGetState(privdom, NULL);
-    if (state != req_state) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, _("domain '%s' not %s"),
-                       privdom->def->name, req_state_name);
-        goto cleanup;
-    }
-
-    if (chstate(privdom))
-        goto cleanup;
-
-    virDomainObjSetState(privdom, new_state, reason);
-
-    ret = 0;
-
- cleanup:
-    if (privdom)
-        virObjectUnlock(privdom);
+    if (prlsdkDomainSuspend(domain) < 0)
+        return -1;
 
-    return ret;
+    return parallelsLoadDomains(domain->conn->privateData, domain->name);
 }
 
-static int parallelsPause(virDomainObjPtr privdom)
+int parallelsDomainResume(virDomainPtr domain)
 {
-    return parallelsCmdRun(PRLCTL, "pause", PARALLELS_UUID(privdom), NULL);
-}
-
-static int
-parallelsDomainSuspend(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsPause,
-                                      VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
-}
-
-static int parallelsResume(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "resume", PARALLELS_UUID(privdom), NULL);
-}
+    if (prlsdkDomainResume(domain) < 0)
+        return -1;
 
-static int
-parallelsDomainResume(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_PAUSED, "paused",
-                                      parallelsResume,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
+    return parallelsLoadDomains(domain->conn->privateData, domain->name);
 }
 
-static int parallelsStart(virDomainObjPtr privdom)
+int parallelsDomainCreate(virDomainPtr domain)
 {
-    return parallelsCmdRun(PRLCTL, "start", PARALLELS_UUID(privdom), NULL);
-}
+    if (prlsdkDomainCreate(domain) < 0)
+        return -1;
 
-static int
-parallelsDomainCreate(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_SHUTOFF, "stopped",
-                                      parallelsStart,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_EVENT_STARTED_BOOTED);
+    return parallelsLoadDomains(domain->conn->privateData, domain->name);
 }
 
-static int parallelsKill(virDomainObjPtr privdom)
+int parallelsDomainDestroy(virDomainPtr domain)
 {
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), "--kill", NULL);
-}
+    if (prlsdkDomainDestroy(domain) < 0)
+        return -1;
 
-static int
-parallelsDomainDestroy(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsKill,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTROYED);
+    return parallelsLoadDomains(domain->conn->privateData, domain->name);
 }
 
-static int parallelsStop(virDomainObjPtr privdom)
+int parallelsDomainShutdown(virDomainPtr domain)
 {
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), NULL);
-}
+    if (prlsdkDomainShutdown(domain) < 0)
+        return -1;
 
-static int
-parallelsDomainShutdown(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsStop,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+    return parallelsLoadDomains(domain->conn->privateData, domain->name);
 }
 
 static int
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index ba9d226..8d22da3 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -1340,3 +1340,91 @@ prlsdkDomainObjLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 
     return dom;
 }
+
+static int prlsdkStart(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_StartEx(sdkdom, PSM_VM_START, 0);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+static int prlsdkStopEx(parallelsConnPtr privconn,
+                        PRL_HANDLE sdkdom,
+                        PRL_UINT32 mode)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_StopEx(sdkdom, mode, 0);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+static int prlsdkKill(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    return prlsdkStopEx(privconn, sdkdom, PSM_KILL);
+}
+
+static int prlsdkStop(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    return prlsdkStopEx(privconn, sdkdom, PSM_SHUTDOWN);
+}
+
+static int prlsdkPause(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_Pause(sdkdom, false);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+static int prlsdkResume(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_Resume(sdkdom);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+typedef int (*prlsdkChangeStateFunc)(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+
+static int
+prlsdkDomainChangeState(virDomainPtr domain,
+                        prlsdkChangeStateFunc chstate)
+{
+    parallelsConnPtr privconn = domain->conn->privateData;
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
+    int ret = -1;
+
+    sdkdom = prlsdkSdkDomainLookupByUUID(domain->conn, domain->uuid);
+    if (sdkdom == PRL_INVALID_HANDLE)
+        return -1;
+
+    ret = chstate(privconn, sdkdom);
+    PrlHandle_Free(sdkdom);
+    return ret;
+}
+
+int prlsdkDomainSuspend(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkPause);
+}
+
+int prlsdkDomainResume(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkResume);
+}
+
+int prlsdkDomainCreate(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkStart);
+}
+
+int prlsdkDomainDestroy(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkKill);
+}
+
+int prlsdkDomainShutdown(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkStop);
+}
diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h
index 30c6c21..b02565b 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -37,3 +37,8 @@ virDomainPtr
 prlsdkDomainLookupByName(virConnectPtr conn, const char *name);
 virDomainObjPtr
 prlsdkDomainObjLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
+int prlsdkDomainSuspend(virDomainPtr domain);
+int prlsdkDomainResume(virDomainPtr domain);
+int prlsdkDomainCreate(virDomainPtr domain);
+int prlsdkDomainDestroy(virDomainPtr domain);
+int prlsdkDomainShutdown(virDomainPtr domain);
-- 
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]