提交 1d3a9ee9 编写于 作者: M Michal Privoznik

qemu: Make memory path generation embed driver aware

So far, libvirt generates the following path for memory:

  $memoryBackingDir/$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/1-QEMUGuest/ram-node0

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

  $root/lib/qemu/ram/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-gc9bd08ee) 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: 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>
上级 bf54784c
......@@ -3479,7 +3479,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;
}
......@@ -7240,11 +7240,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;
......@@ -7261,7 +7261,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;
......@@ -7280,7 +7280,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
static int
qemuBuildMemCommandLine(virCommandPtr cmd,
virQEMUDriverConfigPtr cfg,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
qemuDomainObjPrivatePtr priv)
......@@ -7312,7 +7311,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)) {
......@@ -7393,7 +7392,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++) {
......@@ -9886,7 +9885,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)
......
......@@ -1965,16 +1965,23 @@ qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
int
qemuGetMemoryBackingDomainPath(const virDomainDef *def,
virQEMUDriverConfigPtr cfg,
qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver,
const virDomainDef *def,
char **path)
{
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
const char *root = driver->embeddedRoot;
g_autofree char *shortName = NULL;
if (!(shortName = virDomainDefGetShortName(def)))
return -1;
*path = g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortName);
if (root && !STRPREFIX(cfg->memoryBackingDir, root)) {
g_autofree char * hash = virDomainDriverGenerateRootHash("qemu", root);
*path = g_strdup_printf("%s/%s-%s", cfg->memoryBackingDir, hash, shortName);
} else {
*path = g_strdup_printf("%s/%s", cfg->memoryBackingDir, shortName);
}
return 0;
}
......@@ -1982,8 +1989,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
/**
* qemuGetMemoryBackingPath:
* @driver: the qemu driver
* @def: domain definition
* @cfg: the driver config
* @alias: memory object alias
* @memPath: constructed path
*
......@@ -1993,8 +2000,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)
{
......@@ -2007,7 +2014,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);
......
......@@ -397,10 +397,10 @@ int qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
unsigned long long pagesize,
char **memPath);
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);
......@@ -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 &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册