[PATCH 5/7] hyperv: refactor hypervDomainSetMemoryProperty

Matt Coleman mcoleman at datto.com
Wed Nov 11 06:48:32 UTC 2020


* use hypervMsvmVSMSModifyResourceSettings()
* improve the error message: say which property it failed to set
* remove usage of VIR_FREE()

Signed-off-by: Matt Coleman <matt at datto.com>
---
 src/hyperv/hyperv_driver.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 6d7bc4b80f..e05c10d194 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -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);
 
-- 
2.27.0





More information about the libvir-list mailing list