diff mbox series

[V2] Modify virCPUarmCompare to perform compare actions

Message ID OSYP286MB018131ABA7BA761FDD7BAA2799210@OSYP286MB0181.JPNP286.PROD.OUTLOOK.COM
State New
Headers show
Series [V2] Modify virCPUarmCompare to perform compare actions | expand

Commit Message

Zhenyu Zheng Sept. 16, 2020, 3:04 a.m. UTC
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 | 51 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 47 insertions(+), 4 deletions(-)

-- 
2.20.1

Comments

Peter Krempa Sept. 16, 2020, 7:19 a.m. UTC | #1
On Wed, Sep 16, 2020 at 11:04:58 +0800, 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>

> ---

>  src/cpu/cpu_arm.c | 51 +++++++++++++++++++++++++++++++++++++++++++----

>  1 file changed, 47 insertions(+), 4 deletions(-)

> 

> diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c

> index 939a3b8390..e8581ec31f 100644

> --- a/src/cpu/cpu_arm.c

> +++ b/src/cpu/cpu_arm.c

> @@ -463,11 +463,54 @@ 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

> +)

>  {

> -    return VIR_CPU_COMPARE_IDENTICAL;

> +    g_autofree char *message = NULL;

> +    virCPUCompareResult ret = VIR_CPU_COMPARE_IDENTICAL;

> +

> +    /* Only support host to host CPU compare for ARM*/

> +    if (cpu->type != VIR_CPU_TYPE_HOST)

> +        return ret;

> +

> +    if (!host || !host->model) {

> +        if (failIncompatible) {

> +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",

> +                           _("unknown host CPU"));

> +            ret = VIR_CPU_COMPARE_ERROR;

> +        } else {

> +            VIR_WARN("unknown host CPU");

> +            ret = VIR_CPU_COMPARE_INCOMPATIBLE;

> +        }

> +        return ret;

> +    }

> +

> +    /* Compare vendor and model to check if CPUs are identical */

> +    if (STRNEQ(host->vendor, cpu->vendor) ||

> +        STRNEQ(host->model, cpu->model)) {

> +        VIR_DEBUG("host CPU model does not match required CPU model %s",

> +                  cpu->model);

> +        if (message) {


'message' was initialized to NULL here so this code won't ever be
executed.

> +            message = g_strdup_printf(_("host CPU model does not match required "

> +                                        "CPU model %s"),

> +                                      cpu->model);

> +        }

> +

> +        ret = VIR_CPU_COMPARE_INCOMPATIBLE;

> +    }

> +

> +    if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) {

> +        ret = VIR_CPU_COMPARE_ERROR;

> +        if (message) {

> +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message);


Neither this code since it will still be NULL.

Also please don't store the error message in a random variable, but
rather use a specific virReportError call. If you want to omit it in
certain cases, just skip the whole virReportError call.

> +        } else {

> +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);

> +        }

> +    }

> +

> +    return ret;

>  }

>  

>  static int

> -- 

> 2.20.1

> 

>
Zhenyu Zheng Sept. 16, 2020, 7:49 a.m. UTC | #2
oh, yes, thanks for the correction, I've messed this up with another
version of code.

On Wed, Sep 16, 2020 at 3:20 PM Peter Krempa <pkrempa@redhat.com> wrote:

> On Wed, Sep 16, 2020 at 11:04:58 +0800, 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>

> > ---

> >  src/cpu/cpu_arm.c | 51 +++++++++++++++++++++++++++++++++++++++++++----

> >  1 file changed, 47 insertions(+), 4 deletions(-)

> >

> > diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c

> > index 939a3b8390..e8581ec31f 100644

> > --- a/src/cpu/cpu_arm.c

> > +++ b/src/cpu/cpu_arm.c

> > @@ -463,11 +463,54 @@ 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

> > +)

> >  {

> > -    return VIR_CPU_COMPARE_IDENTICAL;

> > +    g_autofree char *message = NULL;

> > +    virCPUCompareResult ret = VIR_CPU_COMPARE_IDENTICAL;

> > +

> > +    /* Only support host to host CPU compare for ARM*/

> > +    if (cpu->type != VIR_CPU_TYPE_HOST)

> > +        return ret;

> > +

> > +    if (!host || !host->model) {

> > +        if (failIncompatible) {

> > +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",

> > +                           _("unknown host CPU"));

> > +            ret = VIR_CPU_COMPARE_ERROR;

> > +        } else {

> > +            VIR_WARN("unknown host CPU");

> > +            ret = VIR_CPU_COMPARE_INCOMPATIBLE;

> > +        }

> > +        return ret;

> > +    }

> > +

> > +    /* Compare vendor and model to check if CPUs are identical */

> > +    if (STRNEQ(host->vendor, cpu->vendor) ||

> > +        STRNEQ(host->model, cpu->model)) {

> > +        VIR_DEBUG("host CPU model does not match required CPU model %s",

> > +                  cpu->model);

> > +        if (message) {

>

> 'message' was initialized to NULL here so this code won't ever be

> executed.

>

> > +            message = g_strdup_printf(_("host CPU model does not match

> required "

> > +                                        "CPU model %s"),

> > +                                      cpu->model);

> > +        }

> > +

> > +        ret = VIR_CPU_COMPARE_INCOMPATIBLE;

> > +    }

> > +

> > +    if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) {

> > +        ret = VIR_CPU_COMPARE_ERROR;

> > +        if (message) {

> > +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message);

>

> Neither this code since it will still be NULL.

>

> Also please don't store the error message in a random variable, but

> rather use a specific virReportError call. If you want to omit it in

> certain cases, just skip the whole virReportError call.

>

> > +        } else {

> > +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);

> > +        }

> > +    }

> > +

> > +    return ret;

> >  }

> >

> >  static int

> > --

> > 2.20.1

> >

> >

>

>
<div dir="ltr">oh, yes, thanks for the correction, I&#39;ve messed this up with another version of code.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 16, 2020 at 3:20 PM Peter Krempa &lt;<a href="mailto:pkrempa@redhat.com">pkrempa@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Sep 16, 2020 at 11:04:58 +0800, Zhenyu Zheng wrote:<br>
&gt; Modify virCPUarmCompare in cpu_arm.c to perform compare action.<br>
&gt; This patch only adds host to host CPU compare, the rest cases<br>
&gt; remains the same. This is useful for source and destination host<br>
&gt; compare during migrations to avoid migration between different<br>
&gt; CPU models that have different CPU freatures.<br>
&gt; <br>
&gt; Signed-off-by: Zhenyu Zheng &lt;<a href="mailto:zheng.zhenyu@outlook.com" target="_blank">zheng.zhenyu@outlook.com</a>&gt;<br>
&gt; ---<br>
&gt;  src/cpu/cpu_arm.c | 51 +++++++++++++++++++++++++++++++++++++++++++----<br>
&gt;  1 file changed, 47 insertions(+), 4 deletions(-)<br>
&gt; <br>
&gt; diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c<br>
&gt; index 939a3b8390..e8581ec31f 100644<br>
&gt; --- a/src/cpu/cpu_arm.c<br>
&gt; +++ b/src/cpu/cpu_arm.c<br>
&gt; @@ -463,11 +463,54 @@ virCPUarmBaseline(virCPUDefPtr *cpus,<br>
&gt;  }<br>
&gt;  <br>
&gt;  static virCPUCompareResult<br>
&gt; -virCPUarmCompare(virCPUDefPtr host G_GNUC_UNUSED,<br>
&gt; -                 virCPUDefPtr cpu G_GNUC_UNUSED,<br>
&gt; -                 bool failMessages G_GNUC_UNUSED)<br>
&gt; +virCPUarmCompare(virCPUDefPtr host,<br>
&gt; +                 virCPUDefPtr cpu,<br>
&gt; +                 bool failIncompatible<br>
&gt; +)<br>
&gt;  {<br>
&gt; -    return VIR_CPU_COMPARE_IDENTICAL;<br>
&gt; +    g_autofree char *message = NULL;<br>
&gt; +    virCPUCompareResult ret = VIR_CPU_COMPARE_IDENTICAL;<br>
&gt; +<br>
&gt; +    /* Only support host to host CPU compare for ARM*/<br>
&gt; +    if (cpu-&gt;type != VIR_CPU_TYPE_HOST)<br>
&gt; +        return ret;<br>
&gt; +<br>
&gt; +    if (!host || !host-&gt;model) {<br>
&gt; +        if (failIncompatible) {<br>
&gt; +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, &quot;%s&quot;,<br>
&gt; +                           _(&quot;unknown host CPU&quot;));<br>
&gt; +            ret = VIR_CPU_COMPARE_ERROR;<br>
&gt; +        } else {<br>
&gt; +            VIR_WARN(&quot;unknown host CPU&quot;);<br>
&gt; +            ret = VIR_CPU_COMPARE_INCOMPATIBLE;<br>
&gt; +        }<br>
&gt; +        return ret;<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    /* Compare vendor and model to check if CPUs are identical */<br>
&gt; +    if (STRNEQ(host-&gt;vendor, cpu-&gt;vendor) ||<br>
&gt; +        STRNEQ(host-&gt;model, cpu-&gt;model)) {<br>
&gt; +        VIR_DEBUG(&quot;host CPU model does not match required CPU model %s&quot;,<br>
&gt; +                  cpu-&gt;model);<br>
&gt; +        if (message) {<br>
<br>
&#39;message&#39; was initialized to NULL here so this code won&#39;t ever be<br>
executed.<br>
<br>
&gt; +            message = g_strdup_printf(_(&quot;host CPU model does not match required &quot;<br>
&gt; +                                        &quot;CPU model %s&quot;),<br>
&gt; +                                      cpu-&gt;model);<br>
&gt; +        }<br>
&gt; +<br>
&gt; +        ret = VIR_CPU_COMPARE_INCOMPATIBLE;<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    if (failIncompatible &amp;&amp; ret == VIR_CPU_COMPARE_INCOMPATIBLE) {<br>
&gt; +        ret = VIR_CPU_COMPARE_ERROR;<br>
&gt; +        if (message) {<br>
&gt; +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, &quot;%s&quot;, message);<br>
<br>
Neither this code since it will still be NULL.<br>
<br>
Also please don&#39;t store the error message in a random variable, but<br>
rather use a specific virReportError call. If you want to omit it in<br>
certain cases, just skip the whole virReportError call.<br>
<br>
&gt; +        } else {<br>
&gt; +            virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);<br>
&gt; +        }<br>
&gt; +    }<br>
&gt; +<br>
&gt; +    return ret;<br>
&gt;  }<br>
&gt;  <br>
&gt;  static int<br>
&gt; -- <br>
&gt; 2.20.1<br>
&gt; <br>
&gt; <br>
<br>
</blockquote></div>
diff mbox series

Patch

diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 939a3b8390..e8581ec31f 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -463,11 +463,54 @@  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
+)
 {
-    return VIR_CPU_COMPARE_IDENTICAL;
+    g_autofree char *message = NULL;
+    virCPUCompareResult ret = VIR_CPU_COMPARE_IDENTICAL;
+
+    /* Only support host to host CPU compare for ARM*/
+    if (cpu->type != VIR_CPU_TYPE_HOST)
+        return ret;
+
+    if (!host || !host->model) {
+        if (failIncompatible) {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+                           _("unknown host CPU"));
+            ret = VIR_CPU_COMPARE_ERROR;
+        } else {
+            VIR_WARN("unknown host CPU");
+            ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+        }
+        return ret;
+    }
+
+    /* Compare vendor and model to check if CPUs are identical */
+    if (STRNEQ(host->vendor, cpu->vendor) ||
+        STRNEQ(host->model, cpu->model)) {
+        VIR_DEBUG("host CPU model does not match required CPU model %s",
+                  cpu->model);
+        if (message) {
+            message = g_strdup_printf(_("host CPU model does not match required "
+                                        "CPU model %s"),
+                                      cpu->model);
+        }
+
+        ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+    }
+
+    if (failIncompatible && ret == VIR_CPU_COMPARE_INCOMPATIBLE) {
+        ret = VIR_CPU_COMPARE_ERROR;
+        if (message) {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", message);
+        } else {
+            virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL);
+        }
+    }
+
+    return ret;
 }
 
 static int