Change domain state using parallels SDK functions instead of
prlctl command.
We don't need to send events and update domains in
privconn->domains list in these functions anymore, because
it's done in prlsdkEventsHandler. Each time we do something
with domain, parallels server sends an event,
prlsdkEventsHandler is called and we update cached state
accordingly
Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
src/parallels/parallels_driver.c | 124 ++-------------------------------------
src/parallels/parallels_sdk.c | 92 +++++++++++++++++++++++++++++
src/parallels/parallels_sdk.h | 5 ++
3 files changed, 102 insertions(+), 119 deletions(-)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 2d73bd6..a01249d 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)
@@ -1787,11 +1673,11 @@ static virDriver parallelsDriver = {
.domainIsPersistent = parallelsDomainIsPersistent, /* 0.10.0 */
.domainGetAutostart = parallelsDomainGetAutostart, /* 0.10.0 */
.domainGetVcpus = parallelsDomainGetVcpus, /* 1.2.6 */
- .domainSuspend = parallelsDomainSuspend, /* 0.10.0 */
- .domainResume = parallelsDomainResume, /* 0.10.0 */
- .domainDestroy = parallelsDomainDestroy, /* 0.10.0 */
- .domainShutdown = parallelsDomainShutdown, /* 0.10.0 */
- .domainCreate = parallelsDomainCreate, /* 0.10.0 */
+ .domainSuspend = prlsdkDomainSuspend, /* 0.10.0 */
+ .domainResume = prlsdkDomainResume, /* 0.10.0 */
+ .domainDestroy = prlsdkDomainDestroy, /* 0.10.0 */
+ .domainShutdown = prlsdkDomainShutdown, /* 0.10.0 */
+ .domainCreate = prlsdkDomainCreate, /* 0.10.0 */
.domainDefineXML = parallelsDomainDefineXML, /* 0.10.0 */
.connectDomainEventRegisterAny = parallelsConnectDomainEventRegisterAny, /* 1.2.10
*/
.connectDomainEventDeregisterAny = parallelsConnectDomainEventDeregisterAny, /*
1.2.10 */
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index dfc2220..78caa6c 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -1530,3 +1530,95 @@ void prlsdkUnsubscribeFromPCSEvents(parallelsConnPtr privconn)
logPrlError(ret);
}
}
+
+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;
+ virDomainObjPtr dom;
+ parallelsDomObjPtr pdom;
+ int ret = -1;
+
+ dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
+ if (dom == NULL) {
+ parallelsDomNotFoundError(domain);
+ return -1;
+ }
+
+ pdom = dom->privateData;
+ ret = chstate(privconn, pdom->sdkdom);
+ virObjectUnlock(dom);
+ 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 5ffbf53..61c2a81 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -34,3 +34,8 @@ virDomainObjPtr
prlsdkAddDomain(parallelsConnPtr privconn, const unsigned char *uuid);
int prlsdkSubscribeToPCSEvents(parallelsConnPtr privconn);
void prlsdkUnsubscribeFromPCSEvents(parallelsConnPtr privconn);
+int prlsdkDomainSuspend(virDomainPtr domain);
+int prlsdkDomainResume(virDomainPtr domain);
+int prlsdkDomainCreate(virDomainPtr domain);
+int prlsdkDomainDestroy(virDomainPtr domain);
+int prlsdkDomainShutdown(virDomainPtr domain);
--
1.9.3