[PATCH v3 08/10] qemu: Make hugepages path generation embed driver aware

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

 



So far, libvirt generates the following path for hugepages:

  $mnt/libvirt/qemu/$id-$shortName

where $mnt is the mount point of hugetlbfs corresponding to
hugepages of desired size (e.g. /dev/hugepages), $id is domain ID
and $shortName is shortened version of domain name. So for
instance, the generated path may look something like this:

  /dev/hugepages/libvirt/qemu/1-QEMUGuest

But this won't work with embed driver really, because if there
are two instances of embed driver, and they both want to start a
domain with the same name and with hugepages, both drivers will
generate the same path which is not desired. Fortunately, we can
reuse the approach for machined name generation
(v6.1.0-178-gc9bd08ee35) and include part of hash of the root in
the generated path.

Note, the important change is in qemuGetBaseHugepagePath(). The
rest is needed to pass driver around.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
Reviewed-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_command.c |  4 ++--
 src/qemu/qemu_conf.c    | 24 +++++++++++++++++-------
 src/qemu/qemu_conf.h    | 10 ++++++----
 src/qemu/qemu_driver.c  |  2 +-
 src/qemu/qemu_process.c |  2 +-
 5 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 9a0a96bdea..689796a92b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3465,7 +3465,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
             if (!priv->memPrealloc)
                 prealloc = true;
         } else if (useHugepage) {
-            if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) < 0)
+            if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &memPath) < 0)
                 return -1;
             if (!priv->memPrealloc)
                 prealloc = true;
@@ -7251,7 +7251,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
         if (!pagesize &&
             qemuBuildMemoryGetDefaultPagesize(cfg, &pagesize) < 0)
             return -1;
-        if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &mem_path) < 0)
+        if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &mem_path) < 0)
             return -1;
     } else if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
         if (qemuGetMemoryBackingPath(def, cfg, "ram", &mem_path) < 0)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index da2abb6188..713542f8cd 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -40,6 +40,7 @@
 #include "virxml.h"
 #include "virlog.h"
 #include "cpu/cpu.h"
+#include "domain_driver.h"
 #include "domain_nwfilter.h"
 #include "virfile.h"
 #include "virsocket.h"
@@ -1887,21 +1888,29 @@ qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def)
 }
 
 char *
-qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage)
+qemuGetBaseHugepagePath(virQEMUDriverPtr driver,
+                        virHugeTLBFSPtr hugepage)
 {
+    const char *root = driver->embeddedRoot;
     char *ret;
 
-    ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
+    if (root && !STRPREFIX(hugepage->mnt_dir, root)) {
+        g_autofree char * hash = virDomainDriverGenerateRootHash("qemu", root);
+        ret = g_strdup_printf("%s/libvirt/%s", hugepage->mnt_dir, hash);
+    } else {
+        ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
+    }
 
     return ret;
 }
 
 
 char *
-qemuGetDomainHugepagePath(const virDomainDef *def,
+qemuGetDomainHugepagePath(virQEMUDriverPtr driver,
+                          const virDomainDef *def,
                           virHugeTLBFSPtr hugepage)
 {
-    g_autofree char *base = qemuGetBaseHugepagePath(hugepage);
+    g_autofree char *base = qemuGetBaseHugepagePath(driver, hugepage);
     g_autofree char *domPath = virDomainDefGetShortName(def);
     char *ret = NULL;
 
@@ -1920,11 +1929,12 @@ qemuGetDomainHugepagePath(const virDomainDef *def,
  *        -1 otherwise.
  */
 int
-qemuGetDomainHupageMemPath(const virDomainDef *def,
-                           virQEMUDriverConfigPtr cfg,
+qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
+                           const virDomainDef *def,
                            unsigned long long pagesize,
                            char **memPath)
 {
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     size_t i = 0;
 
     if (!cfg->nhugetlbfs) {
@@ -1947,7 +1957,7 @@ qemuGetDomainHupageMemPath(const virDomainDef *def,
         return -1;
     }
 
-    if (!(*memPath = qemuGetDomainHugepagePath(def, &cfg->hugetlbfs[i])))
+    if (!(*memPath = qemuGetDomainHugepagePath(driver, def, &cfg->hugetlbfs[i])))
         return -1;
 
     return 0;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 8a0d220ce7..b85a9497b7 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -386,12 +386,14 @@ virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
 
 int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def);
 
-char * qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage);
-char * qemuGetDomainHugepagePath(const virDomainDef *def,
+char * qemuGetBaseHugepagePath(virQEMUDriverPtr driver,
+                               virHugeTLBFSPtr hugepage);
+char * qemuGetDomainHugepagePath(virQEMUDriverPtr driver,
+                                 const virDomainDef *def,
                                  virHugeTLBFSPtr hugepage);
 
-int qemuGetDomainHupageMemPath(const virDomainDef *def,
-                               virQEMUDriverConfigPtr cfg,
+int qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
+                               const virDomainDef *def,
                                unsigned long long pagesize,
                                char **memPath);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 716b82f8f2..33f177adbd 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -917,7 +917,7 @@ qemuStateInitialize(bool privileged,
     for (i = 0; i < cfg->nhugetlbfs; i++) {
         g_autofree char *hugepagePath = NULL;
 
-        hugepagePath = qemuGetBaseHugepagePath(&cfg->hugetlbfs[i]);
+        hugepagePath = qemuGetBaseHugepagePath(qemu_driver, &cfg->hugetlbfs[i]);
 
         if (!hugepagePath)
             goto error;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 6b9f6fb860..f9c400059f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3881,7 +3881,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
     if (!build || shouldBuildHP) {
         for (i = 0; i < cfg->nhugetlbfs; i++) {
             g_autofree char *path = NULL;
-            path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]);
+            path = qemuGetDomainHugepagePath(driver, vm->def, &cfg->hugetlbfs[i]);
 
             if (!path)
                 return -1;
-- 
2.24.1





[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