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(a)redhat.com>
---
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 3a772fa3f3..6c21d28510 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;
@@ -7249,7 +7249,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 6eb655fe21..f2e3111312 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"
@@ -1894,21 +1895,29 @@ qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr
def)
}
char *
-qemuGetBaseHugepagePath(virHugeTLBFSPtr hugepage)
+qemuGetBaseHugepagePath(virQEMUDriverPtr driver,
+ virHugeTLBFSPtr hugepage)
{
+ const char *root = virQEMUDriverGetEmbedRoot(driver);
char *ret;
- ret = g_strdup_printf("%s/libvirt/qemu", hugepage->mnt_dir);
+ if (root) {
+ g_autofree char * hash = virDomainDriverHashRoot(QEMU_DRIVER_NAME, 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;
@@ -1927,11 +1936,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) {
@@ -1954,7 +1964,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 0f0eb60c69..9b282db372 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -388,12 +388,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 209f8279bd..ac866a923d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -918,7 +918,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 fcb47e8596..7035c6d426 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