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

Re: [libvirt] [PATCH v3 05/12] parallels: reimplement functions, which change domain state



18.11.2014 16:17, Dmitry Guryanov пишет:
Change domain state using parallels SDK functions instead of
prlctl command.

We don't need to send events from these functions now, becase
events handler will send them. But we still need to update
virDomainObj in privconn->domains.

Signed-off-by: Dmitry Guryanov <dguryanov parallels com>
---
  src/parallels/parallels_driver.c | 139 +++++++--------------------------------
  src/parallels/parallels_sdk.c    |  70 ++++++++++++++++++++
  src/parallels/parallels_sdk.h    |  10 +++
  3 files changed, 105 insertions(+), 114 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index e145766..658969f 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -670,120 +670,6 @@ 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)
-{
-    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);
-
-    return ret;
-}
-
-static int parallelsPause(virDomainObjPtr privdom)
-{
-    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);
-}
-
-static int
-parallelsDomainResume(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_PAUSED, "paused",
-                                      parallelsResume,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
-}
-
-static int parallelsStart(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "start", PARALLELS_UUID(privdom), NULL);
-}
-
-static int
-parallelsDomainCreate(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_SHUTOFF, "stopped",
-                                      parallelsStart,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_EVENT_STARTED_BOOTED);
-}
-
-static int parallelsKill(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), "--kill", NULL);
-}
-
-static int
-parallelsDomainDestroy(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsKill,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTROYED);
-}
-
-static int parallelsStop(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), NULL);
-}
-
-static int
-parallelsDomainShutdown(virDomainPtr domain)
-{
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsStop,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
-}
-
  static int
  parallelsApplyGraphicsParams(virDomainGraphicsDefPtr *oldgraphics, int nold,
                               virDomainGraphicsDefPtr *newgraphics, int nnew)
@@ -1762,6 +1648,31 @@ parallelsConnectDomainEventDeregisterAny(virConnectPtr conn,
      return ret;
  }
+static int parallelsDomainSuspend(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkPause);
+}
+
+static int parallelsDomainResume(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkResume);
+}
+
+static int parallelsDomainCreate(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkStart);
+}
+
+static int parallelsDomainDestroy(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkKill);
+}
+
+static int parallelsDomainShutdown(virDomainPtr domain)
+{
+    return prlsdkDomainChangeState(domain, prlsdkStop);
+}
+
  static virHypervisorDriver parallelsDriver = {
      .no = VIR_DRV_PARALLELS,
      .name = "Parallels",
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index 01efc22..d42456f 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -1538,3 +1538,73 @@ void prlsdkUnsubscribeFromPCSEvents(parallelsConnPtr privconn)
      if (PRL_FAILED(ret))
          logPrlError(ret);
  }
+
+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);
+}
+
+int prlsdkKill(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    return prlsdkStopEx(privconn, sdkdom, PSM_KILL);
+}
+
+int prlsdkStop(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    return prlsdkStopEx(privconn, sdkdom, PSM_SHUTDOWN);
+}
+
+int prlsdkPause(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_Pause(sdkdom, false);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+int prlsdkResume(parallelsConnPtr privconn, PRL_HANDLE sdkdom)
+{
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_Resume(sdkdom);
+    return waitJob(job, privconn->jobTimeout);
+}
+
+int
+prlsdkDomainChangeState(virDomainPtr domain,
+                        prlsdkChangeStateFunc chstate)
+{
+    parallelsConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr dom;
+    parallelsDomObjPtr pdom;
+    int ret = -1;
+
+    dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
+    if (dom == NULL) {
+        parallelsDomNotFoundError(domain);
+        return -1;
+    }
+
+    pdom = dom->privateData;
+    if ((ret = chstate(privconn, pdom->sdkdom)))
+        goto cleanup;
+
+    ret = prlsdkUpdateDomain(privconn, dom);
+
+ cleanup:
+    virObjectUnlock(dom);
error code translation is from PRL to VIR is necessary here
something like this:

    switch(ret){
    case PRL_ERR_DISP_VM_IS_NOT_STARTED:
        ret = VIR_ERR_OPERATION_INVALID;
        break;
    default:
        ret = VIR_ERR_OPERATION_FAILED;
    }

+    return ret;
+}
diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h
index 5ffbf53..1e26672 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -34,3 +34,13 @@ virDomainObjPtr
  prlsdkAddDomain(parallelsConnPtr privconn, const unsigned char *uuid);
  int prlsdkSubscribeToPCSEvents(parallelsConnPtr privconn);
  void prlsdkUnsubscribeFromPCSEvents(parallelsConnPtr privconn);
+int prlsdkStart(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+int prlsdkKill(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+int prlsdkStop(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+int prlsdkPause(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+int prlsdkResume(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+
+typedef int (*prlsdkChangeStateFunc)(parallelsConnPtr privconn, PRL_HANDLE sdkdom);
+int
+prlsdkDomainChangeState(virDomainPtr domain,
+                        prlsdkChangeStateFunc chstate);


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