[PATCH v2 18/20] conf: Move hugepages validation out of XML parser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 75 ++++++++++++++++++++++--------------------
 1 file changed, 40 insertions(+), 35 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index be9c08626a..f88576b5cc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6191,9 +6191,49 @@ virDomainDefMemtuneValidate(const virDomainDef *def)
     size_t i;
     ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
 
+    if (mem->nhugepages == 0)
+        return 0;
+
+    if (mem->allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("hugepages are not allowed with memory "
+                         "allocation ondemand"));
+        return -1;
+    }
+
+    if (mem->source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("hugepages are not allowed with anonymous "
+                         "memory source"));
+        return -1;
+    }
+
     for (i = 0; i < mem->nhugepages; i++) {
+        size_t j;
         ssize_t nextBit;
 
+        for (j = 0; j < i; j++) {
+            if (mem->hugepages[i].nodemask &&
+                mem->hugepages[j].nodemask &&
+                virBitmapOverlaps(mem->hugepages[i].nodemask,
+                                  mem->hugepages[j].nodemask)) {
+                virReportError(VIR_ERR_XML_DETAIL,
+                               _("nodeset attribute of hugepages "
+                                 "of sizes %llu and %llu intersect"),
+                               mem->hugepages[i].size,
+                               mem->hugepages[j].size);
+                return -1;
+            } else if (!mem->hugepages[i].nodemask &&
+                       !mem->hugepages[j].nodemask) {
+                virReportError(VIR_ERR_XML_DETAIL,
+                               _("two master hugepages detected: "
+                                 "%llu and %llu"),
+                               mem->hugepages[i].size,
+                               mem->hugepages[j].size);
+                return -1;
+            }
+        }
+
         if (!mem->hugepages[i].nodemask) {
             /* This is the master hugepage to use. Skip it as it has no
              * nodemask anyway. */
@@ -19466,19 +19506,6 @@ virDomainDefParseXML(xmlDocPtr xml,
 
     if (virXPathNode("./memoryBacking/hugepages", ctxt)) {
         /* hugepages will be used */
-
-        if (def->mem.allocation == VIR_DOMAIN_MEMORY_ALLOCATION_ONDEMAND) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("hugepages are not allowed with memory allocation ondemand"));
-            goto error;
-        }
-
-        if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("hugepages are not allowed with anonymous memory source"));
-            goto error;
-        }
-
         if ((n = virXPathNodeSet("./memoryBacking/hugepages/page", ctxt, &nodes)) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("cannot extract hugepages nodes"));
@@ -19494,28 +19521,6 @@ virDomainDefParseXML(xmlDocPtr xml,
                                                &def->mem.hugepages[i]) < 0)
                     goto error;
                 def->mem.nhugepages++;
-
-                for (j = 0; j < i; j++) {
-                    if (def->mem.hugepages[i].nodemask &&
-                        def->mem.hugepages[j].nodemask &&
-                        virBitmapOverlaps(def->mem.hugepages[i].nodemask,
-                                          def->mem.hugepages[j].nodemask)) {
-                        virReportError(VIR_ERR_XML_DETAIL,
-                                       _("nodeset attribute of hugepages "
-                                         "of sizes %llu and %llu intersect"),
-                                       def->mem.hugepages[i].size,
-                                       def->mem.hugepages[j].size);
-                        goto error;
-                    } else if (!def->mem.hugepages[i].nodemask &&
-                               !def->mem.hugepages[j].nodemask) {
-                        virReportError(VIR_ERR_XML_DETAIL,
-                                       _("two master hugepages detected: "
-                                         "%llu and %llu"),
-                                       def->mem.hugepages[i].size,
-                                       def->mem.hugepages[j].size);
-                        goto error;
-                    }
-                }
             }
 
             VIR_FREE(nodes);
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux