qemu_monitor: use cpu def instead of char for expansion

When expanding a CPU model via query-cpu-model-expansion, any features
that were a part of the original model are discarded. For exmaple,
when expanding modelA with features f1, f2, a full expansion may reveal
feature f3, but the expanded model will not include f1 or f2.

Let's pass a virCPUDefPtr to the expansion function in preparation for
taking features into consideration.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Message-Id: <1568924706-2311-4-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:54 -04:00 committed by Jiri Denemark
parent 0a0be9b34d
commit 67a4dcc151
6 changed files with 22 additions and 13 deletions

View File

@ -2503,6 +2503,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
qemuMonitorCPUModelInfoPtr nonMigratable = NULL;
virHashTablePtr hash = NULL;
const char *model;
virCPUDefPtr cpu;
qemuMonitorCPUModelExpansionType type;
virDomainVirtType virtType;
int ret = -1;
@ -2518,6 +2519,9 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
model = "host";
}
if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, model) < 0)
goto cleanup;
/* Some x86_64 features defined in cpu_map.xml use spelling which differ
* from the one preferred by QEMU. Static expansion would give us only the
* preferred spelling. With new QEMU we always use the QEMU's canonical
@ -2531,12 +2535,12 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
else
type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
if (qemuMonitorGetCPUModelExpansion(mon, type, model, true, &modelInfo) < 0)
if (qemuMonitorGetCPUModelExpansion(mon, type, cpu, true, &modelInfo) < 0)
goto cleanup;
/* Try to check migratability of each feature. */
if (modelInfo &&
qemuMonitorGetCPUModelExpansion(mon, type, model, false,
qemuMonitorGetCPUModelExpansion(mon, type, cpu, false,
&nonMigratable) < 0)
goto cleanup;
@ -2580,6 +2584,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
virHashFree(hash);
qemuMonitorCPUModelInfoFree(nonMigratable);
qemuMonitorCPUModelInfoFree(modelInfo);
virCPUDefFree(cpu);
return ret;
}

View File

@ -3546,16 +3546,15 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
int
qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
const char *model_name,
virCPUDefPtr cpu,
bool migratable,
qemuMonitorCPUModelInfoPtr *model_info)
{
VIR_DEBUG("type=%d model_name=%s migratable=%d",
type, model_name, migratable);
VIR_DEBUG("type=%d cpu=%p migratable=%d", type, cpu, migratable);
QEMU_CHECK_MONITOR(mon);
return qemuMonitorJSONGetCPUModelExpansion(mon, type, model_name,
return qemuMonitorJSONGetCPUModelExpansion(mon, type, cpu,
migratable, model_info);
}

View File

@ -1146,7 +1146,7 @@ typedef enum {
int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
const char *model_name,
virCPUDefPtr cpu,
bool migratable,
qemuMonitorCPUModelInfoPtr *model_info);

View File

@ -5685,7 +5685,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
static virJSONValuePtr
qemuMonitorJSONMakeCPUModel(const char *model_name,
qemuMonitorJSONMakeCPUModel(virCPUDefPtr cpu,
bool migratable)
{
virJSONValuePtr model = NULL;
@ -5694,7 +5694,7 @@ qemuMonitorJSONMakeCPUModel(const char *model_name,
if (!(model = virJSONValueNewObject()))
goto error;
if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
if (virJSONValueObjectAppendString(model, "name", cpu->model) < 0)
goto error;
if (!migratable) {
@ -5776,7 +5776,7 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name,
int
qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
const char *model_name,
virCPUDefPtr cpu,
bool migratable,
qemuMonitorCPUModelInfoPtr *model_info)
{
@ -5791,7 +5791,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
*model_info = NULL;
if (!(model = qemuMonitorJSONMakeCPUModel(model_name, migratable)))
if (!(model = qemuMonitorJSONMakeCPUModel(cpu, migratable)))
return -1;
retry:

View File

@ -381,7 +381,7 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
qemuMonitorCPUModelExpansionType type,
const char *model_name,
virCPUDefPtr cpu,
bool migratable,
qemuMonitorCPUModelInfoPtr *model_info)
ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);

View File

@ -481,6 +481,7 @@ cpuTestMakeQEMUCaps(const struct data *data)
virQEMUCapsPtr qemuCaps = NULL;
qemuMonitorTestPtr testMon = NULL;
qemuMonitorCPUModelInfoPtr model = NULL;
virCPUDefPtr cpu = NULL;
char *json = NULL;
if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
@ -490,9 +491,12 @@ cpuTestMakeQEMUCaps(const struct data *data)
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
goto error;
if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, "host") < 0)
goto cleanup;
if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
"host", true, &model) < 0)
cpu, true, &model) < 0)
goto error;
if (!(qemuCaps = virQEMUCapsNew()))
@ -515,6 +519,7 @@ cpuTestMakeQEMUCaps(const struct data *data)
cleanup:
qemuMonitorCPUModelInfoFree(model);
qemuMonitorTestFree(testMon);
virCPUDefFree(cpu);
VIR_FREE(json);
return qemuCaps;