]> xenbits.xensource.com Git - libvirt.git/commitdiff
cpu: Introduce cpuModelIsAllowed internal API
authorJiri Denemark <jdenemar@redhat.com>
Wed, 19 Dec 2012 11:08:32 +0000 (12:08 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 19 Apr 2013 12:33:15 +0000 (14:33 +0200)
The API can be used to check if the model is on the supported models
list, which needs to be done in several places.

src/cpu/cpu.c
src/cpu/cpu.h
src/cpu/cpu_generic.c
src/cpu/cpu_x86.c

index 6beab5508cf9e100a186173e67335fca9e07ec5f..68125a540e27544a8efd77dd3e1280d6bce25b22 100644 (file)
@@ -442,3 +442,20 @@ cpuHasFeature(virArch arch,
 
     return driver->hasFeature(data, feature);
 }
+
+bool
+cpuModelIsAllowed(const char *model,
+                  const char **models,
+                  unsigned int nmodels)
+{
+    unsigned int i;
+
+    if (!models || !nmodels)
+        return true;
+
+    for (i = 0; i < nmodels; i++) {
+        if (models[i] && STREQ(models[i], model))
+            return true;
+    }
+    return false;
+}
index e279072da69dd3bd7c7b0d35aa3081a6b561484c..cba7149e919327632efca82d7a3e6dbdb5a548b5 100644 (file)
@@ -163,4 +163,9 @@ cpuHasFeature(virArch arch,
               const char *feature);
 
 
+bool
+cpuModelIsAllowed(const char *model,
+                  const char **models,
+                  unsigned int nmodels);
+
 #endif /* __VIR_CPU_H__ */
index 5dfa6a21a4e9551c9f954ea54cd499ac990ca3fc..9d5117f2b7fa5b0fe51e41f8a772b35c3fb67ddc 100644 (file)
@@ -123,20 +123,11 @@ genericBaseline(virCPUDefPtr *cpus,
     unsigned int count;
     unsigned int i, j;
 
-    if (models) {
-        bool found = false;
-        for (i = 0; i < nmodels; i++) {
-            if (STREQ(cpus[0]->model, models[i])) {
-                found = true;
-                break;
-            }
-        }
-        if (!found) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("CPU model '%s' is not support by hypervisor"),
-                           cpus[0]->model);
-            goto error;
-        }
+    if (!cpuModelIsAllowed(cpus[0]->model, models, nmodels)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("CPU model %s is not supported by hypervisor"),
+                       cpus[0]->model);
+        goto error;
     }
 
     if (VIR_ALLOC(cpu) < 0 ||
index c750afd9a607eb0714325a401fc110d9b27915a7..4940c23703982bcde0d31e1d53450c0c27d7d20e 100644 (file)
@@ -1317,16 +1317,7 @@ x86Decode(virCPUDefPtr cpu,
 
     candidate = map->models;
     while (candidate != NULL) {
-        bool allowed = (models == NULL);
-
-        for (i = 0; i < nmodels; i++) {
-            if (models && models[i] && STREQ(models[i], candidate->name)) {
-                allowed = true;
-                break;
-            }
-        }
-
-        if (!allowed) {
+        if (!cpuModelIsAllowed(candidate->name, models, nmodels)) {
             if (preferred && STREQ(candidate->name, preferred)) {
                 if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) {
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,