]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Modify virCPUarmCompare to perform compare actions
authorZhenyu Zheng <zheng.zhenyu@outlook.com>
Thu, 24 Sep 2020 14:12:21 +0000 (22:12 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 5 Oct 2020 16:05:32 +0000 (18:05 +0200)
Modify virCPUarmCompare in cpu_arm.c to perform compare action.
This patch only adds host to host CPU compare, the rest cases
remains the same. This is useful for source and destination host
compare during migrations to avoid migration between different
CPU models that have different CPU freatures.

Signed-off-by: Zhenyu Zheng <zheng.zhenyu@outlook.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/cpu/cpu_arm.c

index 939a3b8390327d04ab0383d6ec66e53694240c63..31997b59cd7aba19ef455ae80e6050bc265f13e5 100644 (file)
@@ -463,10 +463,43 @@ virCPUarmBaseline(virCPUDefPtr *cpus,
 }
 
 static virCPUCompareResult
-virCPUarmCompare(virCPUDefPtr host G_GNUC_UNUSED,
-                 virCPUDefPtr cpu G_GNUC_UNUSED,
-                 bool failMessages G_GNUC_UNUSED)
+virCPUarmCompare(virCPUDefPtr host,
+                 virCPUDefPtr cpu,
+                 bool failIncompatible)
 {
+    /* Only support host to host CPU compare for ARM */
+    if (cpu->type != VIR_CPU_TYPE_HOST)
+        return VIR_CPU_COMPARE_IDENTICAL;
+
+    if (!host || !host->model) {
+        if (failIncompatible) {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+                           _("unknown host CPU"));
+            return VIR_CPU_COMPARE_ERROR;
+        }
+
+        VIR_WARN("unknown host CPU");
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
+    }
+
+    /* Compare vendor and model to check if CPUs are identical */
+    if (STRNEQ_NULLABLE(host->vendor, cpu->vendor) ||
+        STRNEQ_NULLABLE(host->model, cpu->model)) {
+        VIR_DEBUG("Host CPU model does not match required CPU "
+                  "vendor %s or(and) model %s",
+                  NULLSTR(cpu->vendor), NULLSTR(cpu->model));
+
+        if (failIncompatible) {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE,
+                           _("Host CPU model does not match required CPU "
+                             "vendor %s or(and) model %s"),
+                           NULLSTR(cpu->vendor), NULLSTR(cpu->model));
+            return VIR_CPU_COMPARE_ERROR;
+        }
+
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
+    }
+
     return VIR_CPU_COMPARE_IDENTICAL;
 }