[PATCH V4] Modify virCPUarmCompare to perform compare actions

Zhenyu Zheng posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/OSYP286MB01813FB72F6DA82E897BB2C699390@OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM
src/cpu/cpu_arm.c | 39 ++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)
[PATCH V4] Modify virCPUarmCompare to perform compare actions
Posted by Zhenyu Zheng 3 years, 7 months ago
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>
---
 src/cpu/cpu_arm.c | 39 ++++++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 939a3b8390..64bd0f03c2 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -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;
+        } else {
+            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;
+        } else {
+            return VIR_CPU_COMPARE_INCOMPATIBLE;
+        }
+    }
     return VIR_CPU_COMPARE_IDENTICAL;
 }
 
-- 
2.20.1


Re: [PATCH V4] Modify virCPUarmCompare to perform compare actions
Posted by Daniel Henrique Barboza 3 years, 6 months ago

On 9/24/20 11:12 AM, Zhenyu Zheng wrote:
> 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>
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>


>   src/cpu/cpu_arm.c | 39 ++++++++++++++++++++++++++++++++++++---
>   1 file changed, 36 insertions(+), 3 deletions(-)
> 
> diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
> index 939a3b8390..64bd0f03c2 100644
> --- a/src/cpu/cpu_arm.c
> +++ b/src/cpu/cpu_arm.c
> @@ -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;
> +        } else {
> +            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;
> +        } else {
> +            return VIR_CPU_COMPARE_INCOMPATIBLE;
> +        }
> +    }
>       return VIR_CPU_COMPARE_IDENTICAL;
>   }
>   
> 

Re: [PATCH V4] Modify virCPUarmCompare to perform compare actions
Posted by Michal Privoznik 3 years, 6 months ago
On 10/2/20 3:45 PM, Daniel Henrique Barboza wrote:
> 
> 
> On 9/24/20 11:12 AM, Zhenyu Zheng wrote:
>> 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>
>> ---
> 
> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

Pushed now.

Michal