[libvirt PATCH v2 05/14] Introduce virCPUGetVendorForModel and use it in QEMU driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So far QEMU driver does not get CPU model vendor from QEMU directly and
it has to ask the CPU driver for the info stored in CPU map.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>
---

Notes:
    Version 2:
    - no change

 src/cpu/cpu.c                | 25 +++++++++++++++++++++++++
 src/cpu/cpu.h                |  8 ++++++++
 src/libvirt_private.syms     |  1 +
 src/qemu/qemu_capabilities.c | 18 +++++++++++++-----
 4 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index d97ef5e873..7f3caf7a27 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -923,6 +923,31 @@ virCPUGetModels(virArch arch, char ***models)
 }
 
 
+/** virCPUGetVendorForModel:
+ *
+ * @arch: CPU architecture
+ * @model: CPU model to be checked
+ *
+ * Returns @model's vendor or NULL if the vendor is unknown.
+ */
+const char *
+virCPUGetVendorForModel(virArch arch,
+                        const char *model)
+{
+    struct cpuArchDriver *driver;
+
+    VIR_DEBUG("arch=%s", virArchToString(arch));
+
+    if (!(driver = cpuGetSubDriver(arch)))
+        return NULL;
+
+    if (!driver->getVendorForModel)
+        return NULL;
+
+    return driver->getVendorForModel(model);
+}
+
+
 /**
  * virCPUTranslate:
  *
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 41a62ce486..a4cdb37f03 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -105,6 +105,9 @@ typedef virCPUData *
 typedef int
 (*virCPUArchGetModels)(char ***models);
 
+typedef const char *
+(*virCPUArchGetVendorForModel)(const char *model);
+
 typedef int
 (*virCPUArchTranslate)(virCPUDef *cpu,
                        virDomainCapsCPUModels *models);
@@ -150,6 +153,7 @@ struct cpuArchDriver {
     virCPUArchDataFormat dataFormat;
     virCPUArchDataParse dataParse;
     virCPUArchGetModels getModels;
+    virCPUArchGetVendorForModel getVendorForModel;
     virCPUArchTranslate translate;
     virCPUArchConvertLegacy convertLegacy;
     virCPUArchExpandFeatures expandFeatures;
@@ -262,6 +266,10 @@ virCPUModelIsAllowed(const char *model,
 int
 virCPUGetModels(virArch arch, char ***models);
 
+const char *
+virCPUGetVendorForModel(virArch arch,
+                        const char *model);
+
 int
 virCPUTranslate(virArch arch,
                 virCPUDef *cpu,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 00cb07709d..9cf5c0de7c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1500,6 +1500,7 @@ virCPUExpandFeatures;
 virCPUGetHost;
 virCPUGetHostIsSupported;
 virCPUGetModels;
+virCPUGetVendorForModel;
 virCPUProbeHost;
 virCPUTranslate;
 virCPUUpdate;
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 5af5de8fc5..ccd274b80d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2175,9 +2175,11 @@ virQEMUCapsAddCPUDefinitions(virQEMUCaps *qemuCaps,
 
 
 static virDomainCapsCPUModels *
-virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
+virQEMUCapsCPUDefsToModels(virArch arch,
+                           qemuMonitorCPUDefs *defs,
                            const char **modelAllowed,
-                           const char **modelForbidden)
+                           const char **modelForbidden,
+                           bool vendors)
 {
     virDomainCapsCPUModels *cpuModels = NULL;
     size_t i;
@@ -2187,6 +2189,7 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
 
     for (i = 0; i < defs->ncpus; i++) {
         qemuMonitorCPUDefInfo *cpu = defs->cpus + i;
+        char *vendor = NULL;
 
         if (modelAllowed && !g_strv_contains(modelAllowed, cpu->name))
             continue;
@@ -2194,8 +2197,11 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefs *defs,
         if (modelForbidden && g_strv_contains(modelForbidden, cpu->name))
             continue;
 
+        if (vendors)
+            vendor = g_strdup(virCPUGetVendorForModel(arch, cpu->name));
+
         virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable,
-                                  cpu->blockers, cpu->deprecated, NULL);
+                                  cpu->blockers, cpu->deprecated, vendor);
     }
 
     return cpuModels;
@@ -2213,7 +2219,8 @@ virQEMUCapsGetCPUModels(virQEMUCaps *qemuCaps,
     if (!(defs = virQEMUCapsGetAccel(qemuCaps, type)->cpuModels))
         return NULL;
 
-    return virQEMUCapsCPUDefsToModels(defs, modelAllowed, modelForbidden);
+    return virQEMUCapsCPUDefsToModels(qemuCaps->arch, defs,
+                                      modelAllowed, modelForbidden, true);
 }
 
 
@@ -2946,7 +2953,8 @@ virQEMUCapsFetchCPUModels(qemuMonitor *mon,
     if (virQEMUCapsFetchCPUDefinitions(mon, arch, &defs) < 0)
         return -1;
 
-    if (defs && !(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
+    if (defs &&
+        !(*cpuModels = virQEMUCapsCPUDefsToModels(arch, defs, NULL, NULL, false)))
         return -1;
 
     return 0;
-- 
2.38.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux