parallels: reimplement functions, which change domain state

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>
This commit is contained in:
Dmitry Guryanov 2014-12-01 18:38:51 +03:00 committed by Peter Krempa
parent 0a7aba408e
commit 560dcdf02f
3 changed files with 105 additions and 114 deletions

View File

@ -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",

View File

@ -1548,3 +1548,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);
return ret;
}

View File

@ -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);