[PATCH 4/5] qemu: implement virConnectListAllDomains() for qemu driver

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

 



This patch adds a basic implementation of the listing code for
virConnectListAllDomains() to qemu driver. The listing code does
not support any filtering flags yet, but they may be easily added
later.
---
 src/qemu/qemu_driver.c |   97 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index efbc421..e7b029f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12948,6 +12948,102 @@ cleanup:
     return ret;
 }

+struct virDomainListData {
+    virConnectPtr conn;
+    virDomainPtr *domains;
+    int ndomains;
+    int size;
+    int limit;
+    bool error;
+    bool populate;
+};
+
+#define VIR_DOMAIN_LIST_POPULATION_INCREMENT 10
+
+static void
+qemuPopulateDomainList(void *payload,
+                       const void *name ATTRIBUTE_UNUSED,
+                       void *opaque)
+{
+    struct virDomainListData *data = opaque;
+    virDomainObjPtr vm = payload;
+
+    if (data->error ||
+        (data->limit >= 0 &&
+         data->ndomains >= data->limit))
+        return;
+
+    if (!data->populate) {
+        data->ndomains++;
+        return;
+    }
+
+    virDomainObjLock(vm);
+
+    if (data->size == data->ndomains) {
+        if (VIR_REALLOC_N(data->domains,
+                          data->size + VIR_DOMAIN_LIST_POPULATION_INCREMENT) < 0)
+            goto no_memory;
+        data->size += VIR_DOMAIN_LIST_POPULATION_INCREMENT;
+    }
+
+    data->domains[data->ndomains] = virGetDomain(data->conn,
+                                                 vm->def->name,
+                                                 vm->def->uuid);
+    if (data->domains[data->ndomains] == NULL)
+        goto no_memory;
+
+    data->domains[data->ndomains]->id = vm->def->id;
+    data->ndomains++;
+
+cleanup:
+    virDomainObjUnlock(vm);
+    return;
+
+no_memory:
+    virReportOOMError();
+    data->error = true;
+    goto cleanup;
+}
+
+static int
+qemuListAllDomains(virConnectPtr conn,
+                   virDomainPtr **domains,
+                   int ndomains,
+                   unsigned int flags)
+{
+    struct qemud_driver *driver = conn->privateData;
+    int ret = -1;
+    int i;
+
+    struct virDomainListData data = { conn,  NULL, 0, 0, ndomains,
+                                     false, !!domains};
+
+    virCheckFlags(0, -1);
+
+    qemuDriverLock(driver);
+
+    virHashForEach(driver->domains.objs, qemuPopulateDomainList,
+                   (void *) &data);
+
+    if (data.error) {
+        for (i = 0; i < data.size; i++) {
+            if (data.domains[i])
+                virDomainFree(data.domains[i]);
+        }
+        VIR_FREE(data.domains);
+        data.ndomains = -1;
+    }
+
+    if (domains)
+        *domains = data.domains;
+
+    ret = data.ndomains;
+
+    qemuDriverUnlock(driver);
+    return ret;
+}
+
 static virDriver qemuDriver = {
     .no = VIR_DRV_QEMU,
     .name = QEMU_DRIVER_NAME,
@@ -13108,6 +13204,7 @@ static virDriver qemuDriver = {
     .domainPMSuspendForDuration = qemuDomainPMSuspendForDuration, /* 0.9.11 */
     .domainPMWakeup = qemuDomainPMWakeup, /* 0.9.11 */
     .domainGetCPUStats = qemuDomainGetCPUStats, /* 0.9.11 */
+    .connectListAllDomains = qemuListAllDomains, /* 0.9.13 */
 };


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