]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Make x86ModelFromCPU easier to read
authorJiri Denemark <jdenemar@redhat.com>
Sat, 18 Jun 2016 08:54:50 +0000 (10:54 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 22 Sep 2016 13:40:09 +0000 (15:40 +0200)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/cpu/cpu_x86.c

index ee5b57d6fcdf45eec1a37e85db2768b0a1cb9ee0..cf8f17d150ca901b9437f36070752e714317db35 100644 (file)
@@ -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;