]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Filter models in virQEMUCapsGetCPUDefinitions
authorJiri Denemark <jdenemar@redhat.com>
Fri, 20 Sep 2019 20:48:13 +0000 (22:48 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 20 Nov 2019 16:22:05 +0000 (17:22 +0100)
Some callers of virQEMUCapsGetCPUDefinitions will need to filter the
returned list of CPU models. Let's add the filtering parameters directly
to virQEMUCapsGetCPUDefinitions to avoid copying the CPU models list
twice.

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

index 6e5d894a364c2926e65ba84ab247e0b633e1c08f..65260c77dfd7a56fe677657b06249a25af971039 100644 (file)
@@ -1883,7 +1883,9 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
 
 virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
-                             virDomainVirtType type)
+                             virDomainVirtType type,
+                             const char **modelWhitelist,
+                             const char **modelBlacklist)
 {
     virDomainCapsCPUModelsPtr cpuModels;
 
@@ -1895,6 +1897,9 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
     if (!cpuModels)
         return NULL;
 
+    if (modelWhitelist || modelBlacklist)
+        return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, modelBlacklist);
+
     return virDomainCapsCPUModelsCopy(cpuModels);
 }
 
@@ -3132,7 +3137,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
     if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
         goto cleanup;
 
-    cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+    cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
 
     if (cpuDecode(cpu, data, cpuModels) < 0)
         goto cleanup;
@@ -3221,7 +3226,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 
         VIR_DEBUG("No host CPU model info from QEMU; probing host CPU directly");
 
-        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
         hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
 
         if (!hostCPU ||
index aa593396ce6e025acb28d008cbb8695bb1a5c11a..d621d1fcfe76d23aa3d8a6d10987a6fbda36eb35 100644 (file)
@@ -573,7 +573,9 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
                                  size_t count,
                                  virDomainCapsCPUUsable usable);
 virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
-                                                       virDomainVirtType type);
+                                                       virDomainVirtType type,
+                                                       const char **modelWhitelist,
+                                                       const char **modelBlacklist);
 virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
                                                          virArch arch);
 
index f5e3671c2b7f9b8a3a4188ebcaa016997af8738d..0a748b10a2dda49a81cb0adc26b92ab424fc999e 100644 (file)
@@ -13710,7 +13710,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
     if (!qemuCaps)
         goto cleanup;
 
-    if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) ||
+    if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype, NULL, NULL)) ||
         cpuModels->nmodels == 0) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("QEMU '%s' does not support any CPU models for "
index 148d49803510afca5311a3cdc41b2dcf5cdfe6bc..55595aa73a69b1a9889971abbd289fb0834de87a 100644 (file)
@@ -6054,7 +6054,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
                                                  VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
             return -1;
 
-        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
+        cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, NULL, NULL);
 
         if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
             return -1;
index b8ec76d2feb3ec8bee2a67eb57d147997b7ddf7c..21d95e9e289d3d2f7ffc63571f58f4783dc381d8 100644 (file)
@@ -542,7 +542,7 @@ cpuTestGetCPUModels(const struct data *data,
     if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
         return -1;
 
-    *models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
+    *models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM, NULL, NULL);
 
     virObjectUnref(qemuCaps);