]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vbox: Rewrite vboxDomainDestroyFlags
authorTaowei <uaedante@gmail.com>
Mon, 11 Aug 2014 10:06:32 +0000 (18:06 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 15 Aug 2014 07:25:11 +0000 (09:25 +0200)
src/vbox/vbox_common.c
src/vbox/vbox_tmpl.c
src/vbox/vbox_uniformed_api.h

index 8228410614d120445a04f42365c2f96def1ca2b0..baaadc4d20e42437347d1dd73462c5c43d4f093b 100644 (file)
@@ -2553,3 +2553,48 @@ int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
     vboxIIDUnalloc(&iid);
     return ret;
 }
+
+int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
+{
+    VBOX_OBJECT_CHECK(dom->conn, int, -1);
+    IMachine *machine    = NULL;
+    vboxIIDUnion iid;
+    IConsole *console    = NULL;
+    PRUint32 state;
+    PRBool isAccessible  = PR_FALSE;
+
+    virCheckFlags(0, -1);
+
+    if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0)
+        goto cleanup;
+
+    if (!machine)
+        goto cleanup;
+
+    gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
+    if (!isAccessible)
+        goto cleanup;
+
+    gVBoxAPI.UIMachine.GetState(machine, &state);
+
+    if (gVBoxAPI.machineStateChecker.PoweredOff(state)) {
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("machine already powered down"));
+        goto cleanup;
+    }
+
+    gVBoxAPI.UISession.OpenExisting(data, &iid, machine);
+    gVBoxAPI.UISession.GetConsole(data->vboxSession, &console);
+    if (console) {
+        gVBoxAPI.UIConsole.PowerDown(console);
+        VBOX_RELEASE(console);
+        dom->id = -1;
+        ret = 0;
+    }
+    gVBoxAPI.UISession.Close(data->vboxSession);
+
+ cleanup:
+    VBOX_RELEASE(machine);
+    vboxIIDUnalloc(&iid);
+    return ret;
+}
index bb46b79724169fbd132a99c5b09536f07276aafe..a2b45a79715dbc669fba43715b021b662e14cfd7 100644 (file)
@@ -933,68 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar *utf16,
     return result;
 }
 
-static int
-vboxDomainDestroyFlags(virDomainPtr dom,
-                       unsigned int flags)
-{
-    VBOX_OBJECT_CHECK(dom->conn, int, -1);
-    IMachine *machine    = NULL;
-    vboxIID iid = VBOX_IID_INITIALIZER;
-    IConsole *console    = NULL;
-    PRUint32 state       = MachineState_Null;
-    PRBool isAccessible  = PR_FALSE;
-    nsresult rc;
-
-    virCheckFlags(0, -1);
-
-    vboxIIDFromUUID(&iid, dom->uuid);
-    rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("no domain with matching id %d"), dom->id);
-        goto cleanup;
-    }
-
-    if (!machine)
-        goto cleanup;
-
-    machine->vtbl->GetAccessible(machine, &isAccessible);
-    if (isAccessible) {
-        machine->vtbl->GetState(machine, &state);
-
-        if (state == MachineState_PoweredOff) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("machine already powered down"));
-            goto cleanup;
-        }
-
-        VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-        data->vboxSession->vtbl->GetConsole(data->vboxSession, &console);
-        if (console) {
-
-#if VBOX_API_VERSION == 2002000
-            console->vtbl->PowerDown(console);
-#else
-            IProgress *progress = NULL;
-            console->vtbl->PowerDown(console, &progress);
-            if (progress) {
-                progress->vtbl->WaitForCompletion(progress, -1);
-                VBOX_RELEASE(progress);
-            }
-#endif
-            VBOX_RELEASE(console);
-            dom->id = -1;
-            ret = 0;
-        }
-        VBOX_SESSION_CLOSE();
-    }
-
- cleanup:
-    VBOX_RELEASE(machine);
-    vboxIIDUnalloc(&iid);
-    return ret;
-}
-
 static int
 vboxDomainDestroy(virDomainPtr dom)
 {
@@ -9849,6 +9787,23 @@ _consolePowerButton(IConsole *console)
     return console->vtbl->PowerButton(console);
 }
 
+static nsresult
+_consolePowerDown(IConsole *console)
+{
+    nsresult rc;
+#if VBOX_API_VERSION == 2002000
+    rc = console->vtbl->PowerDown(console);
+#else
+    IProgress *progress = NULL;
+    rc = console->vtbl->PowerDown(console, &progress);
+    if (progress) {
+        rc = progress->vtbl->WaitForCompletion(progress, -1);
+        VBOX_RELEASE(progress);
+    }
+#endif
+    return rc;
+}
+
 static nsresult
 _consoleReset(IConsole *console)
 {
@@ -10381,6 +10336,7 @@ static vboxUniformedIConsole _UIConsole = {
     .Pause = _consolePause,
     .Resume = _consoleResume,
     .PowerButton = _consolePowerButton,
+    .PowerDown = _consolePowerDown,
     .Reset = _consoleReset,
 };
 
index d5c6fb4fba7a99dae1f46540f9ac9ef46adbfcf8..b9c206823ab551cdc2c933b7efcd9dfedc38cb7b 100644 (file)
@@ -240,6 +240,7 @@ typedef struct {
     nsresult (*Pause)(IConsole *console);
     nsresult (*Resume)(IConsole *console);
     nsresult (*PowerButton)(IConsole *console);
+    nsresult (*PowerDown)(IConsole *console);
     nsresult (*Reset)(IConsole *console);
 } vboxUniformedIConsole;
 
@@ -426,6 +427,7 @@ int vboxDomainResume(virDomainPtr dom);
 int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainShutdown(virDomainPtr dom);
 int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
+int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);