[PATCHv1 6/9] vbox: Add support for virDomainList

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

 



The virtual box doesn't use the common virDomainObj implementation so
this patch adds a separate implementation using the virtual box API.

This driver implementation supports only the following filter flags:
 VIR_CONNECT_LIST_DOMAINS_ACTIVE
 VIR_CONNECT_LIST_DOMAINS_INACTIVE
 VIR_CONNECT_LIST_DOMAINS_TRANSIENT
 VIR_CONNECT_LIST_DOMAINS_PERSISTENT
The latter two of these are irelevant as virtual box only supports
persistent domains, so specifying only VIR_CONNECT_LIST_DOMAINS_TRANSIENT
results into a empty list.
---
New in series. Tested to work.
---
 src/vbox/vbox_tmpl.c |  133 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4b0ee2e..36b52a8 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -9097,6 +9097,138 @@ endjob:
 }
 #endif /* VBOX_API_VERSION >= 4000 */

+static int
+vboxListAllDomains(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;
+    int i;
+    virDomainPtr dom;
+    virDomainPtr *doms = NULL;
+    size_t ndoms = 0;
+    int count = 0;
+    bool active;
+
+    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+                  VIR_CONNECT_LIST_DOMAINS_TRANSIENT, -1);
+
+
+    rc = vboxArrayGet(&machines, data->vboxObj, data->vboxObj->vtbl->GetMachines);
+    if (NS_FAILED(rc)) {
+        vboxError(VIR_ERR_INTERNAL_ERROR,
+                  _("Could not get list of domains, rc=%08x"), (unsigned)rc);
+        goto cleanup;
+    }
+
+    if (domains) {
+        if (VIR_ALLOC_N(doms, 1) < 0)
+            goto no_memory;
+        ndoms = 1;
+    }
+
+    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 (!(flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE &&
+                      flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
+                    if (flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE &&
+                        !active)
+                        continue;
+                    if (flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE &&
+                        active)
+                        continue;
+                }
+
+                /* filter by persistent state - all vbox domains are persistent */
+                if (flags & VIR_CONNECT_LIST_DOMAINS_TRANSIENT &&
+                    !(flags & VIR_CONNECT_LIST_DOMAINS_PERSISTENT))
+                    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);
+
+                if (machineNameUtf8) {
+                    VBOX_UTF8_FREE(machineNameUtf8);
+                    machineNameUtf8 = NULL;
+                }
+
+                if (machineNameUtf16) {
+                    VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+                    machineNameUtf16 = NULL;
+                }
+
+                if (!dom)
+                    goto no_memory;
+
+                if (active)
+                    dom->id = i + 1;
+
+                if (VIR_EXPAND_N(doms, ndoms, 1) < 0)
+                    goto no_memory;
+
+                doms[count++] = dom;
+            }
+        }
+    }
+
+    if (doms)
+        *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;
+
+no_memory:
+    virReportOOMError();
+    goto cleanup;
+}
+
+
+
 /**
  * Function Tables
  */
@@ -9175,6 +9307,7 @@ virDriver NAME(Driver) = {
     .domainRevertToSnapshot = vboxDomainRevertToSnapshot, /* 0.8.0 */
     .domainSnapshotDelete = vboxDomainSnapshotDelete, /* 0.8.0 */
     .isAlive = vboxIsAlive, /* 0.9.8 */
+    .listAllDomains = vboxListAllDomains, /* 0.9.13 */
 };

 virNetworkDriver NAME(NetworkDriver) = {
-- 
1.7.3.4

--
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]