Some older s390 CPU models (e.g. z900) will not report props as a
response from query-cpu-model-expansion. As such, we should make the
props field optional when parsing the return data from the QMP response.
Signed-off-by: Collin Walling <walling(a)linux.ibm.com>
---
src/qemu/qemu_capabilities.c | 10 ++++++++--
src/qemu/qemu_monitor.c | 4 +++-
src/qemu/qemu_monitor.h | 1 +
src/qemu/qemu_monitor_json.c | 24 ++++++++++++++++--------
src/qemu/qemu_monitor_json.h | 3 ++-
tests/cputest.c | 6 +++++-
6 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index bc0ac3d..3020530 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2500,6 +2500,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
virCPUDefPtr cpu;
qemuMonitorCPUModelExpansionType type;
virDomainVirtType virtType;
+ bool fail_no_props = true;
int ret = -1;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
@@ -2529,12 +2530,17 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
else
type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
- if (qemuMonitorGetCPUModelExpansion(mon, type, cpu, true, &modelInfo) < 0)
+ /* Older s390 models do not report a feature set */
+ if (ARCH_IS_S390(qemuCaps->arch))
+ fail_no_props = false;
+
+ if (qemuMonitorGetCPUModelExpansion(mon, type, cpu, true, fail_no_props,
+ &modelInfo) < 0)
goto cleanup;
/* Try to check migratability of each feature. */
if (modelInfo &&
- qemuMonitorGetCPUModelExpansion(mon, type, cpu, false,
+ qemuMonitorGetCPUModelExpansion(mon, type, cpu, false, fail_no_props,
&nonMigratable) < 0)
goto cleanup;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7b454c2..6bda620 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3718,6 +3718,7 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
+ bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info)
{
VIR_DEBUG("type=%d cpu=%p migratable=%d", type, cpu, migratable);
@@ -3725,7 +3726,8 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
QEMU_CHECK_MONITOR(mon);
return qemuMonitorJSONGetCPUModelExpansion(mon, type, cpu,
- migratable, model_info);
+ migratable, fail_no_props,
+ model_info);
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 672b4f9..c9cb3bd 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1159,6 +1159,7 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
+ bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info);
void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 77113c0..ddcf425 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5833,6 +5833,7 @@ qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu,
static int
qemuMonitorJSONParseCPUModelData(virJSONValuePtr data,
+ bool fail_no_props,
virJSONValuePtr *cpu_model,
virJSONValuePtr *cpu_props,
const char **cpu_name)
@@ -5849,7 +5850,8 @@ qemuMonitorJSONParseCPUModelData(virJSONValuePtr data,
return -1;
}
- if (!(*cpu_props = virJSONValueObjectGetObject(*cpu_model, "props"))) {
+ if (!(*cpu_props = virJSONValueObjectGetObject(*cpu_model, "props"))
&&
+ fail_no_props) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-cpu-model-expansion reply data was missing
'props'"));
return -1;
@@ -5873,13 +5875,17 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name,
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) {
+ size_t nprops = virJSONValueObjectKeysNumber(cpu_props);
- if (virJSONValueObjectForeachKeyValue(cpu_props,
- qemuMonitorJSONParseCPUModelProperty,
- machine_model) < 0)
- goto cleanup;
+ if (VIR_ALLOC_N(machine_model->props, nprops) < 0)
+ goto cleanup;
+
+ if (virJSONValueObjectForeachKeyValue(cpu_props,
+ qemuMonitorJSONParseCPUModelProperty,
+ machine_model) < 0)
+ goto cleanup;
+ }
VIR_STEAL_PTR(*model_info, machine_model);
ret = 0;
@@ -5895,6 +5901,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
+ bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info)
{
VIR_AUTOPTR(virJSONValue) model = NULL;
@@ -5945,7 +5952,8 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
data = virJSONValueObjectGetObject(reply, "return");
if (qemuMonitorJSONParseCPUModelData(data,
- &cpu_model, &cpu_props, &cpu_name)
< 0)
+ fail_no_props, &cpu_model, &cpu_props,
+ &cpu_name) < 0)
return -1;
/* QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL requests "full" expansion
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index bdccd36..682710f 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -392,8 +392,9 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
+ bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info)
- ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
+ ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(6);
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
char ***commands)
diff --git a/tests/cputest.c b/tests/cputest.c
index 3c17ed4..e3937c6 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -482,6 +482,7 @@ cpuTestMakeQEMUCaps(const struct data *data)
qemuMonitorTestPtr testMon = NULL;
qemuMonitorCPUModelInfoPtr model = NULL;
virCPUDefPtr cpu = NULL;
+ bool fail_no_props = true;
char *json = NULL;
if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
@@ -494,9 +495,12 @@ cpuTestMakeQEMUCaps(const struct data *data)
if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, "host") < 0)
goto cleanup;
+ if (ARCH_IS_S390(data->arch))
+ fail_no_props = false;
+
if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
- cpu, true, &model) < 0)
+ cpu, true, fail_no_props, &model) < 0)
goto error;
if (!(qemuCaps = virQEMUCapsNew()))
--
2.7.4