[PATCH 8/9] qemu: Make memory 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 memory:

  $memoryBackingDir/libvirt/qemu/$id-$shortName/ram-nodeN

where $memoryBackingDir is the path where QEMU mmaps() memory for
the guest (e.g. /var/lib/libvirt/qemu/ram), $id is domain ID
and $shortName is shortened version of domain name. So for
instance, the generated path may look something like this:

  /var/lib/libvirt/qemu/ram/libvirt/qemu/1-QEMUGuest/ram-node0

While in case of embed driver the following path would be
generated by default:

  $root/lib/qemu/ram/libvirt/qemu/1-QEMUGuest/ram-node0

which is not clashing with other embed drivers, we allow users to
override the default and have all embed drivers use the same
prefix. This can create clashing paths. 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 qemuGetMemoryBackingBasePath().
The rest is needed to pass driver around.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_command.c | 15 +++++++--------
 src/qemu/qemu_conf.c    | 26 +++++++++++++++++---------
 src/qemu/qemu_conf.h    | 10 +++++-----
 src/qemu/qemu_driver.c  |  2 +-
 src/qemu/qemu_process.c |  5 ++---
 5 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6c21d28510..773b93740f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3472,7 +3472,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
         } else {
             /* We can have both pagesize and mem source. If that's the case,
              * prefer hugepages as those are more specific. */
-            if (qemuGetMemoryBackingPath(def, cfg, mem->info.alias, &memPath) < 0)
+            if (qemuGetMemoryBackingPath(priv->driver, def, mem->info.alias, &memPath) < 0)
                 return -1;
         }
 
@@ -7231,11 +7231,11 @@ qemuBuildSmpCommandLine(virCommandPtr cmd,
 
 
 static int
-qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
-                    const virDomainDef *def,
+qemuBuildMemPathStr(const virDomainDef *def,
                     virCommandPtr cmd,
                     qemuDomainObjPrivatePtr priv)
 {
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
     const long system_page_size = virGetSystemPageSizeKB();
     g_autofree char *mem_path = NULL;
 
@@ -7252,7 +7252,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
         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)
+        if (qemuGetMemoryBackingPath(priv->driver, def, "ram", &mem_path) < 0)
             return -1;
     } else {
         return 0;
@@ -7271,7 +7271,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
 
 static int
 qemuBuildMemCommandLine(virCommandPtr cmd,
-                        virQEMUDriverConfigPtr cfg,
                         const virDomainDef *def,
                         virQEMUCapsPtr qemuCaps,
                         qemuDomainObjPrivatePtr priv)
@@ -7303,7 +7302,7 @@ qemuBuildMemCommandLine(virCommandPtr cmd,
      * the hugepages and no numa node is specified.
      */
     if (!virDomainNumaGetNodeCount(def->numa) &&
-        qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
+        qemuBuildMemPathStr(def, cmd, priv) < 0)
         return -1;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OVERCOMMIT)) {
@@ -7384,7 +7383,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
     }
 
     if (!needBackend &&
-        qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
+        qemuBuildMemPathStr(def, cmd, priv) < 0)
         goto cleanup;
 
     for (i = 0; i < ncells; i++) {
@@ -9877,7 +9876,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
     if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0)
         return NULL;
 
-    if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps, priv) < 0)
+    if (qemuBuildMemCommandLine(cmd, def, qemuCaps, priv) < 0)
         return NULL;
 
     if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f2e3111312..b48d5ab3fd 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1972,16 +1972,24 @@ qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
 
 
 void
-qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
+qemuGetMemoryBackingBasePath(virQEMUDriverPtr driver,
                              char **path)
 {
-    *path = g_strdup_printf("%s/libvirt/qemu", cfg->memoryBackingDir);
+    const char *root = virQEMUDriverGetEmbedRoot(driver);
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+
+    if (root) {
+        g_autofree char * hash = virDomainDriverHashRoot(QEMU_DRIVER_NAME, root);
+        *path = g_strdup_printf("%s/libvirt/%s", cfg->memoryBackingDir, hash);
+    } else {
+        *path = g_strdup_printf("%s/libvirt/qemu", cfg->memoryBackingDir);
+    }
 }
 
 
 int
-qemuGetMemoryBackingDomainPath(const virDomainDef *def,
-                               virQEMUDriverConfigPtr cfg,
+qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver,
+                               const virDomainDef *def,
                                char **path)
 {
     g_autofree char *shortName = NULL;
@@ -1990,7 +1998,7 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
     if (!(shortName = virDomainDefGetShortName(def)))
         return -1;
 
-    qemuGetMemoryBackingBasePath(cfg, &base);
+    qemuGetMemoryBackingBasePath(driver, &base);
     *path = g_strdup_printf("%s/%s", base, shortName);
 
     return 0;
@@ -1999,8 +2007,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
 
 /**
  * qemuGetMemoryBackingPath:
+ * @driver: the qemu driver
  * @def: domain definition
- * @cfg: the driver config
  * @alias: memory object alias
  * @memPath: constructed path
  *
@@ -2010,8 +2018,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
  *          -1 otherwise (with error reported).
  */
 int
-qemuGetMemoryBackingPath(const virDomainDef *def,
-                         virQEMUDriverConfigPtr cfg,
+qemuGetMemoryBackingPath(virQEMUDriverPtr driver,
+                         const virDomainDef *def,
                          const char *alias,
                          char **memPath)
 {
@@ -2024,7 +2032,7 @@ qemuGetMemoryBackingPath(const virDomainDef *def,
         return -1;
     }
 
-    if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0)
+    if (qemuGetMemoryBackingDomainPath(driver, def, &domainPath) < 0)
         return -1;
 
     *memPath = g_strdup_printf("%s/%s", domainPath, alias);
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 9b282db372..3ac2b149fd 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -399,12 +399,12 @@ int qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
                                unsigned long long pagesize,
                                char **memPath);
 
-void qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg,
+void qemuGetMemoryBackingBasePath(virQEMUDriverPtr driver,
                                   char **path);
-int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
-                                   virQEMUDriverConfigPtr cfg,
+int qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver,
+                                   const virDomainDef *def,
                                    char **path);
-int qemuGetMemoryBackingPath(const virDomainDef *def,
-                             virQEMUDriverConfigPtr cfg,
+int qemuGetMemoryBackingPath(virQEMUDriverPtr driver,
+                             const virDomainDef *def,
                              const char *alias,
                              char **memPath);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ac866a923d..2971d54772 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -935,7 +935,7 @@ qemuStateInitialize(bool privileged,
             goto error;
     }
 
-    qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath);
+    qemuGetMemoryBackingBasePath(qemu_driver, &memoryBackingPath);
 
     if (virFileMakePath(memoryBackingPath) < 0) {
         virReportSystemError(errno,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 7035c6d426..8384b4a136 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3894,7 +3894,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
 
     if (!build || shouldBuildMB) {
         g_autofree char *path = NULL;
-        if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0)
+        if (qemuGetMemoryBackingDomainPath(driver, vm->def, &path) < 0)
             return -1;
 
         if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
@@ -3911,10 +3911,9 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
                                     virDomainObjPtr vm,
                                     virDomainMemoryDefPtr mem)
 {
-    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autofree char *path = NULL;
 
-    if (qemuGetMemoryBackingPath(vm->def, cfg, mem->info.alias, &path) < 0)
+    if (qemuGetMemoryBackingPath(driver, vm->def, mem->info.alias, &path) < 0)
         return -1;
 
     if (unlink(path) < 0 &&
-- 
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