]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: implement nodeGetFreeMemory
authorMatt Coleman <mcoleman@datto.com>
Wed, 21 Oct 2020 08:46:08 +0000 (04:46 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 21 Oct 2020 12:20:41 +0000 (14:20 +0200)
Co-authored-by: Sri Ramanujam <sramanujam@datto.com>
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hyperv/hyperv_driver.c

index 9fa26e2324b2f219d47796523d93e5c18a08c2c2..53a59695d0d6848cc1ff8720a13d49919e3e476d 100644 (file)
@@ -1397,6 +1397,32 @@ hypervDomainSetAutostart(virDomainPtr domain, int autostart)
 }
 
 
+static unsigned long long
+hypervNodeGetFreeMemory(virConnectPtr conn)
+{
+    unsigned long long freeMemoryBytes = 0;
+    hypervPrivate *priv = conn->privateData;
+    Win32_OperatingSystem *operatingSystem = NULL;
+    g_auto(virBuffer) query = { g_string_new(WIN32_OPERATINGSYSTEM_WQL_SELECT), 0 };
+
+    if (hypervGetWmiClass(Win32_OperatingSystem, &operatingSystem) < 0)
+        return 0;
+
+    if (!operatingSystem) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not get free memory for host %s"),
+                       conn->uri->server);
+        return 0;
+    }
+
+    freeMemoryBytes = operatingSystem->data.common->FreePhysicalMemory * 1024;
+
+    hypervFreeObject(priv, (hypervObject *)operatingSystem);
+
+    return freeMemoryBytes;
+}
+
+
 static int
 hypervConnectIsEncrypted(virConnectPtr conn)
 {
@@ -1939,6 +1965,7 @@ static virHypervisorDriver hypervHypervisorDriver = {
     .domainCreateWithFlags = hypervDomainCreateWithFlags, /* 0.9.5 */
     .domainGetAutostart = hypervDomainGetAutostart, /* 6.9.0 */
     .domainSetAutostart = hypervDomainSetAutostart, /* 6.9.0 */
+    .nodeGetFreeMemory = hypervNodeGetFreeMemory, /* 6.9.0 */
     .connectIsEncrypted = hypervConnectIsEncrypted, /* 0.9.5 */
     .connectIsSecure = hypervConnectIsSecure, /* 0.9.5 */
     .domainIsActive = hypervDomainIsActive, /* 0.9.5 */