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