[PATCH v2 2/2] qemuDomainAttachMemory: Crate hugepage dir if needed

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

 



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

It may happen that a domain is started without any huge pages.
However, user might try to attach a DIMM module later. DIMM
backed by huge pages (why would somebody want to mix regular and
huge pages is beyond me). Therefore we have to create the dir if
we haven't done so far.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c |  3 +++
 src/qemu/qemu_process.c | 25 +++++++++++++++++++------
 src/qemu/qemu_process.h |  5 +++++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 96f3f4579..0b8d3d80f 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2258,6 +2258,9 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver,
                                   priv->qemuCaps, vm->def, mem, NULL, true) < 0)
         goto cleanup;
 
+    if (qemuProcessBuildDestroyHugepagesPath(driver, vm, mem, true) < 0)
+        goto cleanup;
+
     if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0)
         goto cleanup;
     teardowndevice = true;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 59cca2736..85b800da3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3284,7 +3284,8 @@ qemuProcessReconnectCheckMemAliasOrderMismatch(virDomainObjPtr vm)
 
 
 static bool
-qemuProcessNeedHugepagesPath(virDomainDefPtr def)
+qemuProcessNeedHugepagesPath(virDomainDefPtr def,
+                             virDomainMemoryDefPtr mem)
 {
     const long system_pagesize = virGetSystemPageSizeKB();
     size_t i;
@@ -3304,13 +3305,20 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def)
             return true;
     }
 
+    if (mem &&
+        mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM &&
+        mem->pagesize &&
+        mem->pagesize != system_pagesize)
+        return true;
+
     return false;
 }
 
 
-static int
+int
 qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
                                      virDomainObjPtr vm,
+                                     virDomainMemoryDefPtr mem,
                                      bool build)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@@ -3320,7 +3328,7 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
     int ret = -1;
 
     if (build)
-        shouldBuild = qemuProcessNeedHugepagesPath(vm->def);
+        shouldBuild = qemuProcessNeedHugepagesPath(vm->def, mem);
 
     if (!build || shouldBuild) {
         for (i = 0; i < cfg->nhugetlbfs; i++) {
@@ -3331,6 +3339,11 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
                 goto cleanup;
 
             if (build) {
+                if (virFileExists(hugepagePath)) {
+                    ret = 0;
+                    goto cleanup;
+                }
+
                 if (virFileMakePathWithMode(hugepagePath, 0700) < 0) {
                     virReportSystemError(errno,
                                          _("Unable to create %s"),
@@ -3504,7 +3517,7 @@ qemuProcessReconnect(void *opaque)
         goto cleanup;
     }
 
-    if (qemuProcessBuildDestroyHugepagesPath(driver, obj, true) < 0)
+    if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0)
         goto error;
 
     if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps,
@@ -5572,7 +5585,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver,
                                NULL) < 0)
         goto cleanup;
 
-    if (qemuProcessBuildDestroyHugepagesPath(driver, vm, true) < 0)
+    if (qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, true) < 0)
         goto cleanup;
 
     /* Ensure no historical cgroup for this VM is lying around bogus
@@ -6259,7 +6272,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         goto endjob;
     }
 
-    qemuProcessBuildDestroyHugepagesPath(driver, vm, false);
+    qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, false);
 
     vm->def->id = -1;
 
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index c38310b47..667d5c53d 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -38,6 +38,11 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver,
                         virDomainPausedReason reason,
                         qemuDomainAsyncJob asyncJob);
 
+int qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver,
+                                         virDomainObjPtr vm,
+                                         virDomainMemoryDefPtr mem,
+                                         bool build);
+
 void qemuProcessAutostartAll(virQEMUDriverPtr driver);
 void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver);
 
-- 
2.13.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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