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; } -- 2.14.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list