[PATCH 1/7] hyperv: implement domainSetAutostart

Matt Coleman mcoleman at datto.com
Fri Oct 9 10:09:50 UTC 2020


> On Oct 9, 2020, at 4:58 AM, Pino Toscano <ptoscano at redhat.com> wrote:
> 
> On Friday, 9 October 2020 10:31:50 CEST Matt Coleman wrote:
>> +static int
>> +hypervDomainSetAutostart(virDomainPtr domain, int autostart)
>> +{
>> +    int result = -1;
>> +    char uuid_string[VIR_UUID_STRING_BUFLEN];
>> +    hypervPrivate *priv = domain->conn->privateData;
>> +    Msvm_VirtualSystemSettingData *vssd = NULL;
>> +    hypervInvokeParamsListPtr params = NULL;
>> +    g_auto(virBuffer) eprQuery = VIR_BUFFER_INITIALIZER;
>> +    virHashTablePtr autostartParam = NULL;
>> +    hypervWmiClassInfoListPtr embeddedParamClass = NULL;
>> +    const char *methodName = NULL, *embeddedParamName = NULL;
>> +    g_autofree char *enabledValue = NULL, *disabledValue = NULL;
>> +
>> +    if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
>> +        methodName = "ModifyVirtualSystem";
>> +        embeddedParamName = "SystemSettingData";
>> +        embeddedParamClass = Msvm_VirtualSystemGlobalSettingData_WmiInfo;
>> +        enabledValue = g_strdup("2");
>> +        disabledValue = g_strdup("0");
>> +    } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2) {
>> +        methodName = "ModifySystemSettings";
>> +        embeddedParamName = "SystemSettings";
>> +        embeddedParamClass = Msvm_VirtualSystemSettingData_WmiInfo;
>> +        enabledValue = g_strdup("4");
>> +        disabledValue = g_strdup("2");
>> +    }
> 
> It looks like 'enabledValue' and 'disabledValue' can be static strings
> (like 'methodName' and 'embeddedParamName').

I removed g_autofree and g_strdup() with the following patch applied on 
top of my initial changes. Can it be squashed into this commit, or do I 
have to submit a [PATCH v2]?

Signed-off-by: Matt Coleman <matt at datto.com>
---
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index c91bc58488..baaace041b 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1450,20 +1450,18 @@ hypervDomainSetAutostart(virDomainPtr domain, int autostart)
     virHashTablePtr autostartParam = NULL;
     hypervWmiClassInfoListPtr embeddedParamClass = NULL;
     const char *methodName = NULL, *embeddedParamName = NULL;
-    g_autofree char *enabledValue = NULL, *disabledValue = NULL;
+    char enabledValue[] = "2", disabledValue[] = "0";
 
     if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
         methodName = "ModifyVirtualSystem";
         embeddedParamName = "SystemSettingData";
         embeddedParamClass = Msvm_VirtualSystemGlobalSettingData_WmiInfo;
-        enabledValue = g_strdup("2");
-        disabledValue = g_strdup("0");
     } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2) {
         methodName = "ModifySystemSettings";
         embeddedParamName = "SystemSettings";
         embeddedParamClass = Msvm_VirtualSystemSettingData_WmiInfo;
-        enabledValue = g_strdup("4");
-        disabledValue = g_strdup("2");
+        enabledValue[0] = '4';
+        disabledValue[0] = '2';
     }
 
     virUUIDFormat(domain->uuid, uuid_string);





More information about the libvir-list mailing list