[PATCH v2 1/5] qemuMonitorJSONGetCPUModelExpansion: refactor parsing functions

Collin Walling posted 5 patches 1 month ago
There is a newer version of this series
[PATCH v2 1/5] qemuMonitorJSONGetCPUModelExpansion: refactor parsing functions
Posted by Collin Walling 1 month ago
Refactor the CPU Model parsing functions within
qemuMonitorJSONGetCPUModelExpansion.  The new functions,
qemuMonitorJSONParseCPUModelExpansionData and
qemuMonitorJSONParseCPUModelExpansion invoke the functions they
replace and leave room for a subsequent patch to handle parsing the
(optional) deprecated_props field resulting from the command.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
---
 src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 1b4288b744..fa8c5b1aea 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5100,6 +5100,37 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name,
 }
 
 
+static int
+qemuMonitorJSONParseCPUModelExpansionData(virJSONValue *data,
+                                          bool fail_no_props,
+                                          virJSONValue **cpu_model,
+                                          virJSONValue **cpu_props,
+                                          const char **cpu_name)
+{
+    if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-expansion",
+                                         fail_no_props, cpu_model, cpu_props,
+                                         cpu_name) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+qemuMonitorJSONParseCPUModelExpansion(const char *cpu_name,
+                                      virJSONValue *cpu_props,
+                                      qemuMonitorCPUModelInfo **model_info)
+{
+    g_autoptr(qemuMonitorCPUModelInfo) expanded_model = NULL;
+
+    if (qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, &expanded_model) < 0)
+        return -1;
+
+    *model_info = g_steal_pointer(&expanded_model);
+    return 0;
+}
+
+
 static int
 qemuMonitorJSONQueryCPUModelExpansionOne(qemuMonitor *mon,
                                          qemuMonitorCPUModelExpansionType type,
@@ -5170,9 +5201,9 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitor *mon,
     if ((rc = qemuMonitorJSONQueryCPUModelExpansionOne(mon, type, &model, &data)) <= 0)
         return rc;
 
-    if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-expansion",
-                                         fail_no_props, &cpu_model, &cpu_props,
-                                         &cpu_name) < 0)
+    if (qemuMonitorJSONParseCPUModelExpansionData(data, fail_no_props,
+                                                  &cpu_model, &cpu_props,
+                                                  &cpu_name) < 0)
         return -1;
 
     /* QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL requests "full" expansion
@@ -5188,13 +5219,14 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitor *mon,
         if ((rc = qemuMonitorJSONQueryCPUModelExpansionOne(mon, type, &fullModel, &fullData)) <= 0)
             return rc;
 
-        if (qemuMonitorJSONParseCPUModelData(fullData, "query-cpu-model-expansion",
-                                             fail_no_props, &cpu_model, &cpu_props,
-                                             &cpu_name) < 0)
+        if (qemuMonitorJSONParseCPUModelExpansionData(fullData, fail_no_props,
+                                                      &cpu_model, &cpu_props,
+                                                      &cpu_name) < 0)
             return -1;
     }
 
-    return qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, model_info);
+    return qemuMonitorJSONParseCPUModelExpansion(cpu_name, cpu_props,
+                                                 model_info);
 }
 
 
-- 
2.45.1
Re: [PATCH v2 1/5] qemuMonitorJSONGetCPUModelExpansion: refactor parsing functions
Posted by Jiri Denemark 4 weeks, 1 day ago
On Mon, Nov 25, 2024 at 14:46:35 -0500, Collin Walling wrote:
> Refactor the CPU Model parsing functions within
> qemuMonitorJSONGetCPUModelExpansion.  The new functions,
> qemuMonitorJSONParseCPUModelExpansionData and
> qemuMonitorJSONParseCPUModelExpansion invoke the functions they
> replace and leave room for a subsequent patch to handle parsing the
> (optional) deprecated_props field resulting from the command.
> 
> Signed-off-by: Collin Walling <walling@linux.ibm.com>
> ---
>  src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++------
>  1 file changed, 39 insertions(+), 7 deletions(-)

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Re: [PATCH v2 1/5] qemuMonitorJSONGetCPUModelExpansion: refactor parsing functions
Posted by Boris Fiuczynski 4 weeks, 1 day ago
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>

On 11/25/24 20:46, Collin Walling wrote:
> Refactor the CPU Model parsing functions within
> qemuMonitorJSONGetCPUModelExpansion.  The new functions,
> qemuMonitorJSONParseCPUModelExpansionData and
> qemuMonitorJSONParseCPUModelExpansion invoke the functions they
> replace and leave room for a subsequent patch to handle parsing the
> (optional) deprecated_props field resulting from the command.
> 
> Signed-off-by: Collin Walling <walling@linux.ibm.com>
> ---
>   src/qemu/qemu_monitor_json.c | 46 ++++++++++++++++++++++++++++++------
>   1 file changed, 39 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 1b4288b744..fa8c5b1aea 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5100,6 +5100,37 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name,
>   }
>   
>   
> +static int
> +qemuMonitorJSONParseCPUModelExpansionData(virJSONValue *data,
> +                                          bool fail_no_props,
> +                                          virJSONValue **cpu_model,
> +                                          virJSONValue **cpu_props,
> +                                          const char **cpu_name)
> +{
> +    if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-expansion",
> +                                         fail_no_props, cpu_model, cpu_props,
> +                                         cpu_name) < 0)
> +        return -1;
> +
> +    return 0;
> +}
> +
> +
> +static int
> +qemuMonitorJSONParseCPUModelExpansion(const char *cpu_name,
> +                                      virJSONValue *cpu_props,
> +                                      qemuMonitorCPUModelInfo **model_info)
> +{
> +    g_autoptr(qemuMonitorCPUModelInfo) expanded_model = NULL;
> +
> +    if (qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, &expanded_model) < 0)
> +        return -1;
> +
> +    *model_info = g_steal_pointer(&expanded_model);
> +    return 0;
> +}
> +
> +
>   static int
>   qemuMonitorJSONQueryCPUModelExpansionOne(qemuMonitor *mon,
>                                            qemuMonitorCPUModelExpansionType type,
> @@ -5170,9 +5201,9 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitor *mon,
>       if ((rc = qemuMonitorJSONQueryCPUModelExpansionOne(mon, type, &model, &data)) <= 0)
>           return rc;
>   
> -    if (qemuMonitorJSONParseCPUModelData(data, "query-cpu-model-expansion",
> -                                         fail_no_props, &cpu_model, &cpu_props,
> -                                         &cpu_name) < 0)
> +    if (qemuMonitorJSONParseCPUModelExpansionData(data, fail_no_props,
> +                                                  &cpu_model, &cpu_props,
> +                                                  &cpu_name) < 0)
>           return -1;
>   
>       /* QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL requests "full" expansion
> @@ -5188,13 +5219,14 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitor *mon,
>           if ((rc = qemuMonitorJSONQueryCPUModelExpansionOne(mon, type, &fullModel, &fullData)) <= 0)
>               return rc;
>   
> -        if (qemuMonitorJSONParseCPUModelData(fullData, "query-cpu-model-expansion",
> -                                             fail_no_props, &cpu_model, &cpu_props,
> -                                             &cpu_name) < 0)
> +        if (qemuMonitorJSONParseCPUModelExpansionData(fullData, fail_no_props,
> +                                                      &cpu_model, &cpu_props,
> +                                                      &cpu_name) < 0)
>               return -1;
>       }
>   
> -    return qemuMonitorJSONParseCPUModel(cpu_name, cpu_props, model_info);
> +    return qemuMonitorJSONParseCPUModelExpansion(cpu_name, cpu_props,
> +                                                 model_info);
>   }
>   
>   


-- 
Mit freundlichen Grüßen/Kind regards
    Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294