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