[libvirt] [PATCH 1/2] conf: Forbid hugepages and <source type='file'/>

Michal Privoznik mprivozn at redhat.com
Mon Oct 15 12:39:26 UTC 2018


https://bugzilla.redhat.com/show_bug.cgi?id=1633562

Under <memoryBacking/> we allow users to configure various memory
backing related knobs. However, there are some combinations that
make no sense. For instance, requesting hugepages and file
allocation at the same time. Forbid this configuration then.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/conf/domain_conf.c                          | 16 ++++++++++++++--
 tests/qemuxml2argvdata/hugepages-memaccess2.xml |  1 -
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9911d56130..ef1d5caa1c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4041,7 +4041,7 @@ virDomainDefPostParseMemory(virDomainDefPtr def,
 }
 
 
-static void
+static int
 virDomainDefPostParseMemtune(virDomainDefPtr def)
 {
     size_t i;
@@ -4063,6 +4063,17 @@ virDomainDefPostParseMemtune(virDomainDefPtr def)
             }
         }
     }
+
+    if (def->mem.nhugepages &&
+        def->mem.source != VIR_DOMAIN_MEMORY_SOURCE_NONE &&
+        def->mem.source != VIR_DOMAIN_MEMORY_SOURCE_ANONYMOUS) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("unsupported combination of hugepages and source type %s"),
+                       virDomainMemorySourceTypeToString(def->mem.source));
+        return -1;
+    }
+
+    return 0;
 }
 
 
@@ -5131,7 +5142,8 @@ virDomainDefPostParseCommon(virDomainDefPtr def,
     if (virDomainDefPostParseMemory(def, data->parseFlags) < 0)
         return -1;
 
-    virDomainDefPostParseMemtune(def);
+    if (virDomainDefPostParseMemtune(def) < 0)
+        return -1;
 
     if (virDomainDefRejectDuplicateControllers(def) < 0)
         return -1;
diff --git a/tests/qemuxml2argvdata/hugepages-memaccess2.xml b/tests/qemuxml2argvdata/hugepages-memaccess2.xml
index 205f9efd92..e7f60291be 100644
--- a/tests/qemuxml2argvdata/hugepages-memaccess2.xml
+++ b/tests/qemuxml2argvdata/hugepages-memaccess2.xml
@@ -8,7 +8,6 @@
     <hugepages>
       <page size='2048' unit='KiB' nodeset='1'/>
     </hugepages>
-    <source type='file'/>
     <access mode='private'/>
   </memoryBacking>
   <vcpu placement='static'>4</vcpu>
-- 
2.18.1




More information about the libvir-list mailing list