[libvirt] [PATCH 34/66] vbox: Rewrite vboxDomainGetState

Taowei uaedante at gmail.com
Mon Aug 11 10:06:37 UTC 2014


---
 src/vbox/vbox_common.c        |   27 +++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   36 ------------------------------------
 src/vbox/vbox_uniformed_api.h |    2 ++
 3 files changed, 29 insertions(+), 36 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d661110..1a4a4f5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2748,3 +2748,30 @@ int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
  cleanup:
     return ret;
 }
+
+int vboxDomainGetState(virDomainPtr dom, int *state,
+                       int *reason, unsigned int flags)
+{
+    VBOX_OBJECT_CHECK(dom->conn, int, -1);
+    vboxIIDUnion domiid;
+    IMachine *machine = NULL;
+    PRUint32 mstate;
+
+    virCheckFlags(0, -1);
+
+    if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0)
+        goto cleanup;
+
+    gVBoxAPI.UIMachine.GetState(machine, &mstate);
+
+    *state = gVBoxAPI.vboxConvertState(mstate);
+
+    if (reason)
+        *reason = 0;
+
+    ret = 0;
+
+ cleanup:
+    vboxIIDUnalloc(&domiid);
+    return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3ae1864..33aa66a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -955,42 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 
 static int
-vboxDomainGetState(virDomainPtr dom,
-                   int *state,
-                   int *reason,
-                   unsigned int flags)
-{
-    VBOX_OBJECT_CHECK(dom->conn, int, -1);
-    vboxIID domiid = VBOX_IID_INITIALIZER;
-    IMachine *machine = NULL;
-    PRUint32 mstate = MachineState_Null;
-    nsresult rc;
-
-    virCheckFlags(0, -1);
-
-    vboxIIDFromUUID(&domiid, dom->uuid);
-    rc = VBOX_OBJECT_GET_MACHINE(domiid.value, &machine);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_NO_DOMAIN, "%s",
-                       _("no domain with matching UUID"));
-        goto cleanup;
-    }
-
-    machine->vtbl->GetState(machine, &mstate);
-
-    *state = _vboxConvertState(mstate);
-
-    if (reason)
-        *reason = 0;
-
-    ret = 0;
-
- cleanup:
-    vboxIIDUnalloc(&domiid);
-    return ret;
-}
-
-static int
 vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                         unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 897e10c..0f6c8ea 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -436,6 +436,8 @@ int vboxDomainDestroy(virDomainPtr dom);
 char *vboxDomainGetOSType(virDomainPtr dom);
 int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
 int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
+int vboxDomainGetState(virDomainPtr dom, int *state,
+                       int *reason, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5




More information about the libvir-list mailing list