mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
hyperv: refactor hypervDomainSetMemoryProperty
* 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>
This commit is contained in:
parent
5df9f9dadf
commit
16fb99c7a1
@ -933,20 +933,17 @@ hypervDomainGetMaxMemory(virDomainPtr domain)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
|
hypervDomainSetMemoryProperty(virDomainPtr domain,
|
||||||
|
unsigned long memory,
|
||||||
const char* propertyName)
|
const char* propertyName)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int result = -1;
|
||||||
char uuid_string[VIR_UUID_STRING_BUFLEN];
|
char uuid_string[VIR_UUID_STRING_BUFLEN];
|
||||||
hypervPrivate *priv = domain->conn->privateData;
|
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_VirtualSystemSettingData *vssd = NULL;
|
||||||
Msvm_MemorySettingData *memsd = NULL;
|
Msvm_MemorySettingData *memsd = NULL;
|
||||||
g_autoptr(GHashTable) memResource = NULL;
|
g_autoptr(GHashTable) memResource = NULL;
|
||||||
|
g_autofree char *memory_str = g_strdup_printf("%lu", VIR_ROUND_UP(VIR_DIV_UP(memory, 1024), 2));
|
||||||
memory_str = g_strdup_printf("%lu", memory_mb);
|
|
||||||
|
|
||||||
virUUIDFormat(domain->uuid, uuid_string);
|
virUUIDFormat(domain->uuid, uuid_string);
|
||||||
|
|
||||||
@ -956,13 +953,6 @@ hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
|
|||||||
if (hypervGetMemorySD(priv, vssd->data->InstanceID, &memsd) < 0)
|
if (hypervGetMemorySD(priv, vssd->data->InstanceID, &memsd) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
params = hypervCreateInvokeParamsList("ModifyResourceSettings",
|
|
||||||
MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR,
|
|
||||||
Msvm_VirtualSystemManagementService_WmiInfo);
|
|
||||||
|
|
||||||
if (!params)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
memResource = hypervCreateEmbeddedParam(Msvm_MemorySettingData_WmiInfo);
|
memResource = hypervCreateEmbeddedParam(Msvm_MemorySettingData_WmiInfo);
|
||||||
if (!memResource)
|
if (!memResource)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -973,19 +963,13 @@ hypervDomainSetMemoryProperty(virDomainPtr domain, unsigned long memory,
|
|||||||
if (hypervSetEmbeddedProperty(memResource, "InstanceID", memsd->data->InstanceID) < 0)
|
if (hypervSetEmbeddedProperty(memResource, "InstanceID", memsd->data->InstanceID) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (hypervAddEmbeddedParam(params, "ResourceSettings",
|
if (hypervMsvmVSMSModifyResourceSettings(priv, &memResource,
|
||||||
&memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
|
Msvm_MemorySettingData_WmiInfo) < 0)
|
||||||
hypervFreeEmbeddedParam(memResource);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hypervInvokeMethod(priv, ¶ms, NULL) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(memory_str);
|
|
||||||
hypervFreeObject(priv, (hypervObject *)vssd);
|
hypervFreeObject(priv, (hypervObject *)vssd);
|
||||||
hypervFreeObject(priv, (hypervObject *)memsd);
|
hypervFreeObject(priv, (hypervObject *)memsd);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user