[libvirt] [PATCHv1 1/7] qemu_monitor_json: Properties optional in QMP JSON for CPUModelInfo

Collin Walling walling at linux.ibm.com
Mon May 7 14:41:01 UTC 2018


I'd recommend including this patch with your other qemu_monitor_json patch series.

Let's wait until we see Jiri's patches before moving forward with discussion.

On 05/05/2018 01:48 PM, Chris Venteicher wrote:
> Allow case where props not present in JSON for CPUModelInfo.
> Check for NULL input.
> Update comments to show JSON examples for more typical S390x usecase.
> ---
>  src/qemu/qemu_monitor_json.c | 34 +++++++++++++++-------------------
>  1 file changed, 15 insertions(+), 19 deletions(-)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index cb17cf53bc..92db267353 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -5358,7 +5358,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
>  }
>  
>  
> -/* model_json: {"name": "IvyBridge", "props": {}}
> +/* model_json: {"name": "z13-base", "props": {}}
>   */
>  static virJSONValuePtr
>  qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model)
> @@ -5367,6 +5367,9 @@ qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model)
>      virJSONValuePtr model_json = NULL;
>      size_t i;
>  
> +    if (!model)
> +        goto cleanup;
> +
>      if (!(cpu_props = virJSONValueNewObject()))
>          goto cleanup;
>  
> @@ -5408,7 +5411,7 @@ qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model)
>  }
>  
>  
> -/* model_json: {"name": "IvyBridge", "props": {}}
> +/* model_json: {"name": "z13-base", "props": {}}
>   */
>  static qemuMonitorCPUModelInfoPtr
>  qemuMonitorJSONBuildCPUModelInfoFromJSON(virJSONValuePtr cpu_model)
> @@ -5424,26 +5427,22 @@ qemuMonitorJSONBuildCPUModelInfoFromJSON(virJSONValuePtr cpu_model)
>          goto cleanup;
>      }
>  
> -    if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
> -        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                       _("Parsed JSON reply missing 'props'"));
> -        goto cleanup;
> -    }
> -
>      if (VIR_ALLOC(machine_model) < 0)
>          goto cleanup;
>  
>      if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
>          goto cleanup;
>  
> -    if (VIR_ALLOC_N(machine_model->props,
> -                    virJSONValueObjectKeysNumber(cpu_props)) < 0)
> -        goto cleanup;
> +    if ((cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
> +        if (VIR_ALLOC_N(machine_model->props,
> +                        virJSONValueObjectKeysNumber(cpu_props)) < 0)
> +            goto cleanup;
>  
> -    if (virJSONValueObjectForeachKeyValue(cpu_props,
> -                                          qemuMonitorJSONParseCPUModelProperty,
> -                                          machine_model) < 0)
> -        goto cleanup;
> +        if (virJSONValueObjectForeachKeyValue(cpu_props,
> +                                              qemuMonitorJSONParseCPUModelProperty,
> +                                              machine_model) < 0)
> +            goto cleanup;
> +    }
>  
>      VIR_STEAL_PTR(model, machine_model);
>  
> @@ -5586,11 +5585,8 @@ qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
>      if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
>          goto cleanup;
>  
> -    /* Urgh, some QEMU architectures have query-cpu-model-baseline
> -     * command but return 'GenericError' with string "Not supported",
> -     * instead of simply omitting the command entirely
> -     */
>      if (qemuMonitorJSONHasError(reply, "GenericError")) {
> +        /* QEMU does not support query-cpu-model-baseline or cpu model */
>          ret = 0;
>          goto cleanup;
>      }
> 


-- 
Respectfully,
- Collin Walling




More information about the libvir-list mailing list