[PATCH 4/8] hyperv: replace generic WMI class list helpers with a macro

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

 



From: Matt Coleman <matt@xxxxxxxxx>

Signed-off-by: Matt Coleman <matt@xxxxxxxxx>
---
 src/hyperv/hyperv_driver.c | 39 +++++++++++------
 src/hyperv/hyperv_wmi.c    | 87 ++++----------------------------------
 src/hyperv/hyperv_wmi.h    | 34 +++------------
 3 files changed, 41 insertions(+), 119 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index d883fd616c..4ba226d446 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -47,6 +47,20 @@ VIR_LOG_INIT("hyperv.hyperv_driver");
  * wrapper functions for commonly-accessed WMI objects and interfaces.
  */
 
+/**
+ * hypervGetWmiClass:
+ * @type: the type of the class being retrieved from WMI
+ * @class: double pointer where the class data will be stored
+ *
+ * Retrieve one or more classes from WMI.
+ *
+ * The following variables must exist in the caller:
+ *   1. hypervPrivate *priv
+ *   2. virBuffer query
+ */
+#define hypervGetWmiClass(type, class) \
+    hypervGetWmiClassList(priv, type ## _WmiInfo, &query, (hypervObject **)class)
+
 static int
 hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
                           Win32_Processor **processorList)
@@ -58,7 +72,7 @@ hypervGetProcessorsByName(hypervPrivate *priv, const char *name,
                        "ResultClass = Win32_Processor",
                        name);
 
-    if (hypervGetWin32ProcessorList(priv, &query, processorList) < 0 || !processorList) {
+    if (hypervGetWmiClass(Win32_Processor, processorList) < 0 || !processorList) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not look up processor(s) on '%s'"),
                        name);
@@ -76,7 +90,7 @@ hypervGetActiveVirtualSystemList(hypervPrivate *priv,
                                              "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
                                              "AND " MSVM_COMPUTERSYSTEM_WQL_ACTIVE), 0 };
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not look up active virtual machines"));
         return -1;
     }
@@ -93,7 +107,7 @@ hypervGetInactiveVirtualSystemList(hypervPrivate *priv,
                                              "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
                                              "AND " MSVM_COMPUTERSYSTEM_WQL_INACTIVE), 0 };
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not look up inactive virtual machines"));
         return -1;
     }
@@ -107,7 +121,7 @@ hypervGetPhysicalSystemList(hypervPrivate *priv,
 {
     g_auto(virBuffer) query = { g_string_new(WIN32_COMPUTERSYSTEM_WQL_SELECT), 0 };
 
-    if (hypervGetWin32ComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Win32_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not look up Win32_ComputerSystem"));
         return -1;
     }
@@ -126,7 +140,7 @@ hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
                       "AND ProcessID = %d",
                       id);
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not look up virtual system with ID %d"), id);
         return -1;
     }
@@ -145,7 +159,7 @@ hypervGetVirtualSystemByUUID(hypervPrivate *priv, const char *uuid,
                        "AND Name = \"%s\"",
                        uuid);
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not look up virtual system with UUID '%s'"), uuid);
         return -1;
     }
@@ -165,7 +179,7 @@ hypervGetVirtualSystemByName(hypervPrivate *priv, const char *name,
                        "AND ElementName = \"%s\"",
                        name);
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystemList) < 0 || !*computerSystemList) {
+    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0 || !*computerSystemList) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not look up virtual system named '%s'"), name);
         return -1;
     }
@@ -184,7 +198,7 @@ hypervGetVSSDFromUUID(hypervPrivate *priv, const char *uuid,
                        "ResultClass = Msvm_VirtualSystemSettingData",
                        uuid);
 
-    if (hypervGetMsvmVirtualSystemSettingDataList(priv, &query, data) < 0 || !*data) {
+    if (hypervGetWmiClass(Msvm_VirtualSystemSettingData, data) < 0 || !*data) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not look up virtual system setting data with UUID '%s'"),
                        uuid);
@@ -205,7 +219,7 @@ hypervGetProcSDByVSSDInstanceId(hypervPrivate *priv, const char *id,
                        "ResultClass = Msvm_ProcessorSettingData",
                        id);
 
-    if (hypervGetMsvmProcessorSettingDataList(priv, &query, data) < 0 || !*data) {
+    if (hypervGetWmiClass(Msvm_ProcessorSettingData, data) < 0 || !*data) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not look up processor setting data with virtual system instance ID '%s'"),
                        id);
@@ -226,7 +240,7 @@ hypervGetMemSDByVSSDInstanceId(hypervPrivate *priv, const char *id,
                        "ResultClass = Msvm_MemorySettingData",
                        id);
 
-    if (hypervGetMsvmMemorySettingDataList(priv, &query, data) < 0 || !*data) {
+    if (hypervGetWmiClass(Msvm_MemorySettingData, data) < 0 || !*data) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not look up memory setting data with virtual system instance ID '%s'"),
                        id);
@@ -1279,8 +1293,7 @@ hypervConnectListAllDomains(virConnectPtr conn,
         }
     }
 
-    if (hypervGetMsvmComputerSystemList(priv, &query,
-                                        &computerSystemList) < 0)
+    if (hypervGetWmiClass(Msvm_ComputerSystem, &computerSystemList) < 0)
         goto cleanup;
 
     if (domains) {
@@ -1386,7 +1399,7 @@ hypervDomainSendKey(virDomainPtr domain, unsigned int codeset,
             "where ResultClass = Msvm_Keyboard",
             uuid_string);
 
-    if (hypervGetMsvmKeyboardList(priv, &query, &keyboard) < 0)
+    if (hypervGetWmiClass(Msvm_Keyboard, &keyboard) < 0)
         goto cleanup;
 
     translatedKeycodes = g_new0(int, nkeycodes);
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 809f68a844..c1c244868b 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -83,7 +83,7 @@ hypervGetWmiClassInfo(hypervPrivate *priv, hypervWmiClassInfoListPtr list,
     return -1;
 }
 
-static int
+int
 hypervGetWmiClassList(hypervPrivate *priv, hypervWmiClassInfoListPtr wmiInfo,
                       virBufferPtr query, hypervObject **wmiClass)
 {
@@ -878,8 +878,8 @@ hypervInvokeMethod(hypervPrivate *priv, hypervInvokeParamsListPtr params,
             virBufferAddLit(&query, MSVM_CONCRETEJOB_WQL_SELECT);
             virBufferEscapeSQL(&query, "where InstanceID = \"%s\"", instanceID);
 
-            if (hypervGetMsvmConcreteJobList(priv, &query, &job) < 0
-                    || job == NULL)
+            if (hypervGetWmiClassList(priv, Msvm_ConcreteJob_WmiInfo, &query,
+                    (hypervObject **)&job) < 0 || job == NULL)
                 goto cleanup;
 
             jobState = job->data.common->JobState;
@@ -1218,77 +1218,6 @@ hypervReturnCodeToString(int returnCode)
 
 
 
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Generic "Get WMI class list" helpers
- */
-
-int
-hypervGetMsvmComputerSystemList(hypervPrivate *priv, virBufferPtr query,
-                                Msvm_ComputerSystem **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_ComputerSystem_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetMsvmConcreteJobList(hypervPrivate *priv, virBufferPtr query,
-                             Msvm_ConcreteJob **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_ConcreteJob_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetWin32ComputerSystemList(hypervPrivate *priv, virBufferPtr query,
-                                 Win32_ComputerSystem **list)
-{
-    return hypervGetWmiClassList(priv, Win32_ComputerSystem_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetWin32ProcessorList(hypervPrivate *priv, virBufferPtr query,
-                            Win32_Processor **list)
-{
-    return hypervGetWmiClassList(priv, Win32_Processor_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetMsvmVirtualSystemSettingDataList(hypervPrivate *priv,
-                                          virBufferPtr query,
-                                          Msvm_VirtualSystemSettingData **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_VirtualSystemSettingData_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetMsvmProcessorSettingDataList(hypervPrivate *priv,
-                                      virBufferPtr query,
-                                      Msvm_ProcessorSettingData **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_ProcessorSettingData_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int
-hypervGetMsvmMemorySettingDataList(hypervPrivate *priv, virBufferPtr query,
-                                   Msvm_MemorySettingData **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_MemorySettingData_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query,
-                              Msvm_Keyboard **list)
-{
-    return hypervGetWmiClassList(priv, Msvm_Keyboard_WmiInfo, query,
-                                 (hypervObject **)list);
-}
-
-
-
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Msvm_ComputerSystem
  */
@@ -1371,7 +1300,8 @@ hypervInvokeMsvmComputerSystemRequestStateChange(virDomainPtr domain,
             virBufferAddLit(&query, MSVM_CONCRETEJOB_WQL_SELECT);
             virBufferAsprintf(&query, "where InstanceID = \"%s\"", instanceID);
 
-            if (hypervGetMsvmConcreteJobList(priv, &query, &concreteJob) < 0)
+            if (hypervGetWmiClassList(priv, Msvm_ConcreteJob_WmiInfo, &query,
+                                      (hypervObject **)&concreteJob) < 0)
                 goto cleanup;
 
             if (concreteJob == NULL) {
@@ -1560,7 +1490,8 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
     virBufferAddLit(&query, MSVM_COMPUTERSYSTEM_WQL_VIRTUAL);
     virBufferAsprintf(&query, "and Name = \"%s\"", uuid_string);
 
-    if (hypervGetMsvmComputerSystemList(priv, &query, computerSystem) < 0)
+    if (hypervGetWmiClassList(priv, Msvm_ComputerSystem_WmiInfo, &query,
+                              (hypervObject **)computerSystem) < 0)
         return -1;
 
     if (*computerSystem == NULL) {
@@ -1592,7 +1523,7 @@ hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv,
             uuid_string);
 
     if (hypervGetWmiClassList(priv, Msvm_VirtualSystemSettingData_WmiInfo, &query,
-                (hypervObject **)list) < 0 || *list == NULL)
+                              (hypervObject **)list) < 0 || *list == NULL)
         return -1;
 
     return 0;
@@ -1617,7 +1548,7 @@ hypervGetMsvmMemorySettingDataFromVSSD(hypervPrivate *priv,
             vssd_instanceid);
 
     if (hypervGetWmiClassList(priv, Msvm_MemorySettingData_WmiInfo, &query,
-                (hypervObject **)list) < 0 || *list == NULL)
+                              (hypervObject **)list) < 0 || *list == NULL)
         return -1;
 
     return 0;
diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
index 74a74e0e09..c493a45691 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -37,9 +37,6 @@
 #define MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR \
     "CreationClassName=Msvm_VirtualSystemManagementService"
 
-int hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
-                         const char *detail);
-
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@@ -195,43 +192,24 @@ const char *hypervReturnCodeToString(int returnCode);
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Generic "Get WMI class list" helpers
+ * WMI class list helpers
  */
 
-int hypervGetMsvmComputerSystemList(hypervPrivate *priv, virBufferPtr query,
-                                    Msvm_ComputerSystem **list);
-
-int hypervGetMsvmConcreteJobList(hypervPrivate *priv, virBufferPtr query,
-                                 Msvm_ConcreteJob **list);
-
-int hypervGetWin32ComputerSystemList(hypervPrivate *priv, virBufferPtr query,
-                                     Win32_ComputerSystem **list);
-
-int hypervGetWin32ProcessorList(hypervPrivate *priv, virBufferPtr query,
-                                    Win32_Processor **list);
+int hypervGetWmiClassList(hypervPrivate *priv,
+                          hypervWmiClassInfoListPtr wmiInfo, virBufferPtr query,
+                          hypervObject **wmiClass);
 
-int hypervGetMsvmVirtualSystemSettingDataList(hypervPrivate *priv,
-                                              virBufferPtr query,
-                                              Msvm_VirtualSystemSettingData **list);
+int hypervVerifyResponse(WsManClient *client, WsXmlDocH response,
+                         const char *detail);
 
 int hypervGetMsvmVirtualSystemSettingDataFromUUID(hypervPrivate *priv,
                                                   const char *uuid_string,
                                                   Msvm_VirtualSystemSettingData **list);
 
-int hypervGetMsvmProcessorSettingDataList(hypervPrivate *priv,
-                                          virBufferPtr query,
-                                          Msvm_ProcessorSettingData **list);
-
-int hypervGetMsvmMemorySettingDataList(hypervPrivate *priv, virBufferPtr query,
-                                       Msvm_MemorySettingData **list);
-
 int hypervGetMsvmMemorySettingDataFromVSSD(hypervPrivate *priv,
                                            const char *vssd_instanceid,
                                            Msvm_MemorySettingData **list);
 
-int hypervGetMsvmKeyboardList(hypervPrivate *priv, virBufferPtr query,
-                                       Msvm_Keyboard **list);
-
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Msvm_ComputerSystem
  */
-- 
2.27.0





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

  Powered by Linux