提交 bf54784c 编写于 作者: M Michal Privoznik

qemu: Make hugepages path generation embed driver aware

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-gc9bd08ee) 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: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NAndrea Bolognani <abologna@redhat.com>
Reviewed-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 62975607
......@@ -3472,7 +3472,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;
......@@ -7258,7 +7258,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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -912,7 +912,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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册