1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

qemu_monitor: allow cpu props to be optional

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@linux.ibm.com>
Message-Id: <1568924706-2311-6-git-send-email-walling@linux.ibm.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Collin Walling 2019-09-19 16:24:56 -04:00 committed by Jiri Denemark
parent 708f48525a
commit afd222684e
6 changed files with 35 additions and 13 deletions

View File

@ -2506,6 +2506,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))
@ -2535,12 +2536,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;

View File

@ -3548,6 +3548,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);
@ -3555,7 +3556,8 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
QEMU_CHECK_MONITOR(mon);
return qemuMonitorJSONGetCPUModelExpansion(mon, type, cpu,
migratable, model_info);
migratable, fail_no_props,
model_info);
}

View File

@ -1148,6 +1148,7 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info);
void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);

View File

@ -5736,6 +5736,7 @@ qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu,
static int
qemuMonitorJSONParseCPUModelData(virJSONValuePtr data,
bool fail_no_props,
virJSONValuePtr *cpu_model,
virJSONValuePtr *cpu_props,
const char **cpu_name)
@ -5752,7 +5753,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;
@ -5776,13 +5778,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;
@ -5798,6 +5804,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
virCPUDefPtr cpu,
bool migratable,
bool fail_no_props,
qemuMonitorCPUModelInfoPtr *model_info)
{
VIR_AUTOPTR(virJSONValue) model = NULL;
@ -5848,7 +5855,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

View File

@ -383,8 +383,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)

View File

@ -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()))