51d9a2
From 6ed9653d9339dca71103c8d6c9f75749bdaf9a54 Mon Sep 17 00:00:00 2001
51d9a2
Message-Id: <6ed9653d9339dca71103c8d6c9f75749bdaf9a54@dist-git>
51d9a2
From: Pavel Hrdina <phrdina@redhat.com>
51d9a2
Date: Mon, 13 Aug 2018 18:16:20 +0200
51d9a2
Subject: [PATCH] conf: Move hugepage XML validation check out of qemu_command
51d9a2
MIME-Version: 1.0
51d9a2
Content-Type: text/plain; charset=UTF-8
51d9a2
Content-Transfer-Encoding: 8bit
51d9a2
51d9a2
We can safely validate the hugepage nodeset attribute at a define time.
51d9a2
This validation is not done for already existing domains when the daemon
51d9a2
is restarted.
51d9a2
51d9a2
All the changes to the tests are necessary because we move the error
51d9a2
from domain start into XML parse.
51d9a2
51d9a2
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
51d9a2
(cherry picked from commit 5c93dfb46d9dff623707994f115b6bd7ca4f0682)
51d9a2
51d9a2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1591235
51d9a2
51d9a2
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
51d9a2
Reviewed-by: Ján Tomko <jtomko@redhat.com>
51d9a2
---
51d9a2
 src/conf/domain_conf.c                        | 32 +++++++++++++++++
51d9a2
 src/qemu/qemu_command.c                       | 34 -------------------
51d9a2
 .../seclabel-dynamic-none-relabel.xml         |  2 +-
51d9a2
 tests/qemuxml2argvtest.c                      | 18 +++++-----
51d9a2
 .../hugepages-default-1G-nodeset-2M.xml       |  1 -
51d9a2
 .../qemuxml2xmloutdata/hugepages-nodeset.xml  |  1 -
51d9a2
 .../hugepages-numa-nodeset-nonexist.xml       |  1 -
51d9a2
 .../seclabel-dynamic-none-relabel.xml         |  2 +-
51d9a2
 tests/qemuxml2xmltest.c                       |  3 --
51d9a2
 9 files changed, 43 insertions(+), 51 deletions(-)
51d9a2
 delete mode 120000 tests/qemuxml2xmloutdata/hugepages-default-1G-nodeset-2M.xml
51d9a2
 delete mode 120000 tests/qemuxml2xmloutdata/hugepages-nodeset.xml
51d9a2
 delete mode 120000 tests/qemuxml2xmloutdata/hugepages-numa-nodeset-nonexist.xml
51d9a2
51d9a2
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
51d9a2
index a05aad056d..280bbdf35c 100644
51d9a2
--- a/src/conf/domain_conf.c
51d9a2
+++ b/src/conf/domain_conf.c
51d9a2
@@ -6142,6 +6142,35 @@ virDomainDefLifecycleActionValidate(const virDomainDef *def)
51d9a2
 }
51d9a2
 
51d9a2
 
51d9a2
+static int
51d9a2
+virDomainDefMemtuneValidate(const virDomainDef *def)
51d9a2
+{
51d9a2
+    const virDomainMemtune *mem = &(def->mem);
51d9a2
+    size_t i;
51d9a2
+    ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
51d9a2
+
51d9a2
+    for (i = 0; i < mem->nhugepages; i++) {
51d9a2
+        ssize_t nextBit;
51d9a2
+
51d9a2
+        if (!mem->hugepages[i].nodemask) {
51d9a2
+            /* This is the master hugepage to use. Skip it as it has no
51d9a2
+             * nodemask anyway. */
51d9a2
+            continue;
51d9a2
+        }
51d9a2
+
51d9a2
+        nextBit = virBitmapNextSetBit(mem->hugepages[i].nodemask, pos);
51d9a2
+        if (nextBit >= 0) {
51d9a2
+            virReportError(VIR_ERR_XML_DETAIL,
51d9a2
+                           _("hugepages: node %zd not found"),
51d9a2
+                           nextBit);
51d9a2
+            return -1;
51d9a2
+        }
51d9a2
+    }
51d9a2
+
51d9a2
+    return 0;
51d9a2
+}
51d9a2
+
51d9a2
+
51d9a2
 static int
51d9a2
 virDomainDefValidateInternal(const virDomainDef *def)
51d9a2
 {
51d9a2
@@ -6177,6 +6206,9 @@ virDomainDefValidateInternal(const virDomainDef *def)
51d9a2
     if (virDomainDefLifecycleActionValidate(def) < 0)
51d9a2
         return -1;
51d9a2
 
51d9a2
+    if (virDomainDefMemtuneValidate(def) < 0)
51d9a2
+        return -1;
51d9a2
+
51d9a2
     return 0;
51d9a2
 }
51d9a2
 
51d9a2
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
51d9a2
index 954265feb0..f2b64ed720 100644
51d9a2
--- a/src/qemu/qemu_command.c
51d9a2
+++ b/src/qemu/qemu_command.c
51d9a2
@@ -7482,16 +7482,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
51d9a2
     if (!def->mem.nhugepages)
51d9a2
         return 0;
51d9a2
 
51d9a2
-    if (def->mem.hugepages[0].nodemask) {
51d9a2
-        ssize_t next_bit = virBitmapNextSetBit(def->mem.hugepages[0].nodemask, -1);
51d9a2
-        if (next_bit >= 0) {
51d9a2
-            virReportError(VIR_ERR_XML_DETAIL,
51d9a2
-                           _("hugepages: node %zd not found"),
51d9a2
-                           next_bit);
51d9a2
-            return -1;
51d9a2
-        }
51d9a2
-    }
51d9a2
-
51d9a2
     /* There is one special case: if user specified "huge"
51d9a2
      * pages of regular system pages size.
51d9a2
      * And there is nothing to do in this case.
51d9a2
@@ -7624,30 +7614,6 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
51d9a2
     if (!virDomainNumatuneNodesetIsAvailable(def->numa, priv->autoNodeset))
51d9a2
         goto cleanup;
51d9a2
 
51d9a2
-    for (i = 0; i < def->mem.nhugepages; i++) {
51d9a2
-        ssize_t next_bit, pos = 0;
51d9a2
-
51d9a2
-        if (!def->mem.hugepages[i].nodemask) {
51d9a2
-            /* This is the master hugepage to use. Skip it as it has no
51d9a2
-             * nodemask anyway. */
51d9a2
-            continue;
51d9a2
-        }
51d9a2
-
51d9a2
-        if (ncells) {
51d9a2
-            /* Fortunately, we allow only guest NUMA nodes to be continuous
51d9a2
-             * starting from zero. */
51d9a2
-            pos = ncells - 1;
51d9a2
-        }
51d9a2
-
51d9a2
-        next_bit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, pos);
51d9a2
-        if (next_bit >= 0) {
51d9a2
-            virReportError(VIR_ERR_XML_DETAIL,
51d9a2
-                           _("hugepages: node %zd not found"),
51d9a2
-                           next_bit);
51d9a2
-            goto cleanup;
51d9a2
-        }
51d9a2
-    }
51d9a2
-
51d9a2
     if (VIR_ALLOC_N(nodeBackends, ncells) < 0)
51d9a2
         goto cleanup;
51d9a2
 
51d9a2
diff --git a/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml b/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
51d9a2
index 47f253b5f7..e954250009 100644
51d9a2
--- a/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
51d9a2
+++ b/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
51d9a2
@@ -5,7 +5,7 @@
51d9a2
   <currentMemory unit='KiB'>262144</currentMemory>
51d9a2
   <memoryBacking>
51d9a2
     <hugepages>
51d9a2
-      <page size='2048' unit='KiB' nodeset='0'/>
51d9a2
+      <page size='2048' unit='KiB'/>
51d9a2
     </hugepages>
51d9a2
   </memoryBacking>
51d9a2
   <vcpu placement='static'>4</vcpu>
51d9a2
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
51d9a2
index bd5fdf9412..f82bca2637 100644
51d9a2
--- a/tests/qemuxml2argvtest.c
51d9a2
+++ b/tests/qemuxml2argvtest.c
51d9a2
@@ -959,12 +959,12 @@ mymain(void)
51d9a2
     DO_TEST("hugepages-default", NONE);
51d9a2
     DO_TEST("hugepages-default-2M", NONE);
51d9a2
     DO_TEST("hugepages-default-system-size", NONE);
51d9a2
-    DO_TEST("hugepages-default-1G-nodeset-2M", NONE);
51d9a2
-    DO_TEST_FAILURE("hugepages-nodeset", NONE);
51d9a2
-    DO_TEST_FAILURE("hugepages-nodeset-nonexist",
51d9a2
-                    QEMU_CAPS_DEVICE_PC_DIMM,
51d9a2
-                    QEMU_CAPS_OBJECT_MEMORY_FILE,
51d9a2
-                    QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
51d9a2
+    DO_TEST_PARSE_ERROR("hugepages-default-1G-nodeset-2M", NONE);
51d9a2
+    DO_TEST_PARSE_ERROR("hugepages-nodeset", NONE);
51d9a2
+    DO_TEST_PARSE_ERROR("hugepages-nodeset-nonexist",
51d9a2
+                        QEMU_CAPS_DEVICE_PC_DIMM,
51d9a2
+                        QEMU_CAPS_OBJECT_MEMORY_FILE,
51d9a2
+                        QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
51d9a2
     DO_TEST("hugepages-numa-default",
51d9a2
             QEMU_CAPS_OBJECT_MEMORY_FILE);
51d9a2
     DO_TEST("hugepages-numa-default-2M",
51d9a2
@@ -979,9 +979,9 @@ mymain(void)
51d9a2
     DO_TEST("hugepages-numa-nodeset-part",
51d9a2
             QEMU_CAPS_OBJECT_MEMORY_RAM,
51d9a2
             QEMU_CAPS_OBJECT_MEMORY_FILE);
51d9a2
-    DO_TEST_FAILURE("hugepages-numa-nodeset-nonexist",
51d9a2
-                    QEMU_CAPS_OBJECT_MEMORY_RAM,
51d9a2
-                    QEMU_CAPS_OBJECT_MEMORY_FILE);
51d9a2
+    DO_TEST_PARSE_ERROR("hugepages-numa-nodeset-nonexist",
51d9a2
+                        QEMU_CAPS_OBJECT_MEMORY_RAM,
51d9a2
+                        QEMU_CAPS_OBJECT_MEMORY_FILE);
51d9a2
     DO_TEST("hugepages-shared",
51d9a2
             QEMU_CAPS_OBJECT_MEMORY_RAM,
51d9a2
             QEMU_CAPS_OBJECT_MEMORY_FILE);
51d9a2
diff --git a/tests/qemuxml2xmloutdata/hugepages-default-1G-nodeset-2M.xml b/tests/qemuxml2xmloutdata/hugepages-default-1G-nodeset-2M.xml
51d9a2
deleted file mode 120000
51d9a2
index 3d8eb7616e..0000000000
51d9a2
--- a/tests/qemuxml2xmloutdata/hugepages-default-1G-nodeset-2M.xml
51d9a2
+++ /dev/null
51d9a2
@@ -1 +0,0 @@
51d9a2
-../qemuxml2argvdata/hugepages-default-1G-nodeset-2M.xml
51d9a2
\ No newline at end of file
51d9a2
diff --git a/tests/qemuxml2xmloutdata/hugepages-nodeset.xml b/tests/qemuxml2xmloutdata/hugepages-nodeset.xml
51d9a2
deleted file mode 120000
51d9a2
index b55838b780..0000000000
51d9a2
--- a/tests/qemuxml2xmloutdata/hugepages-nodeset.xml
51d9a2
+++ /dev/null
51d9a2
@@ -1 +0,0 @@
51d9a2
-../qemuxml2argvdata/hugepages-nodeset.xml
51d9a2
\ No newline at end of file
51d9a2
diff --git a/tests/qemuxml2xmloutdata/hugepages-numa-nodeset-nonexist.xml b/tests/qemuxml2xmloutdata/hugepages-numa-nodeset-nonexist.xml
51d9a2
deleted file mode 120000
51d9a2
index d490edca69..0000000000
51d9a2
--- a/tests/qemuxml2xmloutdata/hugepages-numa-nodeset-nonexist.xml
51d9a2
+++ /dev/null
51d9a2
@@ -1 +0,0 @@
51d9a2
-../qemuxml2argvdata/hugepages-numa-nodeset-nonexist.xml
51d9a2
\ No newline at end of file
51d9a2
diff --git a/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml b/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
51d9a2
index 050967b4ee..bfa66b8deb 100644
51d9a2
--- a/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
51d9a2
+++ b/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
51d9a2
@@ -5,7 +5,7 @@
51d9a2
   <currentMemory unit='KiB'>262144</currentMemory>
51d9a2
   <memoryBacking>
51d9a2
     <hugepages>
51d9a2
-      <page size='2048' unit='KiB' nodeset='0'/>
51d9a2
+      <page size='2048' unit='KiB'/>
51d9a2
     </hugepages>
51d9a2
   </memoryBacking>
51d9a2
   <vcpu placement='static'>4</vcpu>
51d9a2
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
51d9a2
index acbe2f7133..aa543e9e51 100644
51d9a2
--- a/tests/qemuxml2xmltest.c
51d9a2
+++ b/tests/qemuxml2xmltest.c
51d9a2
@@ -336,13 +336,10 @@ mymain(void)
51d9a2
     DO_TEST("hugepages-default", NONE);
51d9a2
     DO_TEST("hugepages-default-2M", NONE);
51d9a2
     DO_TEST("hugepages-default-system-size", NONE);
51d9a2
-    DO_TEST("hugepages-default-1G-nodeset-2M", NONE);
51d9a2
-    DO_TEST("hugepages-nodeset", NONE);
51d9a2
     DO_TEST("hugepages-numa-default-2M", NONE);
51d9a2
     DO_TEST("hugepages-numa-default-dimm", NONE);
51d9a2
     DO_TEST("hugepages-numa-nodeset", NONE);
51d9a2
     DO_TEST("hugepages-numa-nodeset-part", NONE);
51d9a2
-    DO_TEST("hugepages-numa-nodeset-nonexist", NONE);
51d9a2
     DO_TEST("hugepages-shared", NONE);
51d9a2
     DO_TEST("hugepages-memaccess", NONE);
51d9a2
     DO_TEST("hugepages-memaccess2", NONE);
51d9a2
-- 
51d9a2
2.18.0
51d9a2