3e5111
From c1ad40f4ad3813ff3013efba80983f62113fc092 Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <c1ad40f4ad3813ff3013efba80983f62113fc092@dist-git>
3e5111
From: Jiri Denemark <jdenemar@redhat.com>
3e5111
Date: Wed, 31 May 2017 16:42:42 +0200
3e5111
Subject: [PATCH] conf: Make error reporting in virCPUDefIsEqual optional
3e5111
3e5111
The function will be used in paths where mismatching CPU defs are not an
3e5111
error.
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
3e5111
(cherry picked from commit 25ec7f6fe959f2811bb014a8c1f0c92bdf9ca13d)
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1441662
3e5111
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/conf/cpu_conf.c    | 83 +++++++++++++++++++++++---------------------------
3e5111
 src/conf/cpu_conf.h    |  3 +-
3e5111
 src/conf/domain_conf.c |  2 +-
3e5111
 3 files changed, 41 insertions(+), 47 deletions(-)
3e5111
3e5111
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
3e5111
index a4be5742e3..ffb2e83d67 100644
3e5111
--- a/src/conf/cpu_conf.c
3e5111
+++ b/src/conf/cpu_conf.c
3e5111
@@ -811,7 +811,8 @@ virCPUDefAddFeature(virCPUDefPtr def,
3e5111
 
3e5111
 bool
3e5111
 virCPUDefIsEqual(virCPUDefPtr src,
3e5111
-                 virCPUDefPtr dst)
3e5111
+                 virCPUDefPtr dst,
3e5111
+                 bool reportError)
3e5111
 {
3e5111
     bool identical = false;
3e5111
     size_t i;
3e5111
@@ -819,98 +820,89 @@ virCPUDefIsEqual(virCPUDefPtr src,
3e5111
     if (!src && !dst)
3e5111
         return true;
3e5111
 
3e5111
+#define MISMATCH(fmt, ...)                                              \
3e5111
+    if (reportError)                                                    \
3e5111
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, fmt, __VA_ARGS__)
3e5111
+
3e5111
     if ((src && !dst) || (!src && dst)) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
3e5111
-                       _("Target CPU does not match source"));
3e5111
+        MISMATCH("%s", _("Target CPU does not match source"));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->type != dst->type) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU type %s does not match source %s"),
3e5111
-                       virCPUTypeToString(dst->type),
3e5111
-                       virCPUTypeToString(src->type));
3e5111
+        MISMATCH(_("Target CPU type %s does not match source %s"),
3e5111
+                 virCPUTypeToString(dst->type),
3e5111
+                 virCPUTypeToString(src->type));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->mode != dst->mode) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU mode %s does not match source %s"),
3e5111
-                       virCPUModeTypeToString(dst->mode),
3e5111
-                       virCPUModeTypeToString(src->mode));
3e5111
+        MISMATCH(_("Target CPU mode %s does not match source %s"),
3e5111
+                 virCPUModeTypeToString(dst->mode),
3e5111
+                 virCPUModeTypeToString(src->mode));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->arch != dst->arch) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU arch %s does not match source %s"),
3e5111
-                       virArchToString(dst->arch),
3e5111
-                       virArchToString(src->arch));
3e5111
+        MISMATCH(_("Target CPU arch %s does not match source %s"),
3e5111
+                 virArchToString(dst->arch),
3e5111
+                 virArchToString(src->arch));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (STRNEQ_NULLABLE(src->model, dst->model)) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU model %s does not match source %s"),
3e5111
-                       NULLSTR(dst->model), NULLSTR(src->model));
3e5111
+        MISMATCH(_("Target CPU model %s does not match source %s"),
3e5111
+                 NULLSTR(dst->model), NULLSTR(src->model));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (STRNEQ_NULLABLE(src->vendor, dst->vendor)) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU vendor %s does not match source %s"),
3e5111
-                       NULLSTR(dst->vendor), NULLSTR(src->vendor));
3e5111
+        MISMATCH(_("Target CPU vendor %s does not match source %s"),
3e5111
+                 NULLSTR(dst->vendor), NULLSTR(src->vendor));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU vendor id %s does not match source %s"),
3e5111
-                       NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id));
3e5111
+        MISMATCH(_("Target CPU vendor id %s does not match source %s"),
3e5111
+                 NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->sockets != dst->sockets) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU sockets %d does not match source %d"),
3e5111
-                       dst->sockets, src->sockets);
3e5111
+        MISMATCH(_("Target CPU sockets %d does not match source %d"),
3e5111
+                 dst->sockets, src->sockets);
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->cores != dst->cores) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU cores %d does not match source %d"),
3e5111
-                       dst->cores, src->cores);
3e5111
+        MISMATCH(_("Target CPU cores %d does not match source %d"),
3e5111
+                 dst->cores, src->cores);
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->threads != dst->threads) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU threads %d does not match source %d"),
3e5111
-                       dst->threads, src->threads);
3e5111
+        MISMATCH(_("Target CPU threads %d does not match source %d"),
3e5111
+                 dst->threads, src->threads);
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     if (src->nfeatures != dst->nfeatures) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                       _("Target CPU feature count %zu does not match source %zu"),
3e5111
-                       dst->nfeatures, src->nfeatures);
3e5111
+        MISMATCH(_("Target CPU feature count %zu does not match source %zu"),
3e5111
+                 dst->nfeatures, src->nfeatures);
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
     for (i = 0; i < src->nfeatures; i++) {
3e5111
         if (STRNEQ(src->features[i].name, dst->features[i].name)) {
3e5111
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                           _("Target CPU feature %s does not match source %s"),
3e5111
-                           dst->features[i].name, src->features[i].name);
3e5111
+            MISMATCH(_("Target CPU feature %s does not match source %s"),
3e5111
+                     dst->features[i].name, src->features[i].name);
3e5111
             goto cleanup;
3e5111
         }
3e5111
 
3e5111
         if (src->features[i].policy != dst->features[i].policy) {
3e5111
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
3e5111
-                           _("Target CPU feature policy %s does not match source %s"),
3e5111
-                           virCPUFeaturePolicyTypeToString(dst->features[i].policy),
3e5111
-                           virCPUFeaturePolicyTypeToString(src->features[i].policy));
3e5111
+            MISMATCH(_("Target CPU feature policy %s does not match source %s"),
3e5111
+                     virCPUFeaturePolicyTypeToString(dst->features[i].policy),
3e5111
+                     virCPUFeaturePolicyTypeToString(src->features[i].policy));
3e5111
             goto cleanup;
3e5111
         }
3e5111
     }
3e5111
@@ -920,11 +912,12 @@ virCPUDefIsEqual(virCPUDefPtr src,
3e5111
         (src->cache && dst->cache &&
3e5111
          (src->cache->level != dst->cache->level ||
3e5111
           src->cache->mode != dst->cache->mode))) {
3e5111
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
3e5111
-                       _("Target CPU cache does not match source"));
3e5111
+        MISMATCH("%s", _("Target CPU cache does not match source"));
3e5111
         goto cleanup;
3e5111
     }
3e5111
 
3e5111
+#undef MISMATCH
3e5111
+
3e5111
     identical = true;
3e5111
 
3e5111
  cleanup:
3e5111
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
3e5111
index 09438b68b4..b0d891552a 100644
3e5111
--- a/src/conf/cpu_conf.h
3e5111
+++ b/src/conf/cpu_conf.h
3e5111
@@ -189,7 +189,8 @@ virCPUDefParseXML(xmlNodePtr node,
3e5111
 
3e5111
 bool
3e5111
 virCPUDefIsEqual(virCPUDefPtr src,
3e5111
-                 virCPUDefPtr dst);
3e5111
+                 virCPUDefPtr dst,
3e5111
+                 bool reportError);
3e5111
 
3e5111
 char *
3e5111
 virCPUDefFormat(virCPUDefPtr def,
3e5111
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
3e5111
index bab85c6362..2197330a22 100644
3e5111
--- a/src/conf/domain_conf.c
3e5111
+++ b/src/conf/domain_conf.c
3e5111
@@ -20042,7 +20042,7 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
3e5111
             goto error;
3e5111
     }
3e5111
 
3e5111
-    if (!virCPUDefIsEqual(src->cpu, dst->cpu))
3e5111
+    if (!virCPUDefIsEqual(src->cpu, dst->cpu, true))
3e5111
         goto error;
3e5111
 
3e5111
     if (!virSysinfoIsEqual(src->sysinfo, dst->sysinfo))
3e5111
-- 
3e5111
2.13.1
3e5111