[PATCH 6/8] test driver: Implement testNodeGetFreeMemory

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

 



Signed-off-by: Tomáš Ryšavý <tom.rysavy.0@xxxxxxxxx>
---
 src/test/test_driver.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index a55519f..cf357c4 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -74,6 +74,7 @@ VIR_LOG_INIT("test.test_driver");
 
 struct _testCell {
     unsigned long mem;
+    unsigned long freeMem;
     int numCpus;
     virCapsHostNUMACellCPU cpus[MAX_CPUS];
 };
@@ -1273,6 +1274,7 @@ testOpenDefault(virConnectPtr conn)
     for (u = 0; u < privconn->numCells; ++u) {
         privconn->cells[u].numCpus = 8;
         privconn->cells[u].mem = (u + 1) * 2048 * 1024;
+        privconn->cells[u].freeMem = (u + 1) * 2048 * 512;
     }
     for (u = 0; u < 16; u++) {
         virBitmapPtr siblings = virBitmapNew(16);
@@ -2750,6 +2752,32 @@ testNodeGetCPUStats(virConnectPtr conn ATTRIBUTE_UNUSED,
     return 0;
 }
 
+static unsigned long long
+testNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+    unsigned int ret = 0;
+    unsigned int freeMem = 0;
+    size_t i;
+
+    testDriverPtr privconn = conn->privateData;
+
+    testDriverLock(privconn);
+
+    if (privconn->cells) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       "%s", _("Range exceeds available cells"));
+        goto cleanup;
+    }
+
+    for (i = 0; i < privconn->numCells; i++)
+        freeMem += privconn->cells[i].freeMem;
+    ret = freeMem;
+
+ cleanup:
+    testDriverUnlock(privconn);
+    return ret;
+}
+
 static int testDomainCreateWithFlags(virDomainPtr domain, unsigned int flags)
 {
     testDriverPtr privconn = domain->conn->privateData;
@@ -6742,6 +6770,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */
     .nodeGetInfo = testNodeGetInfo, /* 0.1.1 */
     .nodeGetCPUStats = testNodeGetCPUStats, /* 2.3.0 */
+    .nodeGetFreeMemory = testNodeGetFreeMemory, /* 2.3.0 */
     .connectGetCapabilities = testConnectGetCapabilities, /* 0.2.1 */
     .connectGetSysinfo = testConnectGetSysinfo, /* 2.3.0 */
     .connectGetType = testConnectGetType, /* 2.3.0 */
-- 
2.9.3

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