]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: reduce duplicate code for Msvm_ComputerSystem lookups
authorMatt Coleman <mcoleman@datto.com>
Thu, 22 Oct 2020 16:38:23 +0000 (12:38 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 2 Nov 2020 17:44:21 +0000 (18:44 +0100)
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hyperv/hyperv_driver.c
src/hyperv/hyperv_wmi.c
src/hyperv/hyperv_wmi.h

index 68835cad910b8e562e15dee3dde3a2c16e9a4c93..fba1e355dbc6175bca0f825df9b8a47d2dde9e1a 100644 (file)
@@ -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);
index d804558fe44ada0fb92733ca3cbe09b93ca6b971..66aed01832fe336b00118a0837b1175cd29441c5 100644 (file)
@@ -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
  */
index 570aa07eb807ed078f691fac0f20d01e016eeb23..5b97ab3db9ea69e52d1d1bed7b9d49dcf0d4d41b 100644 (file)
@@ -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);