99cbc7
From d81b31dc2ad17c7ba790c7cfbc29b82b6c8c198c Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <d81b31dc2ad17c7ba790c7cfbc29b82b6c8c198c@dist-git>
99cbc7
From: Pavel Hrdina <phrdina@redhat.com>
99cbc7
Date: Mon, 13 Aug 2018 18:16:21 +0200
99cbc7
Subject: [PATCH] conf: Move hugepages validation out of XML parser
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
99cbc7
(cherry picked from commit 82327038390bfae117dc6e1d9062e38901cd4c97)
99cbc7
99cbc7
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1591235
99cbc7
99cbc7
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/conf/domain_conf.c | 75 ++++++++++++++++++++++--------------------
99cbc7
 1 file changed, 40 insertions(+), 35 deletions(-)
99cbc7
99cbc7
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
99cbc7
index 280bbdf35c..98e833c5bb 100644
99cbc7
--- a/src/conf/domain_conf.c
99cbc7
+++ b/src/conf/domain_conf.c
99cbc7
@@ -6149,9 +6149,49 @@ virDomainDefMemtuneValidate(const virDomainDef *def)
99cbc7
     size_t i;
99cbc7
     ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
99cbc7
 
99cbc7
+    if (mem->nhugepages == 0)
99cbc7
+        return 0;
99cbc7
+
99cbc7
+    if (mem->allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) {
99cbc7
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
99cbc7
+                       _("hugepages are not allowed with memory "
99cbc7
+                         "allocation ondemand"));
99cbc7
+        return -1;
99cbc7
+    }
99cbc7
+
99cbc7
+    if (mem->source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) {
99cbc7
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
99cbc7
+                       _("hugepages are not allowed with anonymous "
99cbc7
+                         "memory source"));
99cbc7
+        return -1;
99cbc7
+    }
99cbc7
+
99cbc7
     for (i = 0; i < mem->nhugepages; i++) {
99cbc7
+        size_t j;
99cbc7
         ssize_t nextBit;
99cbc7
 
99cbc7
+        for (j = 0; j < i; j++) {
99cbc7
+            if (mem->hugepages[i].nodemask &&
99cbc7
+                mem->hugepages[j].nodemask &&
99cbc7
+                virBitmapOverlaps(mem->hugepages[i].nodemask,
99cbc7
+                                  mem->hugepages[j].nodemask)) {
99cbc7
+                virReportError(VIR_ERR_XML_DETAIL,
99cbc7
+                               _("nodeset attribute of hugepages "
99cbc7
+                                 "of sizes %llu and %llu intersect"),
99cbc7
+                               mem->hugepages[i].size,
99cbc7
+                               mem->hugepages[j].size);
99cbc7
+                return -1;
99cbc7
+            } else if (!mem->hugepages[i].nodemask &&
99cbc7
+                       !mem->hugepages[j].nodemask) {
99cbc7
+                virReportError(VIR_ERR_XML_DETAIL,
99cbc7
+                               _("two master hugepages detected: "
99cbc7
+                                 "%llu and %llu"),
99cbc7
+                               mem->hugepages[i].size,
99cbc7
+                               mem->hugepages[j].size);
99cbc7
+                return -1;
99cbc7
+            }
99cbc7
+        }
99cbc7
+
99cbc7
         if (!mem->hugepages[i].nodemask) {
99cbc7
             /* This is the master hugepage to use. Skip it as it has no
99cbc7
              * nodemask anyway. */
99cbc7
@@ -19414,19 +19454,6 @@ virDomainDefParseXML(xmlDocPtr xml,
99cbc7
 
99cbc7
     if (virXPathNode("./memoryBacking/hugepages", ctxt)) {
99cbc7
         /* hugepages will be used */
99cbc7
-
99cbc7
-        if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) {
99cbc7
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
99cbc7
-                           _("hugepages are not allowed with memory allocation ondemand"));
99cbc7
-            goto error;
99cbc7
-        }
99cbc7
-
99cbc7
-        if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) {
99cbc7
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
99cbc7
-                           _("hugepages are not allowed with anonymous memory source"));
99cbc7
-            goto error;
99cbc7
-        }
99cbc7
-
99cbc7
         if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) {
99cbc7
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
99cbc7
                            _("cannot extract hugepages nodes"));
99cbc7
@@ -19442,28 +19469,6 @@ virDomainDefParseXML(xmlDocPtr xml,
99cbc7
                                                &def->mem.hugepages[i]) < 0)
99cbc7
                     goto error;
99cbc7
                 def->mem.nhugepages++;
99cbc7
-
99cbc7
-                for (j = 0; j < i; j++) {
99cbc7
-                    if (def->mem.hugepages[i].nodemask &&
99cbc7
-                        def->mem.hugepages[j].nodemask &&
99cbc7
-                        virBitmapOverlaps(def->mem.hugepages[i].nodemask,
99cbc7
-                                          def->mem.hugepages[j].nodemask)) {
99cbc7
-                        virReportError(VIR_ERR_XML_DETAIL,
99cbc7
-                                       _("nodeset attribute of hugepages "
99cbc7
-                                         "of sizes %llu and %llu intersect"),
99cbc7
-                                       def->mem.hugepages[i].size,
99cbc7
-                                       def->mem.hugepages[j].size);
99cbc7
-                        goto error;
99cbc7
-                    } else if (!def->mem.hugepages[i].nodemask &&
99cbc7
-                               !def->mem.hugepages[j].nodemask) {
99cbc7
-                        virReportError(VIR_ERR_XML_DETAIL,
99cbc7
-                                       _("two master hugepages detected: "
99cbc7
-                                         "%llu and %llu"),
99cbc7
-                                       def->mem.hugepages[i].size,
99cbc7
-                                       def->mem.hugepages[j].size);
99cbc7
-                        goto error;
99cbc7
-                    }
99cbc7
-                }
99cbc7
             }
99cbc7
 
99cbc7
             VIR_FREE(nodes);
99cbc7
-- 
99cbc7
2.18.0
99cbc7