[PATCHv1 7/9] hyperv: Add implementation for virConnectListAllDomains()

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

 



Hyperv doesn't use the common virDomainObjimplementation so
this patch adds a separate implementation.

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 Hyperv only supports persistent
domains, so specifying only VIR_CONNECT_LIST_DOMAINS_TRANSIENT results
into an empty list.
---
New in series. UNTESTED!! (I don't have access to Hyperv, and couldn't even get dependencies to compile this driver, so I'm not even sure if this compiles.)
---
 src/hyperv/hyperv_driver.c |   95 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 3b15292..bf5848f 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1259,6 +1259,100 @@ hypervDomainManagedSaveRemove(virDomainPtr domain, unsigned int flags)
 }


+static int
+hypervListAllDomains(virConnectPtr conn,
+                     virDomainPtr **domains,
+                     unsigned int flags)
+{
+    hypervPrivate *priv = conn->privateData;
+    virBuffer query = VIR_BUFFER_INITIALIZER;
+    Msvm_ComputerSystem *computerSystemList = NULL;
+    Msvm_ComputerSystem *computerSystem = NULL;
+    size_t ndoms;
+    virDomainPtr domain;
+    virDomainPtr *doms = NULL;
+    int count = 0;
+    int ret = -1;
+    int i;
+
+    virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+                  VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+                  VIR_CONNECT_LIST_DOMAINS_TRANSIENT, -1);
+
+    virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_SELECT);
+    virBufferAddLit(&query, "where ");
+    virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL);
+
+    /* construct query with filter depending on flags */
+    if (!(flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE &&
+          flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE)) {
+        if (flags & VIR_CONNECT_LIST_DOMAINS_ACTIVE) {
+            virBufferAddLit(&query, "and ");
+            virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_ACTIVE);
+        }
+        if (flags & VIR_CONNECT_LIST_DOMAINS_INACTIVE) {
+            virBufferAddLit(&query, "and ");
+            virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_INACTIVE);
+        }
+    }
+
+    /* filter by persistent state - all vbox domains are persistent */
+    if (flags & VIR_CONNECT_LIST_DOMAINS_TRANSIENT &&
+        !(flags & VIR_CONNECT_LIST_DOMAINS_PERSISTENT))
+        goto cleanup;
+
+    if (hypervGetMsvmComputerSystemList(priv, &query,
+                                        &computerSystemList) < 0)
+        goto cleanup;
+
+    if (domains) {
+        if (VIR_ALLOC_N(doms, 1) < 0)
+            goto no_memory;
+        ndoms = 1;
+    }
+
+    for (computerSystem = computerSystemList; computerSystem != NULL;
+         computerSystem = computerSystem->next) {
+
+        if (!doms) {
+            count++;
+            continue;
+        }
+
+        if (hypervMsvmComputerSystemToDomain(conn, computerSystem,
+                                             &domain) < 0)
+            goto cleanup;
+
+        if (VIR_EXPAND_N(doms, ndoms, 1) < 0)
+            goto no_memory;
+        doms[count++] = domain;
+    }
+
+    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);
+    hypervFreeObject(priv, (hypervObject *)computerSystemList);
+    return ret;
+
+no_memory:
+    virReportOOMError();
+    goto cleanup;
+}
+
+
+

 static virDriver hypervDriver = {
     .no = VIR_DRV_HYPERV,
@@ -1294,6 +1388,7 @@ static virDriver hypervDriver = {
     .domainHasManagedSaveImage = hypervDomainHasManagedSaveImage, /* 0.9.5 */
     .domainManagedSaveRemove = hypervDomainManagedSaveRemove, /* 0.9.5 */
     .isAlive = hypervIsAlive, /* 0.9.8 */
+    .listAllDomains = hypervListAllDomains, /* 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]