[PATCH 63/66] vbox: Rewrite vboxConnectListAllDomains

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

 



---
 src/vbox/vbox_common.c        |  157 +++++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |  156 ----------------------------------------
 src/vbox/vbox_uniformed_api.h |    2 +
 3 files changed, 159 insertions(+), 156 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d3735ac..14f627f 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7263,3 +7263,160 @@ vboxDomainScreenshot(virDomainPtr dom,
     vboxIIDUnalloc(&iid);
     return ret;
 }
+
+#define MATCH(FLAG) (flags & (FLAG))
+int
+vboxConnectListAllDomains(virConnectPtr conn,
+                          virDomainPtr **domains,
+                          unsigned int flags)
+{
+    VBOX_OBJECT_CHECK(conn, int, -1);
+    vboxArray machines = VBOX_ARRAY_INITIALIZER;
+    char      *machineNameUtf8  = NULL;
+    PRUnichar *machineNameUtf16 = NULL;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    vboxIIDUnion iid;
+    PRUint32 state;
+    nsresult rc;
+    size_t i;
+    virDomainPtr dom;
+    virDomainPtr *doms = NULL;
+    int count = 0;
+    bool active;
+    PRUint32 snapshotCount;
+
+    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
+
+    /* filter out flag options that will produce 0 results in vbox driver:
+     * - managed save: vbox guests don't have managed save images
+     * - autostart: vbox doesn't support autostarting guests
+     * - persistance: vbox doesn't support transient guests
+     */
+    if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) &&
+         !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) ||
+        (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) &&
+         !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) ||
+        (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
+         !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) {
+        if (domains &&
+            VIR_ALLOC_N(*domains, 1) < 0)
+            goto cleanup;
+
+        ret = 0;
+        goto cleanup;
+    }
+
+    rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not get list of domains, rc=%08x"), (unsigned)rc);
+        goto cleanup;
+    }
+
+    if (domains &&
+        VIR_ALLOC_N(doms, machines.count + 1) < 0)
+        goto cleanup;
+
+    for (i = 0; i < machines.count; i++) {
+        IMachine *machine = machines.items[i];
+
+        if (!machine)
+            continue;
+
+        PRBool isAccessible = PR_FALSE;
+        gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
+
+        if (!isAccessible)
+            continue;
+
+      gVBoxAPI.UIMachine.GetState(machine, &state);
+
+      if (gVBoxAPI.machineStateChecker.Online(state))
+          active = true;
+      else
+          active = false;
+
+      /* filter by active state */
+      if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
+          !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) && active) ||
+            (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) && !active)))
+          continue;
+
+      /* filter by snapshot existence */
+      if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
+          rc = gVBoxAPI.UIMachine.GetSnapshotCount(machine, &snapshotCount);
+          if (NS_FAILED(rc)) {
+              virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                             _("could not get snapshot count for listed domains"));
+              goto cleanup;
+          }
+          if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) &&
+                 snapshotCount > 0) ||
+                (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) &&
+                 snapshotCount == 0)))
+              continue;
+      }
+
+      /* filter by machine state */
+      if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE) &&
+          !((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) &&
+             gVBoxAPI.machineStateChecker.Running(state)) ||
+            (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) &&
+             gVBoxAPI.machineStateChecker.Paused(state)) ||
+            (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) &&
+             gVBoxAPI.machineStateChecker.PoweredOff(state)) ||
+            (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) &&
+             (!gVBoxAPI.machineStateChecker.Running(state) &&
+              !gVBoxAPI.machineStateChecker.Paused(state) &&
+              !gVBoxAPI.machineStateChecker.PoweredOff(state)))))
+          continue;
+
+      /* just count the machines */
+      if (!doms) {
+          count++;
+          continue;
+      }
+
+      gVBoxAPI.UIMachine.GetName(machine, &machineNameUtf16);
+      VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8);
+      gVBoxAPI.UIMachine.GetId(machine, &iid);
+      vboxIIDToUUID(&iid, uuid);
+      vboxIIDUnalloc(&iid);
+
+      dom = virGetDomain(conn, machineNameUtf8, uuid);
+
+      VBOX_UTF8_FREE(machineNameUtf8);
+      VBOX_UTF16_FREE(machineNameUtf16);
+
+      if (!dom)
+          goto cleanup;
+
+      if (active)
+          dom->id = i + 1;
+
+      doms[count++] = dom;
+    }
+
+    if (doms) {
+        /* safe to ignore, new size will be equal or less than
+         * previous allocation*/
+        ignore_value(VIR_REALLOC_N(doms, count + 1));
+        *domains = doms;
+        doms = NULL;
+    }
+
+    ret = count;
+
+ cleanup:
+    if (doms) {
+        for (i = 0; i < count; i++) {
+            if (doms[i])
+                virDomainFree(doms[i]);
+        }
+    }
+    VIR_FREE(doms);
+
+    gVBoxAPI.UArray.vboxArrayRelease(&machines);
+    return ret;
+}
+#undef MATCH
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 82c45ad..55ccbc7 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3732,162 +3732,6 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
     return ret;
 }
 
-#define MATCH(FLAG) (flags & (FLAG))
-static int
-vboxConnectListAllDomains(virConnectPtr conn,
-                          virDomainPtr **domains,
-                          unsigned int flags)
-{
-    VBOX_OBJECT_CHECK(conn, int, -1);
-    vboxArray machines = VBOX_ARRAY_INITIALIZER;
-    char      *machineNameUtf8  = NULL;
-    PRUnichar *machineNameUtf16 = NULL;
-    unsigned char uuid[VIR_UUID_BUFLEN];
-    vboxIID iid = VBOX_IID_INITIALIZER;
-    PRUint32 state;
-    nsresult rc;
-    size_t i;
-    virDomainPtr dom;
-    virDomainPtr *doms = NULL;
-    int count = 0;
-    bool active;
-    PRUint32 snapshotCount;
-
-    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
-
-    /* filter out flag options that will produce 0 results in vbox driver:
-     * - managed save: vbox guests don't have managed save images
-     * - autostart: vbox doesn't support autostarting guests
-     * - persistance: vbox doesn't support transient guests
-     */
-    if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) &&
-         !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) ||
-        (MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) &&
-         !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) ||
-        (MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) &&
-         !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) {
-        if (domains &&
-            VIR_ALLOC_N(*domains, 1) < 0)
-            goto cleanup;
-
-        ret = 0;
-        goto cleanup;
-    }
-
-    rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines);
-    if (NS_FAILED(rc)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Could not get list of domains, rc=%08x"), (unsigned)rc);
-        goto cleanup;
-    }
-
-    if (domains &&
-        VIR_ALLOC_N(doms, machines.count + 1) < 0)
-        goto cleanup;
-
-    for (i = 0; i < machines.count; i++) {
-        IMachine *machine = machines.items[i];
-
-        if (machine) {
-            PRBool isAccessible = PR_FALSE;
-            machine->vtbl->GetAccessible(machine, &isAccessible);
-            if (isAccessible) {
-                machine->vtbl->GetState(machine, &state);
-
-                if (state >= MachineState_FirstOnline &&
-                    state <= MachineState_LastOnline)
-                    active = true;
-                else
-                    active = false;
-
-                /* filter by active state */
-                if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) &&
-                    !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE) && active) ||
-                      (MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE) && !active)))
-                    continue;
-
-                /* filter by snapshot existence */
-                if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
-                    rc = machine->vtbl->GetSnapshotCount(machine, &snapshotCount);
-                    if (NS_FAILED(rc)) {
-                        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                                       _("could not get snapshot count for listed domains"));
-                        goto cleanup;
-                    }
-                    if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) &&
-                           snapshotCount > 0) ||
-                          (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) &&
-                           snapshotCount == 0)))
-                        continue;
-                }
-
-                /* filter by machine state */
-                if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE) &&
-                    !((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) &&
-                       state == MachineState_Running) ||
-                      (MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) &&
-                       state == MachineState_Paused) ||
-                      (MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) &&
-                       state == MachineState_PoweredOff) ||
-                      (MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) &&
-                       (state != MachineState_Running &&
-                        state != MachineState_Paused &&
-                        state != MachineState_PoweredOff))))
-                    continue;
-
-                /* just count the machines */
-                if (!doms) {
-                    count++;
-                    continue;
-                }
-
-                machine->vtbl->GetName(machine, &machineNameUtf16);
-                VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8);
-                machine->vtbl->GetId(machine, &iid.value);
-                vboxIIDToUUID(&iid, uuid);
-                vboxIIDUnalloc(&iid);
-
-                dom = virGetDomain(conn, machineNameUtf8, uuid);
-
-                VBOX_UTF8_FREE(machineNameUtf8);
-                VBOX_UTF16_FREE(machineNameUtf16);
-
-                if (!dom)
-                    goto cleanup;
-
-                if (active)
-                    dom->id = i + 1;
-
-                doms[count++] = dom;
-            }
-        }
-    }
-
-    if (doms) {
-        /* safe to ignore, new size will be equal or less than
-         * previous allocation*/
-        ignore_value(VIR_REALLOC_N(doms, count + 1));
-        *domains = doms;
-        doms = NULL;
-    }
-
-    ret = count;
-
- cleanup:
-    if (doms) {
-        for (i = 0; i < count; i++) {
-            if (doms[i])
-                virDomainFree(doms[i]);
-        }
-    }
-    VIR_FREE(doms);
-
-    vboxArrayRelease(&machines);
-    return ret;
-}
-#undef MATCH
-
-
 static int
 vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
                 virNodeInfoPtr nodeinfo)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 7e8f677..c105a07 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -621,6 +621,8 @@ int vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
                              unsigned int flags);
 char *vboxDomainScreenshot(virDomainPtr dom, virStreamPtr st,
                            unsigned int screen, unsigned int flags);
+int vboxConnectListAllDomains(virConnectPtr conn, virDomainPtr **domains,
+                              unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]