Add functions for create/shutdown/destroy and suspend/resume domain.
Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
po/POTFILES.in | 1 +
src/pvs/pvs_driver.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/pvs/pvs_driver.h | 1 +
src/pvs/pvs_utils.c | 18 ++++++
4 files changed, 168 insertions(+), 0 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 07ccb7c..7ec8df5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -166,6 +166,7 @@ src/xenapi/xenapi_utils.c
src/xenxs/xen_sxpr.c
src/xenxs/xen_xm.c
src/pvs/pvs_driver.c
+src/pvs/pvs_utils.c
tools/console.c
tools/libvirt-guests.init.sh
tools/virsh.c
diff --git a/src/pvs/pvs_driver.c b/src/pvs/pvs_driver.c
index 736aa55..b0835b0 100644
--- a/src/pvs/pvs_driver.c
+++ b/src/pvs/pvs_driver.c
@@ -59,6 +59,11 @@
void pvsFreeDomObj(void *p);
static virCapsPtr pvsBuildCapabilities(void);
static int pvsClose(virConnectPtr conn);
+int pvsPause(virDomainObjPtr privdom);
+int pvsResume(virDomainObjPtr privdom);
+int pvsStart(virDomainObjPtr privdom);
+int pvsKill(virDomainObjPtr privdom);
+int pvsStop(virDomainObjPtr privdom);
static void
pvsDriverLock(pvsConnPtr driver)
@@ -86,6 +91,12 @@ pvsFreeDomObj(void *p)
VIR_FREE(pdom);
};
+static void
+pvsDomainEventQueue(pvsConnPtr driver, virDomainEventPtr event)
+{
+ virDomainEventStateQueue(driver->domainEventState, event);
+}
+
static virCapsPtr
pvsBuildCapabilities(void)
{
@@ -746,6 +757,138 @@ pvsDomainGetAutostart(virDomainPtr domain, int *autostart)
return ret;
}
+typedef int (*pvsChangeState) (virDomainObjPtr privdom);
+#define PVS_UUID(x) (((pvsDomObjPtr)(x->privateData))->uuid)
+
+static int
+pvsDomainChangeState(virDomainPtr domain,
+ virDomainState req_state, const char * req_state_name,
+ pvsChangeState chstate,
+ virDomainState new_state, int reason,
+ int event_type, int event_detail)
+{
+ pvsConnPtr privconn = domain->conn->privateData;
+ virDomainObjPtr privdom;
+ virDomainEventPtr event = NULL;
+ int state;
+ int ret = -1;
+
+ pvsDriverLock(privconn);
+ privdom = virDomainFindByName(&privconn->domains, domain->name);
+ pvsDriverUnlock(privconn);
+
+ if (privdom == NULL) {
+ pvsError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto cleanup;
+ }
+
+ state = virDomainObjGetState(privdom, NULL);
+ if (state != req_state) {
+ pvsError(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);
+
+ event = virDomainEventNewFromObj(privdom, event_type, event_detail);
+ ret = 0;
+
+ cleanup:
+ if (privdom)
+ virDomainObjUnlock(privdom);
+
+ if (event) {
+ pvsDriverLock(privconn);
+ pvsDomainEventQueue(privconn, event);
+ pvsDriverUnlock(privconn);
+ }
+ return ret;
+}
+
+int pvsPause(virDomainObjPtr privdom)
+{
+ return pvsCmdRun(PRLCTL, "pause", PVS_UUID(privdom), NULL);
+}
+
+static int
+pvsPauseDomain(virDomainPtr domain)
+{
+ return pvsDomainChangeState(domain,
+ VIR_DOMAIN_RUNNING, "running",
+ pvsPause,
+ VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER,
+ VIR_DOMAIN_EVENT_SUSPENDED,
+ VIR_DOMAIN_EVENT_SUSPENDED_PAUSED);
+}
+
+int pvsResume(virDomainObjPtr privdom)
+{
+ return pvsCmdRun(PRLCTL, "resume", PVS_UUID(privdom), NULL);
+}
+
+static int
+pvsResumeDomain(virDomainPtr domain)
+{
+ return pvsDomainChangeState(domain,
+ VIR_DOMAIN_PAUSED, "paused",
+ pvsResume,
+ VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED,
+ VIR_DOMAIN_EVENT_RESUMED,
+ VIR_DOMAIN_EVENT_RESUMED_UNPAUSED);
+}
+
+int pvsStart(virDomainObjPtr privdom)
+{
+ return pvsCmdRun(PRLCTL, "start", PVS_UUID(privdom), NULL);
+}
+
+static int
+pvsDomainCreate(virDomainPtr domain)
+{
+ return pvsDomainChangeState(domain,
+ VIR_DOMAIN_SHUTOFF, "stopped",
+ pvsStart,
+ VIR_DOMAIN_RUNNING, VIR_DOMAIN_EVENT_STARTED_BOOTED,
+ VIR_DOMAIN_EVENT_STARTED,
+ VIR_DOMAIN_EVENT_STARTED_BOOTED);
+}
+
+int pvsKill(virDomainObjPtr privdom)
+{
+ return pvsCmdRun(PRLCTL, "stop", PVS_UUID(privdom), "--kill",
NULL);
+}
+
+static int
+pvsDestroyDomain(virDomainPtr domain)
+{
+ return pvsDomainChangeState(domain,
+ VIR_DOMAIN_RUNNING, "running",
+ pvsKill,
+ VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTROYED,
+ VIR_DOMAIN_EVENT_STOPPED,
+ VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
+}
+
+int pvsStop(virDomainObjPtr privdom)
+{
+ return pvsCmdRun(PRLCTL, "stop", PVS_UUID(privdom), NULL);
+}
+
+static int
+pvsShutdownDomain(virDomainPtr domain)
+{
+ return pvsDomainChangeState(domain,
+ VIR_DOMAIN_RUNNING, "running",
+ pvsStop,
+ VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN,
+ VIR_DOMAIN_EVENT_STOPPED,
+ VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
+}
+
static virDriver pvsDriver = {
.no = VIR_DRV_PVS,
.name = "PVS",
@@ -768,6 +911,11 @@ static virDriver pvsDriver = {
.domainGetXMLDesc = pvsDomainGetXMLDesc, /* 0.9.12 */
.domainIsPersistent = pvsDomainIsPersistent, /* 0.9.12 */
.domainGetAutostart = pvsDomainGetAutostart, /* 0.9.12 */
+ .domainSuspend = pvsPauseDomain, /* 0.9.12 */
+ .domainResume = pvsResumeDomain, /* 0.9.12 */
+ .domainDestroy = pvsDestroyDomain, /* 0.9.12 */
+ .domainShutdown = pvsShutdownDomain, /* 0.9.12 */
+ .domainCreate = pvsDomainCreate, /* 0.9.12 */
};
/**
diff --git a/src/pvs/pvs_driver.h b/src/pvs/pvs_driver.h
index 2420ce6..080f34b 100644
--- a/src/pvs/pvs_driver.h
+++ b/src/pvs/pvs_driver.h
@@ -61,5 +61,6 @@ typedef struct _pvsConn *pvsConnPtr;
int pvsRegister(void);
virJSONValuePtr pvsParseOutput(const char *binary, ...);
+int pvsCmdRun(const char *binary, ...);
#endif
diff --git a/src/pvs/pvs_utils.c b/src/pvs/pvs_utils.c
index 5d7411c..016317a 100644
--- a/src/pvs/pvs_utils.c
+++ b/src/pvs/pvs_utils.c
@@ -99,3 +99,21 @@ pvsParseOutput(const char *binary, ...)
return jobj;
}
+
+/*
+ * Run prlctl command and check for errors
+ *
+ * Return value is 0 in case of success, else - -1
+ */
+int
+pvsCmdRun(const char *binary, ...)
+{
+ int ret;
+ va_list list;
+
+ va_start(list, binary);
+ ret = pvsDoCmdRun(NULL, binary, list);
+ va_end(list);
+
+ return ret;
+}
--
1.7.1