[libvirt] [PATCH 2/4] conf: Move hugepage XML validation check out of qemu_command

Pavel Hrdina phrdina at redhat.com
Wed Jul 11 08:22:51 UTC 2018


We can safely validate the hugepage nodeset attribute at a define time.
This validation is not done for already existing domains when the daemon
is restarted.

All the changes to the tests are necessary because we move the error
from domain start into XML parse.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/conf/domain_conf.c                        | 32 +++++++++++++++++
 src/qemu/qemu_command.c                       | 34 -------------------
 .../seclabel-dynamic-none-relabel.xml         |  2 +-
 tests/qemuxml2argvtest.c                      | 16 +++++----
 .../qemuxml2xmloutdata/hugepages-pages10.xml  | 30 ----------------
 tests/qemuxml2xmloutdata/hugepages-pages4.xml |  1 -
 tests/qemuxml2xmloutdata/hugepages-pages9.xml | 31 -----------------
 .../seclabel-dynamic-none-relabel.xml         |  2 +-
 tests/qemuxml2xmltest.c                       |  3 --
 9 files changed, 43 insertions(+), 108 deletions(-)
 delete mode 100644 tests/qemuxml2xmloutdata/hugepages-pages10.xml
 delete mode 120000 tests/qemuxml2xmloutdata/hugepages-pages4.xml
 delete mode 100644 tests/qemuxml2xmloutdata/hugepages-pages9.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7396616eda..20d67e7854 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6104,6 +6104,35 @@ virDomainDefLifecycleActionValidate(const virDomainDef *def)
 }
 
 
+static int
+virDomainDefMemtuneValidate(const virDomainDef *def)
+{
+    const virDomainMemtune *mem = &(def->mem);
+    size_t i;
+    ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
+
+    for (i = 0; i < mem->nhugepages; i++) {
+        ssize_t nextBit;
+
+        if (!mem->hugepages[i].nodemask) {
+            /* This is the master hugepage to use. Skip it as it has no
+             * nodemask anyway. */
+            continue;
+        }
+
+        nextBit = virBitmapNextSetBit(mem->hugepages[i].nodemask, pos);
+        if (nextBit >= 0) {
+            virReportError(VIR_ERR_XML_DETAIL,
+                           _("hugepages: node %zd not found"),
+                           nextBit);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
+
 static int
 virDomainDefValidateInternal(const virDomainDef *def)
 {
@@ -6139,6 +6168,9 @@ virDomainDefValidateInternal(const virDomainDef *def)
     if (virDomainDefLifecycleActionValidate(def) < 0)
         return -1;
 
+    if (virDomainDefMemtuneValidate(def) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 44ae8dcef7..a0b829628a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7470,16 +7470,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
     if (!def->mem.nhugepages)
         return 0;
 
-    if (def->mem.hugepages[0].nodemask) {
-        ssize_t next_bit = virBitmapNextSetBit(def->mem.hugepages[0].nodemask, -1);
-        if (next_bit >= 0) {
-            virReportError(VIR_ERR_XML_DETAIL,
-                           _("hugepages: node %zd not found"),
-                           next_bit);
-            return -1;
-        }
-    }
-
     /* There is one special case: if user specified "huge"
      * pages of regular system pages size.
      * And there is nothing to do in this case.
@@ -7612,30 +7602,6 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
     if (!virDomainNumatuneNodesetIsAvailable(def->numa, priv->autoNodeset))
         goto cleanup;
 
-    for (i = 0; i < def->mem.nhugepages; i++) {
-        ssize_t next_bit, pos = 0;
-
-        if (!def->mem.hugepages[i].nodemask) {
-            /* This is the master hugepage to use. Skip it as it has no
-             * nodemask anyway. */
-            continue;
-        }
-
-        if (ncells) {
-            /* Fortunately, we allow only guest NUMA nodes to be continuous
-             * starting from zero. */
-            pos = ncells - 1;
-        }
-
-        next_bit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, pos);
-        if (next_bit >= 0) {
-            virReportError(VIR_ERR_XML_DETAIL,
-                           _("hugepages: node %zd not found"),
-                           next_bit);
-            goto cleanup;
-        }
-    }
-
     if (VIR_ALLOC_N(nodeBackends, ncells) < 0)
         goto cleanup;
 
diff --git a/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml b/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
index 47f253b5f7..e954250009 100644
--- a/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
+++ b/tests/qemuxml2argvdata/seclabel-dynamic-none-relabel.xml
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>262144</currentMemory>
   <memoryBacking>
     <hugepages>
-      <page size='2048' unit='KiB' nodeset='0'/>
+      <page size='2048' unit='KiB'/>
     </hugepages>
   </memoryBacking>
   <vcpu placement='static'>4</vcpu>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7236e184b8..15f9fb7b11 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -968,18 +968,20 @@ mymain(void)
             QEMU_CAPS_OBJECT_MEMORY_RAM,
             QEMU_CAPS_OBJECT_MEMORY_FILE);
     DO_TEST_PARSE_ERROR("hugepages-memaccess-invalid", NONE);
-    DO_TEST_FAILURE("hugepages-pages4",
-            QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
+    DO_TEST_PARSE_ERROR("hugepages-pages4",
+                        QEMU_CAPS_OBJECT_MEMORY_RAM,
+                        QEMU_CAPS_OBJECT_MEMORY_FILE);
     DO_TEST("hugepages-pages5", NONE);
     DO_TEST("hugepages-pages6", NONE);
     DO_TEST("hugepages-pages7",
             QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_OBJECT_MEMORY_FILE,
             QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
-    DO_TEST_FAILURE("hugepages-pages8",
-                    QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_OBJECT_MEMORY_FILE,
-                    QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
-    DO_TEST_FAILURE("hugepages-pages9", NONE);
-    DO_TEST_FAILURE("hugepages-pages10", NONE);
+    DO_TEST_PARSE_ERROR("hugepages-pages8",
+                        QEMU_CAPS_DEVICE_PC_DIMM,
+                        QEMU_CAPS_OBJECT_MEMORY_FILE,
+                        QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
+    DO_TEST_PARSE_ERROR("hugepages-pages9", NONE);
+    DO_TEST_PARSE_ERROR("hugepages-pages10", NONE);
     DO_TEST("hugepages-memaccess", QEMU_CAPS_OBJECT_MEMORY_FILE,
             QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM,
             QEMU_CAPS_NUMA);
diff --git a/tests/qemuxml2xmloutdata/hugepages-pages10.xml b/tests/qemuxml2xmloutdata/hugepages-pages10.xml
deleted file mode 100644
index 4a85ddffad..0000000000
--- a/tests/qemuxml2xmloutdata/hugepages-pages10.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-<domain type='qemu'>
-  <name>SomeDummyHugepagesGuest</name>
-  <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid>
-  <memory unit='KiB'>1048576</memory>
-  <currentMemory unit='KiB'>1048576</currentMemory>
-  <memoryBacking>
-    <hugepages>
-      <page size='2048' unit='KiB' nodeset='0'/>
-    </hugepages>
-  </memoryBacking>
-  <vcpu placement='static'>2</vcpu>
-  <os>
-    <type arch='i686' machine='pc'>hvm</type>
-    <boot dev='hd'/>
-  </os>
-  <clock offset='utc'/>
-  <on_poweroff>destroy</on_poweroff>
-  <on_reboot>restart</on_reboot>
-  <on_crash>destroy</on_crash>
-  <devices>
-    <emulator>/usr/bin/qemu-system-i686</emulator>
-    <controller type='usb' index='0'>
-      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
-    </controller>
-    <controller type='pci' index='0' model='pci-root'/>
-    <input type='mouse' bus='ps2'/>
-    <input type='keyboard' bus='ps2'/>
-    <memballoon model='none'/>
-  </devices>
-</domain>
diff --git a/tests/qemuxml2xmloutdata/hugepages-pages4.xml b/tests/qemuxml2xmloutdata/hugepages-pages4.xml
deleted file mode 120000
index 127e66e64f..0000000000
--- a/tests/qemuxml2xmloutdata/hugepages-pages4.xml
+++ /dev/null
@@ -1 +0,0 @@
-../qemuxml2argvdata/hugepages-pages4.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmloutdata/hugepages-pages9.xml b/tests/qemuxml2xmloutdata/hugepages-pages9.xml
deleted file mode 100644
index 8f380c46df..0000000000
--- a/tests/qemuxml2xmloutdata/hugepages-pages9.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<domain type='qemu'>
-  <name>SomeDummyHugepagesGuest</name>
-  <uuid>ef1bdff4-27f3-4e85-a807-5fb4d58463cc</uuid>
-  <memory unit='KiB'>1048576</memory>
-  <currentMemory unit='KiB'>1048576</currentMemory>
-  <memoryBacking>
-    <hugepages>
-      <page size='2048' unit='KiB' nodeset='0'/>
-      <page size='1048576' unit='KiB'/>
-    </hugepages>
-  </memoryBacking>
-  <vcpu placement='static'>2</vcpu>
-  <os>
-    <type arch='i686' machine='pc'>hvm</type>
-    <boot dev='hd'/>
-  </os>
-  <clock offset='utc'/>
-  <on_poweroff>destroy</on_poweroff>
-  <on_reboot>restart</on_reboot>
-  <on_crash>destroy</on_crash>
-  <devices>
-    <emulator>/usr/bin/qemu-system-i686</emulator>
-    <controller type='usb' index='0'>
-      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
-    </controller>
-    <controller type='pci' index='0' model='pci-root'/>
-    <input type='mouse' bus='ps2'/>
-    <input type='keyboard' bus='ps2'/>
-    <memballoon model='none'/>
-  </devices>
-</domain>
diff --git a/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml b/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
index 050967b4ee..bfa66b8deb 100644
--- a/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
+++ b/tests/qemuxml2xmloutdata/seclabel-dynamic-none-relabel.xml
@@ -5,7 +5,7 @@
   <currentMemory unit='KiB'>262144</currentMemory>
   <memoryBacking>
     <hugepages>
-      <page size='2048' unit='KiB' nodeset='0'/>
+      <page size='2048' unit='KiB'/>
     </hugepages>
   </memoryBacking>
   <vcpu placement='static'>4</vcpu>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index ae11fbe60c..a70516ada1 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -334,12 +334,9 @@ mymain(void)
     DO_TEST("hugepages-pages", NONE);
     DO_TEST("hugepages-pages2", NONE);
     DO_TEST("hugepages-pages3", NONE);
-    DO_TEST("hugepages-pages4", NONE);
     DO_TEST("hugepages-pages5", NONE);
     DO_TEST("hugepages-pages6", NONE);
     DO_TEST("hugepages-pages7", NONE);
-    DO_TEST("hugepages-pages9", NONE);
-    DO_TEST("hugepages-pages10", NONE);
     DO_TEST("hugepages-shared", NONE);
     DO_TEST("hugepages-memaccess", NONE);
     DO_TEST("hugepages-memaccess2", NONE);
-- 
2.17.1




More information about the libvir-list mailing list