[PATCH v2 02/13] qemu_process: Deduplicate code in qemuProcessNeedHugepagesPath()

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

 



The aim of qemuProcessNeedHugepagesPath() is to return whether
guest needs private path inside HugeTLBFS mounts (deducted from
domain definition @def) or whether the memory device that user is
hotplugging in needs the private path (deducted from the @mem
argument). The actual creation of the path is done in the only
caller qemuProcessBuildDestroyMemoryPaths().

The rule for the first case (@def) and the second case (@mem) is
the same (domain has a DIMM device that has HP requested) and is
written twice. Move the logic into a function to deduplicate the
code.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_process.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7feb35e609..6a223e18c2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3863,6 +3863,27 @@ qemuProcessReconnectCheckMemAliasOrderMismatch(virDomainObjPtr vm)
 }
 
 
+static bool
+qemuProcessDomainMemoryDefNeedHugepagesPath(const virDomainMemoryDef *mem,
+                                            const long system_pagesize)
+{
+    switch (mem->model) {
+    case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+        return mem->pagesize &&
+            mem->pagesize != system_pagesize;
+
+    case VIR_DOMAIN_MEMORY_MODEL_NONE:
+    case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
+    case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM:
+    case VIR_DOMAIN_MEMORY_MODEL_LAST:
+        /* None of these can be backed by hugepages. */
+        return false;
+    }
+
+    return false;
+}
+
+
 static bool
 qemuProcessNeedHugepagesPath(virDomainDefPtr def,
                              virDomainMemoryDefPtr mem)
@@ -3879,16 +3900,12 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def,
     }
 
     for (i = 0; i < def->nmems; i++) {
-        if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
-            def->mems[i]->pagesize &&
-            def->mems[i]->pagesize != system_pagesize)
+        if (qemuProcessDomainMemoryDefNeedHugepagesPath(def->mems[i], system_pagesize))
             return true;
     }
 
     if (mem &&
-        mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
-        mem->pagesize &&
-        mem->pagesize != system_pagesize)
+        qemuProcessDomainMemoryDefNeedHugepagesPath(mem, system_pagesize))
         return true;
 
     return false;
-- 
2.26.2




[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