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-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@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
} 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;
}
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;
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;
static int
qemuBuildMemCommandLine(virCommandPtr cmd,
- virQEMUDriverConfigPtr cfg,
const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
qemuDomainObjPrivatePtr priv)
* 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)) {
}
if (!needBackend &&
- qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
+ qemuBuildMemPathStr(def, cmd, priv) < 0)
goto cleanup;
for (i = 0; i < ncells; i++) {
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)
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;
}
/**
* qemuGetMemoryBackingPath:
+ * @driver: the qemu driver
* @def: domain definition
- * @cfg: the driver config
* @alias: memory object alias
* @memPath: constructed path
*
* -1 otherwise (with error reported).
*/
int
-qemuGetMemoryBackingPath(const virDomainDef *def,
- virQEMUDriverConfigPtr cfg,
+qemuGetMemoryBackingPath(virQEMUDriverPtr driver,
+ const virDomainDef *def,
const char *alias,
char **memPath)
{
return -1;
}
- if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0)
+ if (qemuGetMemoryBackingDomainPath(driver, def, &domainPath) < 0)
return -1;
*memPath = g_strdup_printf("%s/%s", domainPath, alias);
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);
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,
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 &&