[libvirt] [PATCH 14/23] qemu_conf: split out virQEMUDriverConfigLoadProcessEntry

Ján Tomko posted 23 patches 7 years ago
[libvirt] [PATCH 14/23] qemu_conf: split out virQEMUDriverConfigLoadProcessEntry
Posted by Ján Tomko 7 years ago
Split out parts of the config parsing code to make
the parent function easier to read.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_conf.c | 162 ++++++++++++++++++++++++-------------------
 1 file changed, 90 insertions(+), 72 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 776ba3f3ad..8bc653fa9e 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -423,6 +423,95 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs,
 }
 
 
+static int
+virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfigPtr cfg,
+                                    virConfPtr conf)
+{
+    char *stdioHandler = NULL;
+    char **hugetlbfs = NULL;
+    char *corestr = NULL;
+    int ret = -1;
+    size_t i;
+
+    if (virConfGetValueStringList(conf, "hugetlbfs_mount", true,
+                                  &hugetlbfs) < 0)
+        goto cleanup;
+    if (hugetlbfs) {
+        /* There already might be something autodetected. Avoid leaking it. */
+        while (cfg->nhugetlbfs) {
+            cfg->nhugetlbfs--;
+            VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
+        }
+        VIR_FREE(cfg->hugetlbfs);
+
+        cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
+        if (hugetlbfs[0] &&
+            VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0)
+            goto cleanup;
+
+        for (i = 0; hugetlbfs[i] != NULL; i++) {
+            if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i],
+                                                 hugetlbfs[i], i != 0) < 0)
+                goto cleanup;
+        }
+    }
+
+    if (virConfGetValueBool(conf, "clear_emulator_capabilities", &cfg->clearEmulatorCapabilities) < 0)
+        goto cleanup;
+    if (virConfGetValueString(conf, "bridge_helper", &cfg->bridgeHelperName) < 0)
+        goto cleanup;
+
+    if (virConfGetValueString(conf, "pr_helper", &cfg->prHelperName) < 0)
+        goto cleanup;
+
+    if (virConfGetValueBool(conf, "set_process_name", &cfg->setProcessName) < 0)
+        goto cleanup;
+    if (virConfGetValueUInt(conf, "max_processes", &cfg->maxProcesses) < 0)
+        goto cleanup;
+    if (virConfGetValueUInt(conf, "max_files", &cfg->maxFiles) < 0)
+        goto cleanup;
+
+    if (virConfGetValueType(conf, "max_core") == VIR_CONF_STRING) {
+        if (virConfGetValueString(conf, "max_core", &corestr) < 0)
+            goto cleanup;
+        if (STREQ(corestr, "unlimited")) {
+            cfg->maxCore = ULLONG_MAX;
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Unknown core size '%s'"),
+                           corestr);
+            goto cleanup;
+        }
+    } else if (virConfGetValueULLong(conf, "max_core", &cfg->maxCore) < 0) {
+        goto cleanup;
+    }
+
+    if (virConfGetValueBool(conf, "dump_guest_core", &cfg->dumpGuestCore) < 0)
+        goto cleanup;
+    if (virConfGetValueString(conf, "stdio_handler", &stdioHandler) < 0)
+        goto cleanup;
+    if (stdioHandler) {
+        if (STREQ(stdioHandler, "logd")) {
+            cfg->stdioLogD = true;
+        } else if (STREQ(stdioHandler, "file")) {
+            cfg->stdioLogD = false;
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Unknown stdio handler %s"),
+                           stdioHandler);
+            VIR_FREE(stdioHandler);
+            goto cleanup;
+        }
+        VIR_FREE(stdioHandler);
+    }
+
+    ret = 0;
+ cleanup:
+    virStringListFree(hugetlbfs);
+    VIR_FREE(corestr);
+    return ret;
+}
+
 static int
 virQEMUDriverConfigLoadDeviceEntry(virQEMUDriverConfigPtr cfg,
                                    virConfPtr conf)
@@ -722,8 +811,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
     virConfPtr conf = NULL;
     int ret = -1;
     int rv;
-    size_t i;
-    char *stdioHandler = NULL;
     char **hugetlbfs = NULL;
     char *corestr = NULL;
 
@@ -894,79 +981,10 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
         goto cleanup;
     if (virConfGetValueBool(conf, "auto_start_bypass_cache", &cfg->autoStartBypassCache) < 0)
         goto cleanup;
-
-    if (virConfGetValueStringList(conf, "hugetlbfs_mount", true,
-                                  &hugetlbfs) < 0)
-        goto cleanup;
-    if (hugetlbfs) {
-        /* There already might be something autodetected. Avoid leaking it. */
-        while (cfg->nhugetlbfs) {
-            cfg->nhugetlbfs--;
-            VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
-        }
-        VIR_FREE(cfg->hugetlbfs);
-
-        cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
-        if (hugetlbfs[0] &&
-            VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0)
-            goto cleanup;
-
-        for (i = 0; hugetlbfs[i] != NULL; i++) {
-            if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i],
-                                                 hugetlbfs[i], i != 0) < 0)
-                goto cleanup;
-        }
-    }
-
-    if (virConfGetValueString(conf, "bridge_helper", &cfg->bridgeHelperName) < 0)
-        goto cleanup;
-
-    if (virConfGetValueString(conf, "pr_helper", &cfg->prHelperName) < 0)
         goto cleanup;
 
-    if (virConfGetValueBool(conf, "clear_emulator_capabilities", &cfg->clearEmulatorCapabilities) < 0)
-        goto cleanup;
-    if (virConfGetValueBool(conf, "set_process_name", &cfg->setProcessName) < 0)
+    if (virQEMUDriverConfigLoadProcessEntry(cfg, conf) < 0)
         goto cleanup;
-    if (virConfGetValueUInt(conf, "max_processes", &cfg->maxProcesses) < 0)
-        goto cleanup;
-    if (virConfGetValueUInt(conf, "max_files", &cfg->maxFiles) < 0)
-        goto cleanup;
-
-    if (virConfGetValueType(conf, "max_core") == VIR_CONF_STRING) {
-        if (virConfGetValueString(conf, "max_core", &corestr) < 0)
-            goto cleanup;
-        if (STREQ(corestr, "unlimited")) {
-            cfg->maxCore = ULLONG_MAX;
-        } else {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unknown core size '%s'"),
-                           corestr);
-            goto cleanup;
-        }
-    } else if (virConfGetValueULLong(conf, "max_core", &cfg->maxCore) < 0) {
-        goto cleanup;
-    }
-
-    if (virConfGetValueBool(conf, "dump_guest_core", &cfg->dumpGuestCore) < 0)
-        goto cleanup;
-
-    if (virConfGetValueString(conf, "stdio_handler", &stdioHandler) < 0)
-        goto cleanup;
-    if (stdioHandler) {
-        if (STREQ(stdioHandler, "logd")) {
-            cfg->stdioLogD = true;
-        } else if (STREQ(stdioHandler, "file")) {
-            cfg->stdioLogD = false;
-        } else {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("Unknown stdio handler %s"),
-                           stdioHandler);
-            VIR_FREE(stdioHandler);
-            goto cleanup;
-        }
-        VIR_FREE(stdioHandler);
-    }
 
     if (virQEMUDriverConfigLoadDeviceEntry(cfg, conf) < 0)
         goto cleanup;
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 14/23] qemu_conf: split out virQEMUDriverConfigLoadProcessEntry
Posted by John Ferlan 7 years ago

On 1/15/19 8:23 AM, Ján Tomko wrote:
> Split out parts of the config parsing code to make
> the parent function easier to read.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  src/qemu/qemu_conf.c | 162 ++++++++++++++++++++++++-------------------
>  1 file changed, 90 insertions(+), 72 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index 776ba3f3ad..8bc653fa9e 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -423,6 +423,95 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs,
>  }
>  
>  
> +static int
> +virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfigPtr cfg,
> +                                    virConfPtr conf)
> +{
> +    char *stdioHandler = NULL;
> +    char **hugetlbfs = NULL;
> +    char *corestr = NULL;

VIR_AUTOPTR for each

> +    int ret = -1;
> +    size_t i;
> +
> +    if (virConfGetValueStringList(conf, "hugetlbfs_mount", true,
> +                                  &hugetlbfs) < 0)
> +        goto cleanup;
> +    if (hugetlbfs) {
> +        /* There already might be something autodetected. Avoid leaking it. */
> +        while (cfg->nhugetlbfs) {
> +            cfg->nhugetlbfs--;
> +            VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
> +        }
> +        VIR_FREE(cfg->hugetlbfs);
> +
> +        cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
> +        if (hugetlbfs[0] &&
> +            VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0)
> +            goto cleanup;
> +
> +        for (i = 0; hugetlbfs[i] != NULL; i++) {
> +            if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i],
> +                                                 hugetlbfs[i], i != 0) < 0)
> +                goto cleanup;
> +        }
> +    }
> +
> +    if (virConfGetValueBool(conf, "clear_emulator_capabilities", &cfg->clearEmulatorCapabilities) < 0)
> +        goto cleanup;
> +    if (virConfGetValueString(conf, "bridge_helper", &cfg->bridgeHelperName) < 0)
> +        goto cleanup;
> +
> +    if (virConfGetValueString(conf, "pr_helper", &cfg->prHelperName) < 0)
> +        goto cleanup;
> +
> +    if (virConfGetValueBool(conf, "set_process_name", &cfg->setProcessName) < 0)
> +        goto cleanup;
> +    if (virConfGetValueUInt(conf, "max_processes", &cfg->maxProcesses) < 0)
> +        goto cleanup;
> +    if (virConfGetValueUInt(conf, "max_files", &cfg->maxFiles) < 0)
> +        goto cleanup;
> +
> +    if (virConfGetValueType(conf, "max_core") == VIR_CONF_STRING) {
> +        if (virConfGetValueString(conf, "max_core", &corestr) < 0)
> +            goto cleanup;
> +        if (STREQ(corestr, "unlimited")) {
> +            cfg->maxCore = ULLONG_MAX;
> +        } else {
> +            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                           _("Unknown core size '%s'"),
> +                           corestr);
> +            goto cleanup;
> +        }
> +    } else if (virConfGetValueULLong(conf, "max_core", &cfg->maxCore) < 0) {
> +        goto cleanup;
> +    }
> +
> +    if (virConfGetValueBool(conf, "dump_guest_core", &cfg->dumpGuestCore) < 0)
> +        goto cleanup;
> +    if (virConfGetValueString(conf, "stdio_handler", &stdioHandler) < 0)
> +        goto cleanup;
> +    if (stdioHandler) {
> +        if (STREQ(stdioHandler, "logd")) {
> +            cfg->stdioLogD = true;
> +        } else if (STREQ(stdioHandler, "file")) {
> +            cfg->stdioLogD = false;
> +        } else {
> +            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +                           _("Unknown stdio handler %s"),
> +                           stdioHandler);
> +            VIR_FREE(stdioHandler);
> +            goto cleanup;
> +        }
> +        VIR_FREE(stdioHandler);
> +    }
> +
> +    ret = 0;
> + cleanup:
> +    virStringListFree(hugetlbfs);
> +    VIR_FREE(corestr);
> +    return ret;
> +}
> +

blank line

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 14/23] qemu_conf: split out virQEMUDriverConfigLoadProcessEntry
Posted by John Ferlan 7 years ago

On 1/15/19 8:23 AM, Ján Tomko wrote:
> Split out parts of the config parsing code to make
> the parent function easier to read.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  src/qemu/qemu_conf.c | 162 ++++++++++++++++++++++++-------------------
>  1 file changed, 90 insertions(+), 72 deletions(-)
> 

I was too quick with the send push...

[...]

>  static int
>  virQEMUDriverConfigLoadDeviceEntry(virQEMUDriverConfigPtr cfg,
>                                     virConfPtr conf)
> @@ -722,8 +811,6 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
>      virConfPtr conf = NULL;
>      int ret = -1;
>      int rv;
> -    size_t i;
> -    char *stdioHandler = NULL;
>      char **hugetlbfs = NULL;

This is now unused and don't forget the StringListFree at the bottom.

>      char *corestr = NULL;
>  
> @@ -894,79 +981,10 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
>          goto cleanup;
>      if (virConfGetValueBool(conf, "auto_start_bypass_cache", &cfg->autoStartBypassCache) < 0)
>          goto cleanup;
> -
> -    if (virConfGetValueStringList(conf, "hugetlbfs_mount", true,
> -                                  &hugetlbfs) < 0)
> -        goto cleanup;
> -    if (hugetlbfs) {
> -        /* There already might be something autodetected. Avoid leaking it. */
> -        while (cfg->nhugetlbfs) {
> -            cfg->nhugetlbfs--;
> -            VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
> -        }
> -        VIR_FREE(cfg->hugetlbfs);
> -
> -        cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
> -        if (hugetlbfs[0] &&
> -            VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0)
> -            goto cleanup;
> -
> -        for (i = 0; hugetlbfs[i] != NULL; i++) {
> -            if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i],
> -                                                 hugetlbfs[i], i != 0) < 0)
> -                goto cleanup;
> -        }
> -    }
> -
> -    if (virConfGetValueString(conf, "bridge_helper", &cfg->bridgeHelperName) < 0)
> -        goto cleanup;
> -
> -    if (virConfGetValueString(conf, "pr_helper", &cfg->prHelperName) < 0)
>          goto cleanup;

This makes a double "goto cleanup;" which you fix in the next patch, but
causes this patch to fail to compile...

With all that this patch is good.

John

[...]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 14/23] qemu_conf: split out virQEMUDriverConfigLoadProcessEntry
Posted by Ján Tomko 7 years ago
On Thu, Jan 17, 2019 at 09:10:11AM -0500, John Ferlan wrote:
>On 1/15/19 8:23 AM, Ján Tomko wrote:
>> @@ -894,79 +981,10 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
>>          goto cleanup;
>>      if (virConfGetValueBool(conf, "auto_start_bypass_cache", &cfg->autoStartBypassCache) < 0)
>>          goto cleanup;
>> -
>> -    if (virConfGetValueStringList(conf, "hugetlbfs_mount", true,
>> -                                  &hugetlbfs) < 0)
>> -        goto cleanup;
>> -    if (hugetlbfs) {
>> -        /* There already might be something autodetected. Avoid leaking it. */
>> -        while (cfg->nhugetlbfs) {
>> -            cfg->nhugetlbfs--;
>> -            VIR_FREE(cfg->hugetlbfs[cfg->nhugetlbfs].mnt_dir);
>> -        }
>> -        VIR_FREE(cfg->hugetlbfs);
>> -
>> -        cfg->nhugetlbfs = virStringListLength((const char *const *)hugetlbfs);
>> -        if (hugetlbfs[0] &&
>> -            VIR_ALLOC_N(cfg->hugetlbfs, cfg->nhugetlbfs) < 0)
>> -            goto cleanup;
>> -
>> -        for (i = 0; hugetlbfs[i] != NULL; i++) {
>> -            if (virQEMUDriverConfigHugeTLBFSInit(&cfg->hugetlbfs[i],
>> -                                                 hugetlbfs[i], i != 0) < 0)
>> -                goto cleanup;
>> -        }
>> -    }
>> -
>> -    if (virConfGetValueString(conf, "bridge_helper", &cfg->bridgeHelperName) < 0)
>> -        goto cleanup;
>> -
>> -    if (virConfGetValueString(conf, "pr_helper", &cfg->prHelperName) < 0)
>>          goto cleanup;
>
>This makes a double "goto cleanup;" which you fix in the next patch, but
>causes this patch to fail to compile...
>

Fun, clang does not mind at all.

I found another occurrence in a later patch.

Jano

>With all that this patch is good.
>
>John
>
>[...]
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list