[PATCH 31/41] cpu: Make x86ModelFromCPU easier to read

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

 



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

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 670b02e..914352d 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1019,21 +1019,28 @@ x86ModelFromCPU(const virCPUDef *cpu,
     virCPUx86ModelPtr model = NULL;
     size_t i;
 
+    /* host CPU only contains required features; requesting other features
+     * just returns an empty model
+     */
+    if (cpu->type == VIR_CPU_TYPE_HOST &&
+        policy != VIR_CPU_FEATURE_REQUIRE)
+        return x86ModelNew();
+
     if (policy == VIR_CPU_FEATURE_REQUIRE) {
         if (!(model = x86ModelFind(map, cpu->model))) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Unknown CPU model %s"), cpu->model);
-            goto error;
+            return NULL;
         }
 
-        if (!(model = x86ModelCopy(model)))
-            goto error;
-    } else if (!(model = x86ModelNew())) {
-        goto error;
-    } else if (cpu->type == VIR_CPU_TYPE_HOST) {
-        return model;
+        model = x86ModelCopy(model);
+    } else {
+        model = x86ModelNew();
     }
 
+    if (!model)
+        return NULL;
+
     for (i = 0; i < cpu->nfeatures; i++) {
         virCPUx86FeaturePtr feature;
 
-- 
2.9.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]