[libvirt] [PATCH 05/21] Added implementation for virNodeGetFreeMemory (required Win32_OperatingSystem class)

Yves Vinter yves.vinter at bull.net
Wed Oct 8 12:33:50 UTC 2014


From: yvinter <yves.vinter at bull.net>

---
 src/hyperv/hyperv_driver.c            | 34 ++++++++++++++++++
 src/hyperv/hyperv_wmi_generator.input | 68 +++++++++++++++++++++++++++++++++++
 src/hyperv/hyperv_wmi_generator.py    |  1 +
 3 files changed, 103 insertions(+)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index f734c09..191c7dd 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1712,6 +1712,39 @@ hypervDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo,
 
 
 
+static unsigned long long
+hypervNodeGetFreeMemory(virConnectPtr conn)
+{
+    unsigned long long res = 0;
+    hypervPrivate *priv = conn->privateData;
+    virBuffer query = VIR_BUFFER_INITIALIZER;
+    Win32_OperatingSystem *operatingSystem = NULL;
+    
+    /* Get Win32_OperatingSystem */
+    virBufferAddLit(&query, WIN32_OPERATINGSYSTEM_WQL_SELECT);
+    
+    if (hypervGetWin32OperatingSystemList(priv, &query, &operatingSystem) < 0) {
+        goto cleanup;
+    }
+    
+    if (operatingSystem == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not get Win32_OperatingSystem"));
+        goto cleanup;
+    }
+    
+    /* Return free memory in bytes */
+    res = operatingSystem->data->FreePhysicalMemory * 1024;
+    
+ cleanup:
+    hypervFreeObject(priv, (hypervObject *) operatingSystem);
+    virBufferFreeAndReset(&query);
+
+    return res;
+}
+
+
+
 static virDriver hypervDriver = {
     .no = VIR_DRV_HYPERV,
     .name = "Hyper-V",
@@ -1753,6 +1786,7 @@ static virDriver hypervDriver = {
     .domainGetMaxVcpus = hypervDomainGetMaxVcpus, /* 1.2.10 */
     .domainGetVcpusFlags = hypervDomainGetVcpusFlags, /* 1.2.10 */
     .domainGetVcpus = hypervDomainGetVcpus, /* 1.2.10 */
+    .nodeGetFreeMemory = hypervNodeGetFreeMemory, /* 1.2.10 */
 };
 
 
diff --git a/src/hyperv/hyperv_wmi_generator.input b/src/hyperv/hyperv_wmi_generator.input
index 8fb34e4..739be87 100644
--- a/src/hyperv/hyperv_wmi_generator.input
+++ b/src/hyperv/hyperv_wmi_generator.input
@@ -454,3 +454,71 @@ class Win32_PerfRawData_HvStats_HyperVHypervisorVirtualProcessor
 	uint64   VirtualMMUHypercallsPersec
 	uint64   VirtualProcessorHypercallsPersec
 end
+
+
+class Win32_OperatingSystem
+	string   BootDevice
+	string   BuildNumber
+	string   BuildType
+	string   Caption
+	string   CodeSet
+	string   CountryCode
+	string   CreationClassName
+	string   CSCreationClassName
+	string   CSDVersion
+	string   CSName
+	sint16   CurrentTimeZone
+	boolean  DataExecutionPrevention_Available
+	boolean  DataExecutionPrevention_32BitApplications
+	boolean  DataExecutionPrevention_Drivers
+	uint8    DataExecutionPrevention_SupportPolicy
+	boolean  Debug
+	string   Description
+	boolean  Distributed
+	uint32   EncryptionLevel
+	uint8    ForegroundApplicationBoost
+	uint64   FreePhysicalMemory
+	uint64   FreeSpaceInPagingFiles
+	uint64   FreeVirtualMemory
+	datetime InstallDate
+	uint32   LargeSystemCache
+	datetime LastBootUpTime
+	datetime LocalDateTime
+	string   Locale
+	string   Manufacturer
+	uint32   MaxNumberOfProcesses
+	uint64   MaxProcessMemorySize
+	string   MUILanguages[]
+	string   Name
+	uint32   NumberOfLicensedUsers
+	uint32   NumberOfProcesses
+	uint32   NumberOfUsers
+	uint32   OperatingSystemSKU
+	string   Organization
+	string   OSArchitecture
+	uint32   OSLanguage
+	uint32   OSProductSuite
+	uint16   OSType
+	string   OtherTypeDescription
+	boolean  PAEEnabled
+	string   PlusProductID
+	string   PlusVersionNumber
+	boolean  PortableOperatingSystem
+	boolean  Primary
+	uint32   ProductType
+	string   RegisteredUser
+	string   SerialNumber
+	uint16   ServicePackMajorVersion
+	uint16   ServicePackMinorVersion
+	uint64   SizeStoredInPagingFiles
+	string   Status
+	uint32   SuiteMask
+	string   SystemDevice
+	string   SystemDirectory
+	string   SystemDrive
+	uint64   TotalSwapSpaceSize
+	uint64   TotalVirtualMemorySize
+	uint64   TotalVisibleMemorySize
+	string   Version
+	string   WindowsDirectory
+end
diff --git a/src/hyperv/hyperv_wmi_generator.py b/src/hyperv/hyperv_wmi_generator.py
index 1011719..5010470 100755
--- a/src/hyperv/hyperv_wmi_generator.py
+++ b/src/hyperv/hyperv_wmi_generator.py
@@ -158,6 +158,7 @@ class Property:
                "int16"    : "INT16",
                "int32"    : "INT32",
                "int64"    : "INT64",
+               "sint16"   : "INT16",
                "uint8"    : "UINT8",
                "uint16"   : "UINT16",
                "uint32"   : "UINT32",
-- 
1.9.1




More information about the libvir-list mailing list