Blob Blame History Raw
From 780500abda14bb71111592254d01c973d16be320 Mon Sep 17 00:00:00 2001
Message-Id: <780500abda14bb71111592254d01c973d16be320@dist-git>
From: Jiri Denemark <jdenemar@redhat.com>
Date: Tue, 28 Jun 2016 10:51:41 +0200
Subject: [PATCH] cpu_x86: Introduce x86FeatureIsMigratable

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
(cherry picked from commit dbb14bb0f1316d92c89541fca816c91dce0dc8fb)

https://bugzilla.redhat.com/show_bug.cgi?id=1365500

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu/cpu_x86.c | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index d9646eb..7bb2bb6 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -767,6 +767,22 @@ x86FeatureFindInternal(const char *name)
 }
 
 
+static bool
+x86FeatureIsMigratable(const char *name,
+                       void *cpu_map)
+{
+    virCPUx86MapPtr map = cpu_map;
+    size_t i;
+
+    for (i = 0; i < map->nblockers; i++) {
+        if (STREQ(name, map->migrate_blockers[i]->name))
+            return false;
+    }
+
+    return true;
+}
+
+
 static char *
 x86FeatureNames(virCPUx86MapPtr map,
                 const char *separator,
@@ -1801,14 +1817,10 @@ x86Decode(virCPUDefPtr cpu,
      * features directly */
     if (flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE) {
         for (i = 0; i < cpuModel->nfeatures; i++) {
-            size_t j;
-            for (j = 0; j < map->nblockers; j++) {
-                if (STREQ(map->migrate_blockers[j]->name,
-                          cpuModel->features[i].name)) {
-                    VIR_FREE(cpuModel->features[i].name);
-                    VIR_DELETE_ELEMENT_INPLACE(cpuModel->features, i,
-                                               cpuModel->nfeatures);
-                }
+            if (!x86FeatureIsMigratable(cpuModel->features[i].name, map)) {
+                VIR_FREE(cpuModel->features[i].name);
+                VIR_DELETE_ELEMENT_INPLACE(cpuModel->features, i,
+                                           cpuModel->nfeatures);
             }
         }
     }
@@ -2531,12 +2543,9 @@ x86UpdateHostModel(virCPUDefPtr guest,
      * Note: this only works as long as no CPU model contains non-migratable
      * features directly */
     for (i = 0; i < guest->nfeatures; i++) {
-        size_t j;
-        for (j = 0; j < map->nblockers; j++) {
-            if (STREQ(map->migrate_blockers[j]->name, guest->features[i].name)) {
-                VIR_FREE(guest->features[i].name);
-                VIR_DELETE_ELEMENT_INPLACE(guest->features, i, guest->nfeatures);
-            }
+        if (!x86FeatureIsMigratable(guest->features[i].name, map)) {
+            VIR_FREE(guest->features[i].name);
+            VIR_DELETE_ELEMENT_INPLACE(guest->features, i, guest->nfeatures);
         }
     }
     for (i = 0; !passthrough && i < oldguest->nfeatures; i++) {
-- 
2.9.2