[libvirt PATCH 02/19] cpu: handle aliases in CPU definitions

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

 



After modifying the sync_cpu_model_i386 script to generate an alias for
versioned CPUs, we need to add the ability to handle cpu model aliases.
This involves parsing and storing the alias in the virCPUx86Model
structure and also allowing the CPU to be looked up by its alias or its
official name.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 src/cpu/cpu_x86.c | 68 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 21 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 7a7f3b409d..4d4f6a8be8 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -148,6 +148,7 @@ struct _virCPUx86Model {
     virCPUx86Signatures *signatures;
     virCPUx86Data data;
     GStrv removedFeatures;
+    char *alias;
 };
 
 typedef struct _virCPUx86Map virCPUx86Map;
@@ -1278,6 +1279,7 @@ x86ModelFree(virCPUx86Model *model)
         return;
 
     g_free(model->name);
+    g_free(model->alias);
     virCPUx86SignaturesFree(model->signatures);
     virCPUx86DataClear(&model->data);
     g_strfreev(model->removedFeatures);
@@ -1309,7 +1311,8 @@ x86ModelFind(virCPUx86Map *map,
     size_t i;
 
     for (i = 0; i < map->nmodels; i++) {
-        if (STREQ(map->models[i]->name, name))
+        if (STREQ(map->models[i]->name, name) ||
+            STREQ_NULLABLE(map->models[i]->alias, name))
             return map->models[i];
     }
 
@@ -1448,6 +1451,22 @@ x86ModelCompare(virCPUx86Model *model1,
 }
 
 
+static int
+x86ModelParseAlias(virCPUx86Model *model,
+                   xmlXPathContextPtr ctxt)
+{
+    xmlNodePtr alias_node = NULL;
+
+    if (!(alias_node = virXPathNode("./alias", ctxt)))
+        return 0;
+
+    if (!(model->alias = virXMLPropStringRequired(alias_node, "name")))
+        return -1;
+
+    return 0;
+}
+
+
 static int
 x86ModelParseDecode(virCPUx86Model *model,
                     xmlXPathContextPtr ctxt)
@@ -1665,6 +1684,9 @@ x86ModelParse(xmlXPathContextPtr ctxt,
     model = g_new0(virCPUx86Model, 1);
     model->name = g_strdup(name);
 
+    if (x86ModelParseAlias(model, ctxt) < 0)
+        return -1;
+
     if (x86ModelParseDecode(model, ctxt) < 0)
         return -1;
 
@@ -2184,26 +2206,30 @@ x86Decode(virCPUDef *cpu,
      */
     for (i = map->nmodels - 1; i >= 0; i--) {
         candidate = map->models[i];
-        if (models &&
-            !(hvModel = virDomainCapsCPUModelsGet(models, candidate->name))) {
-            if (preferred &&
-                !preferred[1] &&
-                STREQ(candidate->name, preferred[0])) {
-                if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
-                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                                   _("CPU model %1$s is not supported by hypervisor"),
-                                   preferred[0]);
-                    return -1;
-                } else {
-                    VIR_WARN("Preferred CPU model %s not allowed by"
-                             " hypervisor; closest supported model will be"
-                             " used", preferred[0]);
-                }
-            } else {
-                VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring",
-                          candidate->name);
-            }
-            continue;
+        if (models) {
+           hvModel = virDomainCapsCPUModelsGet(models, candidate->name);
+           if (!hvModel && candidate->alias)
+               hvModel = virDomainCapsCPUModelsGet(models, candidate->alias);
+           if (!hvModel) {
+               if (preferred &&
+                   !preferred[1] &&
+                   STREQ(candidate->name, preferred[0])) {
+                   if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
+                       virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                      _("CPU model %1$s is not supported by hypervisor"),
+                                      preferred[0]);
+                       return -1;
+                   } else {
+                       VIR_WARN("Preferred CPU model %s not allowed by"
+                                " hypervisor; closest supported model will be"
+                                " used", preferred[0]);
+                   }
+               } else {
+                   VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring",
+                             candidate->name);
+               }
+               continue;
+           }
         }
 
         /* Both vendor and candidate->vendor are pointers to a single list of
-- 
2.41.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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