]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_monitor: use cpu def instead of char for expansion
authorCollin Walling <walling@linux.ibm.com>
Thu, 19 Sep 2019 20:24:54 +0000 (16:24 -0400)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 7 Oct 2019 08:09:49 +0000 (10:09 +0200)
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>
src/qemu/qemu_capabilities.c
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
tests/cputest.c

index 3b50576a2b1d1eddc5f0154e4e15e67a81eb7383..c59fe7e92b2a49db9533f67fcd6defced980aa50 100644 (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;
 }
index 2d46f5cfa7cf0813722488531b20acd9288e5f21..c05d935504e1f75422978bba3cd55f044a38fa7b 100644 (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);
 }
 
index b42bdfbea8d09a02fe8e203966a1c76669a5b587..13d85ee8e990232880cca8a094414fc4b2bf88ce 100644 (file)
@@ -1146,7 +1146,7 @@ typedef enum {
 
 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
                                     qemuMonitorCPUModelExpansionType type,
-                                    const char *model_name,
+                                    virCPUDefPtr cpu,
                                     bool migratable,
                                     qemuMonitorCPUModelInfoPtr *model_info);
 
index 1fe8c68dcfb8b2004f070511e58042db53fc0b81..d09e4d3491ff49285dcf4dfec83202f058be7eb3 100644 (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:
index b756a86350da906b55cb7fca025501d4cdde4a93..6e6da9d456b60d62d7bdd0863e7440d1368196c2 100644 (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);
index 7037bcc8bd6b6b5ad4948af09384597c3164f430..3c17ed4a16fc487da9d8a56dc003c50dc39b0e51 100644 (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;