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

[libvirt] [PATCH 4/6] parallels: don't track domain state in global domains list



Signed-off-by: Dmitry Guryanov <dguryanov parallels com>
---
 src/parallels/parallels_driver.c |  101 ++++++--------------------------------
 1 files changed, 16 insertions(+), 85 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index de3d53f..1f6dcef 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1098,118 +1098,49 @@ 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 = virDomainFindByUUID(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)
-        virDomainObjUnlock(privdom);
-
-    return ret;
-}
-
-static int parallelsPause(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "pause", PARALLELS_UUID(privdom), NULL);
-}
-
 static int
 parallelsPauseDomain(virDomainPtr domain)
 {
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsPause,
-                                      VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_USER);
-}
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-static int parallelsResume(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "resume", PARALLELS_UUID(privdom), NULL);
+    virUUIDFormat(domain->uuid, uuidstr);
+    return parallelsCmdRun(PRLCTL, "pause", uuidstr, NULL) ? -1 : 0;
 }
 
 static int
 parallelsResumeDomain(virDomainPtr domain)
 {
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_PAUSED, "paused",
-                                      parallelsResume,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_UNPAUSED);
-}
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-static int parallelsStart(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "start", PARALLELS_UUID(privdom), NULL);
+    virUUIDFormat(domain->uuid, uuidstr);
+    return parallelsCmdRun(PRLCTL, "resume", uuidstr, NULL) ? -1 : 0;
 }
 
 static int
 parallelsDomainCreate(virDomainPtr domain)
 {
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_SHUTOFF, "stopped",
-                                      parallelsStart,
-                                      VIR_DOMAIN_RUNNING, VIR_DOMAIN_EVENT_STARTED_BOOTED);
-}
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-static int parallelsKill(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), "--kill", NULL);
+    virUUIDFormat(domain->uuid, uuidstr);
+    return parallelsCmdRun(PRLCTL, "start", uuidstr, NULL) ? -1 : 0;
 }
 
 static int
 parallelsDestroyDomain(virDomainPtr domain)
 {
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsKill,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_DESTROYED);
-}
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-static int parallelsStop(virDomainObjPtr privdom)
-{
-    return parallelsCmdRun(PRLCTL, "stop", PARALLELS_UUID(privdom), NULL);
+    virUUIDFormat(domain->uuid, uuidstr);
+    return parallelsCmdRun(PRLCTL, "stop", uuidstr, "--kill", NULL) ? -1 : 0;
 }
 
 static int
 parallelsShutdownDomain(virDomainPtr domain)
 {
-    return parallelsDomainChangeState(domain,
-                                      VIR_DOMAIN_RUNNING, "running",
-                                      parallelsStop,
-                                      VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+    virUUIDFormat(domain->uuid, uuidstr);
+    return parallelsCmdRun(PRLCTL, "stop", uuidstr, NULL) ? -1 : 0;
 }
 
 static int
-- 
1.7.1


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