[PATCH 5/6] hyperv: reduce duplicate code for Msvm_ComputerSystem lookups

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

 



Signed-off-by: Matt Coleman <matt@xxxxxxxxx>
---
 src/hyperv/hyperv_driver.c | 26 +-------------------------
 src/hyperv/hyperv_wmi.c    | 36 ++++++++++++++++++++++--------------
 src/hyperv/hyperv_wmi.h    |  4 ++++
 3 files changed, 27 insertions(+), 39 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 68835cad91..fba1e355db 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -172,30 +172,6 @@ hypervGetVirtualSystemByID(hypervPrivate *priv, int id,
 }
 
 
-static int
-hypervGetVirtualSystemByUUID(hypervPrivate *priv, const char *uuid,
-                             Msvm_ComputerSystem **computerSystemList)
-{
-    g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
-    virBufferEscapeSQL(&query,
-                       MSVM_COMPUTERSYSTEM_WQL_SELECT
-                       "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
-                       "AND Name = '%s'",
-                       uuid);
-
-    if (hypervGetWmiClass(Msvm_ComputerSystem, computerSystemList) < 0)
-        return -1;
-
-    if (*computerSystemList == NULL) {
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("No domain with UUID %s"), uuid);
-        return -1;
-    }
-
-    return 0;
-}
-
-
 static int
 hypervGetVirtualSystemByName(hypervPrivate *priv, const char *name,
                              Msvm_ComputerSystem **computerSystemList)
@@ -806,7 +782,7 @@ hypervDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
 
     virUUIDFormat(uuid, uuid_string);
 
-    if (hypervGetVirtualSystemByUUID(priv, uuid_string, &computerSystem) < 0)
+    if (hypervMsvmComputerSystemFromUUID(priv, uuid_string, &computerSystem) < 0)
         goto cleanup;
 
     hypervMsvmComputerSystemToDomain(conn, computerSystem, &domain);
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index d804558fe4..66aed01832 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -1508,32 +1508,27 @@ hypervMsvmComputerSystemToDomain(virConnectPtr conn,
 
 
 int
-hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
-                                   Msvm_ComputerSystem **computerSystem)
+hypervMsvmComputerSystemFromUUID(hypervPrivate *priv, const char *uuid,
+                                 Msvm_ComputerSystem **computerSystem)
 {
-    hypervPrivate *priv = domain->conn->privateData;
-    char uuid_string[VIR_UUID_STRING_BUFLEN];
     g_auto(virBuffer) query = VIR_BUFFER_INITIALIZER;
 
-    if (computerSystem == NULL || *computerSystem != NULL) {
+    if (!computerSystem || *computerSystem) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
         return -1;
     }
 
-    virUUIDFormat(domain->uuid, uuid_string);
-
-    virBufferAsprintf(&query,
-                      MSVM_COMPUTERSYSTEM_WQL_SELECT
-                      "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
-                      "AND Name = '%s'", uuid_string);
+    virBufferEscapeSQL(&query,
+                       MSVM_COMPUTERSYSTEM_WQL_SELECT
+                       "WHERE " MSVM_COMPUTERSYSTEM_WQL_VIRTUAL
+                       "AND Name = '%s'", uuid);
 
     if (hypervGetWmiClassList(priv, Msvm_ComputerSystem_WmiInfo, &query,
                               (hypervObject **)computerSystem) < 0)
         return -1;
 
-    if (*computerSystem == NULL) {
-        virReportError(VIR_ERR_NO_DOMAIN,
-                       _("No domain with UUID %s"), uuid_string);
+    if (!*computerSystem) {
+        virReportError(VIR_ERR_NO_DOMAIN, _("No domain with UUID %s"), uuid);
         return -1;
     }
 
@@ -1541,6 +1536,19 @@ hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
 }
 
 
+int
+hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
+                                   Msvm_ComputerSystem **computerSystem)
+{
+    hypervPrivate *priv = domain->conn->privateData;
+    char uuidString[VIR_UUID_STRING_BUFLEN];
+
+    virUUIDFormat(domain->uuid, uuidString);
+
+    return hypervMsvmComputerSystemFromUUID(priv, uuidString, computerSystem);
+}
+
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Msvm_VirtualSystemSettingData
  */
diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h
index 570aa07eb8..5b97ab3db9 100644
--- a/src/hyperv/hyperv_wmi.h
+++ b/src/hyperv/hyperv_wmi.h
@@ -233,5 +233,9 @@ int hypervMsvmComputerSystemToDomain(virConnectPtr conn,
                                      Msvm_ComputerSystem *computerSystem,
                                      virDomainPtr *domain);
 
+int
+hypervMsvmComputerSystemFromUUID(hypervPrivate *priv, const char *uuid,
+                                 Msvm_ComputerSystem **computerSystem);
+
 int hypervMsvmComputerSystemFromDomain(virDomainPtr domain,
                                        Msvm_ComputerSystem **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