mirror of https://gitee.com/openkylin/libvirt.git
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-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>
This commit is contained in:
parent
bf54784cb1
commit
1d3a9ee9da
|
@ -3479,7 +3479,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
|
||||||
} else {
|
} else {
|
||||||
/* We can have both pagesize and mem source. If that's the case,
|
/* We can have both pagesize and mem source. If that's the case,
|
||||||
* prefer hugepages as those are more specific. */
|
* 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7240,11 +7240,11 @@ qemuBuildSmpCommandLine(virCommandPtr cmd,
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
|
qemuBuildMemPathStr(const virDomainDef *def,
|
||||||
const virDomainDef *def,
|
|
||||||
virCommandPtr cmd,
|
virCommandPtr cmd,
|
||||||
qemuDomainObjPrivatePtr priv)
|
qemuDomainObjPrivatePtr priv)
|
||||||
{
|
{
|
||||||
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(priv->driver);
|
||||||
const long system_page_size = virGetSystemPageSizeKB();
|
const long system_page_size = virGetSystemPageSizeKB();
|
||||||
g_autofree char *mem_path = NULL;
|
g_autofree char *mem_path = NULL;
|
||||||
|
|
||||||
|
@ -7261,7 +7261,7 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
|
||||||
if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &mem_path) < 0)
|
if (qemuGetDomainHupageMemPath(priv->driver, def, pagesize, &mem_path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} else if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
|
} 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;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7280,7 +7280,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildMemCommandLine(virCommandPtr cmd,
|
qemuBuildMemCommandLine(virCommandPtr cmd,
|
||||||
virQEMUDriverConfigPtr cfg,
|
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
qemuDomainObjPrivatePtr priv)
|
qemuDomainObjPrivatePtr priv)
|
||||||
|
@ -7312,7 +7311,7 @@ qemuBuildMemCommandLine(virCommandPtr cmd,
|
||||||
* the hugepages and no numa node is specified.
|
* the hugepages and no numa node is specified.
|
||||||
*/
|
*/
|
||||||
if (!virDomainNumaGetNodeCount(def->numa) &&
|
if (!virDomainNumaGetNodeCount(def->numa) &&
|
||||||
qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
|
qemuBuildMemPathStr(def, cmd, priv) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OVERCOMMIT)) {
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OVERCOMMIT)) {
|
||||||
|
@ -7393,7 +7392,7 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needBackend &&
|
if (!needBackend &&
|
||||||
qemuBuildMemPathStr(cfg, def, cmd, priv) < 0)
|
qemuBuildMemPathStr(def, cmd, priv) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < ncells; i++) {
|
for (i = 0; i < ncells; i++) {
|
||||||
|
@ -9886,7 +9885,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||||
if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0)
|
if (!migrateURI && !snapshot && qemuDomainAlignMemorySizes(def) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildMemCommandLine(cmd, cfg, def, qemuCaps, priv) < 0)
|
if (qemuBuildMemCommandLine(cmd, def, qemuCaps, priv) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0)
|
if (qemuBuildSmpCommandLine(cmd, def, qemuCaps) < 0)
|
||||||
|
|
|
@ -1965,16 +1965,23 @@ qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuGetMemoryBackingDomainPath(const virDomainDef *def,
|
qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverConfigPtr cfg,
|
const virDomainDef *def,
|
||||||
char **path)
|
char **path)
|
||||||
{
|
{
|
||||||
|
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
const char *root = driver->embeddedRoot;
|
||||||
g_autofree char *shortName = NULL;
|
g_autofree char *shortName = NULL;
|
||||||
|
|
||||||
if (!(shortName = virDomainDefGetShortName(def)))
|
if (!(shortName = virDomainDefGetShortName(def)))
|
||||||
return -1;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1982,8 +1989,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qemuGetMemoryBackingPath:
|
* qemuGetMemoryBackingPath:
|
||||||
|
* @driver: the qemu driver
|
||||||
* @def: domain definition
|
* @def: domain definition
|
||||||
* @cfg: the driver config
|
|
||||||
* @alias: memory object alias
|
* @alias: memory object alias
|
||||||
* @memPath: constructed path
|
* @memPath: constructed path
|
||||||
*
|
*
|
||||||
|
@ -1993,8 +2000,8 @@ qemuGetMemoryBackingDomainPath(const virDomainDef *def,
|
||||||
* -1 otherwise (with error reported).
|
* -1 otherwise (with error reported).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
qemuGetMemoryBackingPath(const virDomainDef *def,
|
qemuGetMemoryBackingPath(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverConfigPtr cfg,
|
const virDomainDef *def,
|
||||||
const char *alias,
|
const char *alias,
|
||||||
char **memPath)
|
char **memPath)
|
||||||
{
|
{
|
||||||
|
@ -2007,7 +2014,7 @@ qemuGetMemoryBackingPath(const virDomainDef *def,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0)
|
if (qemuGetMemoryBackingDomainPath(driver, def, &domainPath) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
*memPath = g_strdup_printf("%s/%s", domainPath, alias);
|
*memPath = g_strdup_printf("%s/%s", domainPath, alias);
|
||||||
|
|
|
@ -397,10 +397,10 @@ int qemuGetDomainHupageMemPath(virQEMUDriverPtr driver,
|
||||||
unsigned long long pagesize,
|
unsigned long long pagesize,
|
||||||
char **memPath);
|
char **memPath);
|
||||||
|
|
||||||
int qemuGetMemoryBackingDomainPath(const virDomainDef *def,
|
int qemuGetMemoryBackingDomainPath(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverConfigPtr cfg,
|
const virDomainDef *def,
|
||||||
char **path);
|
char **path);
|
||||||
int qemuGetMemoryBackingPath(const virDomainDef *def,
|
int qemuGetMemoryBackingPath(virQEMUDriverPtr driver,
|
||||||
virQEMUDriverConfigPtr cfg,
|
const virDomainDef *def,
|
||||||
const char *alias,
|
const char *alias,
|
||||||
char **memPath);
|
char **memPath);
|
||||||
|
|
|
@ -3894,7 +3894,7 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver,
|
||||||
|
|
||||||
if (!build || shouldBuildMB) {
|
if (!build || shouldBuildMB) {
|
||||||
g_autofree char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0)
|
if (qemuGetMemoryBackingDomainPath(driver, vm->def, &path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
|
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm,
|
||||||
|
@ -3911,10 +3911,9 @@ qemuProcessDestroyMemoryBackingPath(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainMemoryDefPtr mem)
|
virDomainMemoryDefPtr mem)
|
||||||
{
|
{
|
||||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
|
||||||
g_autofree char *path = NULL;
|
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;
|
return -1;
|
||||||
|
|
||||||
if (unlink(path) < 0 &&
|
if (unlink(path) < 0 &&
|
||||||
|
|
Loading…
Reference in New Issue