]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: refactor hypervDomainSetMemoryProperty
authorMatt Coleman <mcoleman@datto.com>
Wed, 11 Nov 2020 06:48:32 +0000 (01:48 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 12 Nov 2020 08:43:54 +0000 (09:43 +0100)
* use hypervMsvmVSMSModifyResourceSettings()
* improve the error message: say which property it failed to set
* remove usage of VIR_FREE()

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hyperv/hyperv_driver.c

index 6d7bc4b80f86d267965cc5f235c62b2cc8138d38..e05c10d19495a5d6f2fdde320c856cb7dff2cb5c 100644 (file)
@@ -933,20 +933,17 @@ hypervDomainGetMaxMemory(virDomainPtr domain)
 
 
 static int
-hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
+hypervDomainSetMemoryProperty(virDomainPtr domain,
+                              unsigned long memory,
                               const char* propertyName)
 {
     int result = -1;
     char uuid_string[VIR_UUID_STRING_BUFLEN];
     hypervPrivate *priv = domain->conn->privateData;
-    char *memory_str = NULL;
-    g_autoptr(hypervInvokeParamsList) params = NULL;
-    unsigned long memory_mb = VIR_ROUND_UP(VIR_DIV_UP(memory, 1024), 2);
     Msvm_VirtualSystemSettingData *vssd = NULL;
     Msvm_MemorySettingData *memsd = NULL;
     g_autoptr(GHashTable) memResource = NULL;
-
-    memory_str = g_strdup_printf("%lu", memory_mb);
+    g_autofree char *memory_str = g_strdup_printf("%lu", VIR_ROUND_UP(VIR_DIV_UP(memory, 1024), 2));
 
     virUUIDFormat(domain->uuid, uuid_string);
 
@@ -956,13 +953,6 @@ hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
     if (hypervGetMemorySD(priv, vssd->data->InstanceID, &memsd) < 0)
         goto cleanup;
 
-    params = hypervCreateInvokeParamsList("ModifyResourceSettings",
-                                          MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR,
-                                          Msvm_VirtualSystemManagementService_WmiInfo);
-
-    if (!params)
-        goto cleanup;
-
     memResource = hypervCreateEmbeddedParam(Msvm_MemorySettingData_WmiInfo);
     if (!memResource)
         goto cleanup;
@@ -973,19 +963,13 @@ hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
     if (hypervSetEmbeddedProperty(memResource, "InstanceID", memsd->data->InstanceID) < 0)
         goto cleanup;
 
-    if (hypervAddEmbeddedParam(params, "ResourceSettings",
-                               &memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
-        hypervFreeEmbeddedParam(memResource);
-        goto cleanup;
-    }
-
-    if (hypervInvokeMethod(priv, &params, NULL) < 0)
+    if (hypervMsvmVSMSModifyResourceSettings(priv, &memResource,
+                                             Msvm_MemorySettingData_WmiInfo) < 0)
         goto cleanup;
 
     result = 0;
 
  cleanup:
-    VIR_FREE(memory_str);
     hypervFreeObject(priv, (hypervObject *)vssd);
     hypervFreeObject(priv, (hypervObject *)memsd);