]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions
authorJiri Denemark <jdenemar@redhat.com>
Fri, 20 Sep 2019 20:41:34 +0000 (22:41 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 20 Nov 2019 16:22:05 +0000 (17:22 +0100)
Rather than returning a direct pointer the list stored in qemuCaps the
function now creates a new copy of the CPU models list.

The main purpose of this seemingly useless change is to update callers
to free the result returned by virQEMUCapsGetCPUDefinitions because the
internals of this function will change significantly in the following
patches.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_capabilities.h
src/qemu/qemu_capabilities.c
src/qemu/qemu_driver.c
src/qemu/qemu_process.c
tests/cputest.c

index a9bf4a8d3f033ef6d51176f221587edf51af3144..6ecabc6e77616319aca2cc2228640efb4df9952f 100644 (file)
@@ -139,6 +139,8 @@ struct _virDomainCapsCPUModels {
     virDomainCapsCPUModelPtr models;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCapsCPUModels, virObjectUnref);
+
 typedef struct _virDomainCapsCPU virDomainCapsCPU;
 typedef virDomainCapsCPU *virDomainCapsCPUPtr;
 struct _virDomainCapsCPU {
index 7c30768379cbfe3b8308d98fd78e28eb95522e3f..6e5d894a364c2926e65ba84ab247e0b633e1c08f 100644 (file)
@@ -1885,10 +1885,17 @@ virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
                              virDomainVirtType type)
 {
+    virDomainCapsCPUModelsPtr cpuModels;
+
     if (type == VIR_DOMAIN_VIRT_KVM)
-        return qemuCaps->kvmCPUModels;
+        cpuModels = qemuCaps->kvmCPUModels;
     else
-        return qemuCaps->tcgCPUModels;
+        cpuModels = qemuCaps->tcgCPUModels;
+
+    if (!cpuModels)
+        return NULL;
+
+    return virDomainCapsCPUModelsCopy(cpuModels);
 }
 
 
@@ -3115,6 +3122,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
                            virCPUDefPtr cpu,
                            bool migratable)
 {
+    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
     virCPUDataPtr data = NULL;
     int ret = -1;
 
@@ -3124,7 +3132,9 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
     if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
         goto cleanup;
 
-    if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0)
+    cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+
+    if (cpuDecode(cpu, data, cpuModels) < 0)
         goto cleanup;
 
     ret = 0;
@@ -3207,10 +3217,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
     if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) {
         goto error;
     } else if (rc == 1) {
+        g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
+
         VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly");
 
-        hostCPU = virQEMUCapsProbeHostCPU(hostArch,
-                                          virQEMUCapsGetCPUDefinitions(qemuCaps, type));
+        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+        hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
+
         if (!hostCPU ||
             virCPUDefCopyModelFilter(cpu, hostCPU, true,
                                      virQEMUCapsCPUFilterFeatures,
index dc14ec86a3b7c142ced321305462c0535b1d0162..f5e3671c2b7f9b8a3a4188ebcaa016997af8738d 100644 (file)
@@ -13684,7 +13684,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
     g_autoptr(virQEMUCaps) qemuCaps = NULL;
     virArch arch;
     virDomainVirtType virttype;
-    virDomainCapsCPUModelsPtr cpuModels;
+    g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
     bool migratable;
     virCPUDefPtr cpu = NULL;
     char *cpustr = NULL;
index 31d797e14380f0e493e37b3048caab34e7c7606f..148d49803510afca5311a3cdc41b2dcf5cdfe6bc 100644 (file)
@@ -6040,6 +6040,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
 
     /* nothing to update for host-passthrough */
     if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
+        g_autoptr(virDomainCapsCPUModels) cpuModels = NULL;
+
         if (def->cpu->check == VIR_CPU_CHECK_PARTIAL &&
             virCPUCompare(caps->host.arch,
                           virQEMUCapsGetHostModel(qemuCaps, def->virtType,
@@ -6052,8 +6054,9 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
                                                  VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
             return -1;
 
-        if (virCPUTranslate(def->os.arch, def->cpu,
-                            virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType)) < 0)
+        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
+
+        if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
             return -1;
 
         def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
index 18c8e8b09cb40ba5f7d4f92e109cca4205ee6a80..b8ec76d2feb3ec8bee2a67eb57d147997b7ddf7c 100644 (file)
@@ -543,7 +543,6 @@ cpuTestGetCPUModels(const struct data *data,
         return -1;
 
     *models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
-    virObjectRef(*models);
 
     virObjectUnref(qemuCaps);