[libvirt] [PATCH v3 0/5] Predictable file names for memory-backend-file

v3 of: https://www.redhat.com/archives/libvir-list/2017-October/msg01091.html diff to v2: - Pushed 1/4 and 2/4 from the original series - Split 3/4 into smaller patches Michal Privoznik (5): qemu: Set alias for memory cell in qemuBuildMemoryCellBackendStr qemu: Rename qemuProcessBuildDestroyHugepagesPath qemu: Destroy whole memory tree qemu: Use predictable file names for memory-backend-file news: Document predictable file names for memory-backend-file docs/news.xml | 11 ++ src/qemu/qemu_command.c | 9 +- src/qemu/qemu_conf.c | 55 ++++++++- src/qemu/qemu_conf.h | 9 +- src/qemu/qemu_driver.c | 17 +++ src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 137 +++++++++++++++------ src/qemu/qemu_process.h | 8 +- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 +- .../qemuxml2argv-hugepages-memaccess2.args | 9 +- 13 files changed, 218 insertions(+), 63 deletions(-) -- 2.13.6

Very soon qemuBuildMemoryBackendStr() is going to use memory cell aliases. Therefore set one. At the same time, move it a bit further - if virAsprintf() fails, there's no point in setting rest of the members. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2fe4ae380..c949afe90 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3522,12 +3522,13 @@ qemuBuildMemoryCellBackendStr(virDomainDefPtr def, unsigned long long memsize = virDomainNumaGetNodeMemorySize(def->numa, cell); + if (virAsprintf(&alias, "ram-node%zu", cell) < 0) + goto cleanup; + *backendStr = NULL; mem.size = memsize; mem.targetNode = cell; - - if (virAsprintf(&alias, "ram-node%zu", cell) < 0) - goto cleanup; + mem.info.alias = alias; if ((rc = qemuBuildMemoryBackendStr(&props, &backendType, cfg, priv->qemuCaps, def, &mem, priv->autoNodeset, false)) < 0) -- 2.13.6

At the same time, move its internals into a separate function so that they can be reused. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 76 +++++++++++++++++++++++++++++-------------------- src/qemu/qemu_process.h | 8 +++--- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e4157f631..ce63b4a4d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2077,7 +2077,7 @@ qemuDomainAttachMemory(virQEMUDriverPtr driver, priv->qemuCaps, vm->def, mem, NULL, true) < 0) goto cleanup; - if (qemuProcessBuildDestroyHugepagesPath(driver, vm, mem, true) < 0) + if (qemuProcessBuildDestroyMemoryPaths(driver, vm, mem, true) < 0) goto cleanup; if (qemuDomainNamespaceSetupMemory(driver, vm, mem) < 0) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7df440ee4..e27cd0d40 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3324,11 +3324,45 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, } +static int +qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, + virDomainDefPtr def, + const char *path, + bool build) +{ + if (build) { + if (virFileExists(path)) + return 0; + + if (virFileMakePathWithMode(path, 0700) < 0) { + virReportSystemError(errno, + _("Unable to create %s"), + path); + return -1; + } + + if (qemuSecurityDomainSetPathLabel(driver->securityManager, + def, path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to label %s"), path); + return -1; + } + } else { + if (rmdir(path) < 0 && + errno != ENOENT) + VIR_WARN("Unable to remove hugepage path: %s (errno=%d)", + path, errno); + } + + return 0; +} + + int -qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainMemoryDefPtr mem, - bool build) +qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMemoryDefPtr mem, + bool build) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); char *hugepagePath = NULL; @@ -3347,31 +3381,11 @@ qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver, if (!hugepagePath) goto cleanup; - if (build) { - if (virFileExists(hugepagePath)) { - ret = 0; - goto cleanup; - } + if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, + hugepagePath, build) < 0) + goto cleanup; - if (virFileMakePathWithMode(hugepagePath, 0700) < 0) { - virReportSystemError(errno, - _("Unable to create %s"), - hugepagePath); - goto cleanup; - } - - if (qemuSecurityDomainSetPathLabel(driver->securityManager, - vm->def, hugepagePath) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Unable to set huge path in security driver")); - goto cleanup; - } - } else { - if (rmdir(hugepagePath) < 0 && - errno != ENOENT) - VIR_WARN("Unable to remove hugepage path: %s (errno=%d)", - hugepagePath, errno); - } + VIR_FREE(hugepagePath); } } @@ -5550,7 +5564,7 @@ qemuProcessPrepareHost(virQEMUDriverPtr driver, NULL) < 0) goto cleanup; - if (qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, true) < 0) + if (qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, true) < 0) goto cleanup; /* Ensure no historical cgroup for this VM is lying around bogus @@ -6254,7 +6268,7 @@ void qemuProcessStop(virQEMUDriverPtr driver, goto endjob; } - qemuProcessBuildDestroyHugepagesPath(driver, vm, NULL, false); + qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, false); vm->def->id = -1; @@ -7112,7 +7126,7 @@ qemuProcessReconnect(void *opaque) goto cleanup; } - if (qemuProcessBuildDestroyHugepagesPath(driver, obj, NULL, true) < 0) + if (qemuProcessBuildDestroyMemoryPaths(driver, obj, NULL, true) < 0) goto error; if ((qemuDomainAssignAddresses(obj->def, priv->qemuCaps, diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 814b86d8a..cd9a72031 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -38,10 +38,10 @@ int qemuProcessStopCPUs(virQEMUDriverPtr driver, virDomainPausedReason reason, qemuDomainAsyncJob asyncJob); -int qemuProcessBuildDestroyHugepagesPath(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainMemoryDefPtr mem, - bool build); +int qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMemoryDefPtr mem, + bool build); void qemuProcessAutostartAll(virQEMUDriverPtr driver); void qemuProcessReconnectAll(virConnectPtr conn, virQEMUDriverPtr driver); -- 2.13.6

On 11/07/2017 10:51 AM, Michal Privoznik wrote:
At the same time, move its internals into a separate function so that they can be reused.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 76 +++++++++++++++++++++++++++++-------------------- src/qemu/qemu_process.h | 8 +++--- 3 files changed, 50 insertions(+), 36 deletions(-)
[...]
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7df440ee4..e27cd0d40 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3324,11 +3324,45 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, }
+static int +qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, + virDomainDefPtr def, + const char *path, + bool build) +{ + if (build) { + if (virFileExists(path)) + return 0; + + if (virFileMakePathWithMode(path, 0700) < 0) { + virReportSystemError(errno, + _("Unable to create %s"), + path); + return -1; + } + + if (qemuSecurityDomainSetPathLabel(driver->securityManager, + def, path) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to label %s"), path); + return -1; + } + } else { + if (rmdir(path) < 0 && + errno != ENOENT) + VIR_WARN("Unable to remove hugepage path: %s (errno=%d)",
This won't be hugepage specific soon... John
+ path, errno); + } + + return 0; +} + +
[...]

When removing path where huge pages are call virFileDeleteTree instead of plain rmdir(). The reason is that in the near future there's going to be more in the path than just files - some subdirs. Therefore plain rmdir() is not going to be enough. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e27cd0d40..8eef2794e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3348,7 +3348,7 @@ qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, return -1; } } else { - if (rmdir(path) < 0 && + if (virFileDeleteTree(path) < 0 && errno != ENOENT) VIR_WARN("Unable to remove hugepage path: %s (errno=%d)", path, errno); -- 2.13.6

On 11/07/2017 10:51 AM, Michal Privoznik wrote:
When removing path where huge pages are call virFileDeleteTree instead of plain rmdir(). The reason is that in the near future there's going to be more in the path than just files - some subdirs. Therefore plain rmdir() is not going to be enough.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index e27cd0d40..8eef2794e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3348,7 +3348,7 @@ qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, return -1; } } else { - if (rmdir(path) < 0 && + if (virFileDeleteTree(path) < 0 && errno != ENOENT) VIR_WARN("Unable to remove hugepage path: %s (errno=%d)", path, errno);
No way ENOENT could be returned here since virFileDeleteTree checks that first... Also virFileDeleteTree will emit a virReportSystemError on rmdir failure (that also has an ENOENT check), plus any number of other checks. Since this code path returns 0/success, then we should probably "consume" the Last error message and splat it as the VIR_WARN message or just decide to actually return an error here now. John

In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case: $memoryBackingDir/libvirt/qemu/$shortName/$alias where $shortName is result of virDomainObjGetShortName(). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_conf.c | 55 +++++++++++++++++- src/qemu/qemu_conf.h | 9 ++- src/qemu/qemu_driver.c | 17 ++++++ src/qemu/qemu_process.c | 65 ++++++++++++++++++---- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 ++- .../qemuxml2argv-hugepages-memaccess2.args | 9 ++- 10 files changed, 155 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c949afe90..c12cfec7a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3419,7 +3419,7 @@ qemuBuildMemoryBackendStr(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(cfg, &memPath) < 0) + if (qemuGetMemoryBackingPath(def, cfg, mem->info.alias, &memPath) < 0) goto cleanup; } diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f3cff1503..af503d31c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1750,9 +1750,41 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, } +int +qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path) +{ + return virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir); +} + + +int +qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path) +{ + char *shortName = NULL; + char *base = NULL; + int ret = -1; + + if (!(shortName = virDomainDefGetShortName(def)) || + qemuGetMemoryBackingBasePath(cfg, &base) < 0 || + virAsprintf(path, "%s/%s", base, shortName) < 0) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(base); + VIR_FREE(shortName); + return ret; +} + + /** * qemuGetMemoryBackingPath: + * @def: domain definition * @cfg: the driver config + * @alias: memory object alias * @memPath: constructed path * * Constructs path to memory backing dir and stores it at @memPath. @@ -1761,8 +1793,27 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, * -1 otherwise (with error reported). */ int -qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath) { - return VIR_STRDUP(*memPath, cfg->memoryBackingDir); + char *domainPath = NULL; + int ret = -1; + + if (!alias) { + /* This should never happen (TM) */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("memory device alias is not assigned")); + goto cleanup; + } + + if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 || + virAsprintf(memPath, "%s/%s", domainPath, alias) < 0) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(domainPath); + return ret; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 9d6866816..a553e30e2 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -364,6 +364,13 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def, unsigned long long pagesize, char **memPath); -int qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath); #endif /* __QEMUD_CONF_H */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bb53d78ea..47f85b9bf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -631,6 +631,7 @@ qemuStateInitialize(bool privileged, uid_t run_uid = -1; gid_t run_gid = -1; char *hugepagePath = NULL; + char *memoryBackingPath = NULL; size_t i; if (VIR_ALLOC(qemu_driver) < 0) @@ -889,6 +890,21 @@ qemuStateInitialize(bool privileged, VIR_FREE(hugepagePath); } + if (qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath) < 0) + goto error; + + if (virFileMakePath(memoryBackingPath) < 0) { + virReportSystemError(errno, + _("unable to create memory backing path %s"), + memoryBackingPath); + goto error; + } + + if (privileged && + virFileUpdatePerm(memoryBackingPath, + 0, S_IXGRP | S_IXOTH) < 0) + goto error; + if (!(qemu_driver->closeCallbacks = virCloseCallbacksNew())) goto error; @@ -946,6 +962,7 @@ qemuStateInitialize(bool privileged, virObjectUnref(conn); VIR_FREE(driverConf); VIR_FREE(hugepagePath); + VIR_FREE(memoryBackingPath); qemuStateCleanup(); return -1; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8eef2794e..eca41261a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3324,6 +3324,36 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, } +static bool +qemuProcessNeedMemoryBackingPath(virDomainDefPtr def, + virDomainMemoryDefPtr mem) +{ + size_t i; + size_t numaNodes; + + if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE || + def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + + numaNodes = virDomainNumaGetNodeCount(def->numa); + for (i = 0; i < numaNodes; i++) { + if (virDomainNumaGetNodeMemoryAccessMode(def->numa, i) + != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + } + + if (mem && + mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM && + (mem->access != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT || + (mem->targetNode >= 0 && + virDomainNumaGetNodeMemoryAccessMode(def->numa, mem->targetNode) + != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT))) + return true; + + return false; +} + + static int qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, virDomainDefPtr def, @@ -3365,33 +3395,46 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver, bool build) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - char *hugepagePath = NULL; + char *path = NULL; size_t i; - bool shouldBuild = false; + bool shouldBuildHP = false; + bool shouldBuildMB = false; int ret = -1; - if (build) - shouldBuild = qemuProcessNeedHugepagesPath(vm->def, mem); + if (build) { + shouldBuildHP = qemuProcessNeedHugepagesPath(vm->def, mem); + shouldBuildMB = qemuProcessNeedMemoryBackingPath(vm->def, mem); + } - if (!build || shouldBuild) { + if (!build || shouldBuildHP) { for (i = 0; i < cfg->nhugetlbfs; i++) { - VIR_FREE(hugepagePath); - hugepagePath = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]); + path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]); - if (!hugepagePath) + if (!path) goto cleanup; if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, - hugepagePath, build) < 0) + path, build) < 0) goto cleanup; - VIR_FREE(hugepagePath); + VIR_FREE(path); } } + if (!build || shouldBuildMB) { + if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0) + goto cleanup; + + if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, + path, build) < 0) + goto cleanup; + + VIR_FREE(path); + } + ret = 0; cleanup: - VIR_FREE(hugepagePath); + VIR_FREE(path); virObjectUnref(cfg); return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m 214 \ -smp 16,sockets=2,cores=4,threads=2 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=yes,size=112197632 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node1,\ share=no,size=112197632 \ -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args index 12f3d8ab8..fa1353259 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args @@ -11,7 +11,8 @@ QEMU_AUDIO_DRV=none \ -m 14336 \ -mem-prealloc \ -smp 8,sockets=1,cores=8,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=yes,size=15032385536 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args index 585e4d506..6f73a1b99 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args @@ -11,10 +11,12 @@ QEMU_AUDIO_DRV=none \ -m 28672 \ -mem-prealloc \ -smp 20,sockets=1,cores=8,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=no,size=15032385536 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\ share=yes,size=15032385536 \ -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args index e9a57a69e..3c352fe03 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args @@ -11,13 +11,16 @@ QEMU_AUDIO_DRV=none \ -m 43008 \ -mem-prealloc \ -smp 32,sockets=1,cores=24,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=yes,size=15032385536 \ -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\ share=yes,size=15032385536 \ -numa node,nodeid=1,cpus=2-3,memdev=ram-node1 \ --object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node2,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node2,\ share=no,size=15032385536 \ -numa node,nodeid=2,cpus=4-5,memdev=ram-node2 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args index 55db49171..d8e506c19 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args @@ -10,17 +10,20 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m size=4194304k,slots=16,maxmem=8388608k \ -smp 4,sockets=4,cores=1,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=no,size=1073741824,host-nodes=0-3,policy=bind \ -numa node,nodeid=0,cpus=0,memdev=ram-node0 \ -object memory-backend-file,id=ram-node1,prealloc=yes,\ mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824,\ host-nodes=0-3,policy=bind \ -numa node,nodeid=1,cpus=1,memdev=ram-node1 \ --object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node2,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node2,\ share=no,size=1073741824,host-nodes=0-3,policy=bind \ -numa node,nodeid=2,cpus=2,memdev=ram-node2 \ --object memory-backend-file,id=ram-node3,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node3,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node3,\ share=no,size=1073741824,host-nodes=3,policy=bind \ -numa node,nodeid=3,cpus=3,memdev=ram-node3 \ -object memory-backend-file,id=memdimm0,prealloc=yes,\ -- 2.13.6

On Tue, Nov 07, 2017 at 04:51:03PM +0100, Michal Privoznik wrote:
In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case:
$memoryBackingDir/libvirt/qemu/$shortName/$alias
where $shortName is result of virDomainObjGetShortName().
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m 214 \ -smp 16,sockets=2,cores=4,threads=2 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\
Heh, we're getting '-1' in all the paths here. Presumably this is because in the test suite we've not bothered to set the 'id' field to any value. I can't help thinking that virDomainObjGetShortName ought to return a fatal error if 'id' is still -1, as in non-test suite code, this would be indication of a significant screw up by someone trying to create names before the VM config is updated to reflect running state. This would of course mean our tests should set 'id' to a sensible value too. No need to fix for this patch though - just a curiosity to look at a later date Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

On 11/07/2017 04:57 PM, Daniel P. Berrange wrote:
On Tue, Nov 07, 2017 at 04:51:03PM +0100, Michal Privoznik wrote:
In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case:
$memoryBackingDir/libvirt/qemu/$shortName/$alias
where $shortName is result of virDomainObjGetShortName().
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m 214 \ -smp 16,sockets=2,cores=4,threads=2 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\
Heh, we're getting '-1' in all the paths here. Presumably this is because in the test suite we've not bothered to set the 'id' field to any value.
I can't help thinking that virDomainObjGetShortName ought to return a fatal error if 'id' is still -1, as in non-test suite code, this would be indication of a significant screw up by someone trying to create names before the VM config is updated to reflect running state. This would of course mean our tests should set 'id' to a sensible value too.
No need to fix for this patch though - just a curiosity to look at a later date
Yeah well, libvirt.git $ git grep "domain.*-1" tests/ | grep args | wc -l 603 I strongly vote for fixing it up separately then. Michal

On Tue, Nov 07, 2017 at 03:57:45PM +0000, Daniel P. Berrange wrote:
On Tue, Nov 07, 2017 at 04:51:03PM +0100, Michal Privoznik wrote:
In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case:
$memoryBackingDir/libvirt/qemu/$shortName/$alias
where $shortName is result of virDomainObjGetShortName().
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m 214 \ -smp 16,sockets=2,cores=4,threads=2 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\
Heh, we're getting '-1' in all the paths here. Presumably this is because in the test suite we've not bothered to set the 'id' field to any value.
I can't help thinking that virDomainObjGetShortName ought to return a fatal error if 'id' is still -1, as in non-test suite code, this would be indication of a significant screw up by someone trying to create names before the VM config is updated to reflect running state. This would of course mean our tests should set 'id' to a sensible value too.
No need to fix for this patch though - just a curiosity to look at a later date
That's actually on purpose, this should not happen in the code, if it did, then it would still function normally. We should start setting id for live XML in tests, yes. When trying to change the fact that parsing was done with _INACTIVE even for live domains, I found out that we are changing parse flags to _INACTIVE if the id for the domain is not set, but actually the fallout from that change is kind of bigger than expected and I did not bother fixing it everywhere. Dunno about Michal, though, maybe he did :)
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 11/07/2017 10:51 AM, Michal Privoznik wrote:
In some cases management application needs to allocate memory for qemu upfront and then just let qemu use that. Since we don't want to expose path for memory-backend-file anywhere in the domain XML, we can generate predictable paths. In this case:
$memoryBackingDir/libvirt/qemu/$shortName/$alias
where $shortName is result of virDomainObjGetShortName().
Just realized the s/Obj/Def/ from my previous review was missed. John
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_conf.c | 55 +++++++++++++++++- src/qemu/qemu_conf.h | 9 ++- src/qemu/qemu_driver.c | 17 ++++++ src/qemu/qemu_process.c | 65 ++++++++++++++++++---- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 ++- .../qemuxml2argv-hugepages-memaccess2.args | 9 ++- 10 files changed, 155 insertions(+), 26 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index c949afe90..c12cfec7a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3419,7 +3419,7 @@ qemuBuildMemoryBackendStr(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(cfg, &memPath) < 0) + if (qemuGetMemoryBackingPath(def, cfg, mem->info.alias, &memPath) < 0) goto cleanup; }
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f3cff1503..af503d31c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1750,9 +1750,41 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, }
+int +qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path) +{ + return virAsprintf(path, "%s/libvirt/qemu", cfg->memoryBackingDir); +} + + +int +qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path) +{ + char *shortName = NULL; + char *base = NULL; + int ret = -1; + + if (!(shortName = virDomainDefGetShortName(def)) || + qemuGetMemoryBackingBasePath(cfg, &base) < 0 || + virAsprintf(path, "%s/%s", base, shortName) < 0) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(base); + VIR_FREE(shortName); + return ret; +} + + /** * qemuGetMemoryBackingPath: + * @def: domain definition * @cfg: the driver config + * @alias: memory object alias * @memPath: constructed path * * Constructs path to memory backing dir and stores it at @memPath. @@ -1761,8 +1793,27 @@ qemuGetDomainHupageMemPath(const virDomainDef *def, * -1 otherwise (with error reported). */ int -qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath) { - return VIR_STRDUP(*memPath, cfg->memoryBackingDir); + char *domainPath = NULL; + int ret = -1; + + if (!alias) { + /* This should never happen (TM) */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("memory device alias is not assigned")); + goto cleanup; + } + + if (qemuGetMemoryBackingDomainPath(def, cfg, &domainPath) < 0 || + virAsprintf(memPath, "%s/%s", domainPath, alias) < 0) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(domainPath); + return ret; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 9d6866816..a553e30e2 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -364,6 +364,13 @@ int qemuGetDomainHupageMemPath(const virDomainDef *def, unsigned long long pagesize, char **memPath);
-int qemuGetMemoryBackingPath(virQEMUDriverConfigPtr cfg, +int qemuGetMemoryBackingBasePath(virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingDomainPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + char **path); +int qemuGetMemoryBackingPath(const virDomainDef *def, + virQEMUDriverConfigPtr cfg, + const char *alias, char **memPath); #endif /* __QEMUD_CONF_H */ diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bb53d78ea..47f85b9bf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -631,6 +631,7 @@ qemuStateInitialize(bool privileged, uid_t run_uid = -1; gid_t run_gid = -1; char *hugepagePath = NULL; + char *memoryBackingPath = NULL; size_t i;
if (VIR_ALLOC(qemu_driver) < 0) @@ -889,6 +890,21 @@ qemuStateInitialize(bool privileged, VIR_FREE(hugepagePath); }
+ if (qemuGetMemoryBackingBasePath(cfg, &memoryBackingPath) < 0) + goto error; + + if (virFileMakePath(memoryBackingPath) < 0) { + virReportSystemError(errno, + _("unable to create memory backing path %s"), + memoryBackingPath); + goto error; + } + + if (privileged && + virFileUpdatePerm(memoryBackingPath, + 0, S_IXGRP | S_IXOTH) < 0) + goto error; + if (!(qemu_driver->closeCallbacks = virCloseCallbacksNew())) goto error;
@@ -946,6 +962,7 @@ qemuStateInitialize(bool privileged, virObjectUnref(conn); VIR_FREE(driverConf); VIR_FREE(hugepagePath); + VIR_FREE(memoryBackingPath); qemuStateCleanup(); return -1; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8eef2794e..eca41261a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3324,6 +3324,36 @@ qemuProcessNeedHugepagesPath(virDomainDefPtr def, }
+static bool +qemuProcessNeedMemoryBackingPath(virDomainDefPtr def, + virDomainMemoryDefPtr mem) +{ + size_t i; + size_t numaNodes; + + if (def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE || + def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + + numaNodes = virDomainNumaGetNodeCount(def->numa); + for (i = 0; i < numaNodes; i++) { + if (virDomainNumaGetNodeMemoryAccessMode(def->numa, i) + != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT) + return true; + } + + if (mem && + mem->model == VIR_DOMAIN_MEMORY_MODEL_DIMM && + (mem->access != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT || + (mem->targetNode >= 0 && + virDomainNumaGetNodeMemoryAccessMode(def->numa, mem->targetNode) + != VIR_DOMAIN_MEMORY_ACCESS_DEFAULT))) + return true; + + return false; +} + + static int qemuProcessBuildDestroyMemoryPathsImpl(virQEMUDriverPtr driver, virDomainDefPtr def, @@ -3365,33 +3395,46 @@ qemuProcessBuildDestroyMemoryPaths(virQEMUDriverPtr driver, bool build) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - char *hugepagePath = NULL; + char *path = NULL; size_t i; - bool shouldBuild = false; + bool shouldBuildHP = false; + bool shouldBuildMB = false; int ret = -1;
- if (build) - shouldBuild = qemuProcessNeedHugepagesPath(vm->def, mem); + if (build) { + shouldBuildHP = qemuProcessNeedHugepagesPath(vm->def, mem); + shouldBuildMB = qemuProcessNeedMemoryBackingPath(vm->def, mem); + }
- if (!build || shouldBuild) { + if (!build || shouldBuildHP) { for (i = 0; i < cfg->nhugetlbfs; i++) { - VIR_FREE(hugepagePath); - hugepagePath = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]); + path = qemuGetDomainHugepagePath(vm->def, &cfg->hugetlbfs[i]);
- if (!hugepagePath) + if (!path) goto cleanup;
if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, - hugepagePath, build) < 0) + path, build) < 0) goto cleanup;
- VIR_FREE(hugepagePath); + VIR_FREE(path); } }
+ if (!build || shouldBuildMB) { + if (qemuGetMemoryBackingDomainPath(vm->def, cfg, &path) < 0) + goto cleanup; + + if (qemuProcessBuildDestroyMemoryPathsImpl(driver, vm->def, + path, build) < 0) + goto cleanup; + + VIR_FREE(path); + } + ret = 0; cleanup: - VIR_FREE(hugepagePath); + VIR_FREE(path); virObjectUnref(cfg); return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args index 5700c3413..352819429 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-memshared.args @@ -10,10 +10,12 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m 214 \ -smp 16,sockets=2,cores=4,threads=2 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=yes,size=112197632 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node1,\ share=no,size=112197632 \ -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args index 12f3d8ab8..fa1353259 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology.args @@ -11,7 +11,8 @@ QEMU_AUDIO_DRV=none \ -m 14336 \ -mem-prealloc \ -smp 8,sockets=1,cores=8,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=yes,size=15032385536 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args index 585e4d506..6f73a1b99 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args @@ -11,10 +11,12 @@ QEMU_AUDIO_DRV=none \ -m 28672 \ -mem-prealloc \ -smp 20,sockets=1,cores=8,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=no,size=15032385536 \ -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\ share=yes,size=15032385536 \ -numa node,nodeid=1,cpus=8-15,memdev=ram-node1 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args index e9a57a69e..3c352fe03 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology3.args @@ -11,13 +11,16 @@ QEMU_AUDIO_DRV=none \ -m 43008 \ -mem-prealloc \ -smp 32,sockets=1,cores=24,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node0,\ share=yes,size=15032385536 \ -numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \ --object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node1,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node1,\ share=yes,size=15032385536 \ -numa node,nodeid=1,cpus=2-3,memdev=ram-node1 \ --object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node2,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-instance-00000092/ram-node2,\ share=no,size=15032385536 \ -numa node,nodeid=2,cpus=4-5,memdev=ram-node2 \ -uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args index 55db49171..d8e506c19 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess2.args @@ -10,17 +10,20 @@ QEMU_AUDIO_DRV=none \ -M pc \ -m size=4194304k,slots=16,maxmem=8388608k \ -smp 4,sockets=4,cores=1,threads=1 \ --object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node0,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node0,\ share=no,size=1073741824,host-nodes=0-3,policy=bind \ -numa node,nodeid=0,cpus=0,memdev=ram-node0 \ -object memory-backend-file,id=ram-node1,prealloc=yes,\ mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824,\ host-nodes=0-3,policy=bind \ -numa node,nodeid=1,cpus=1,memdev=ram-node1 \ --object memory-backend-file,id=ram-node2,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node2,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node2,\ share=no,size=1073741824,host-nodes=0-3,policy=bind \ -numa node,nodeid=2,cpus=2,memdev=ram-node2 \ --object memory-backend-file,id=ram-node3,mem-path=/var/lib/libvirt/qemu/ram,\ +-object memory-backend-file,id=ram-node3,\ +mem-path=/var/lib/libvirt/qemu/ram/libvirt/qemu/-1-QEMUGuest1/ram-node3,\ share=no,size=1073741824,host-nodes=3,policy=bind \ -numa node,nodeid=3,cpus=3,memdev=ram-node3 \ -object memory-backend-file,id=memdimm0,prealloc=yes,\

Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/news.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index ef855d895..fb0ded97c 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -37,6 +37,17 @@ <section title="New features"> </section> <section title="Improvements"> + <change> + <summary> + qemu: Generate predictable paths for qemu memory backends + </summary> + <description> + In some cases management applications need to know + paths passed to memory-backend-file objects upfront. + Libvirt now generates predictable paths so applications + can prepare the files if they need to do so. + </description> + </change> </section> <section title="Bug fixes"> </section> -- 2.13.6

On 11/07/2017 10:51 AM, Michal Privoznik wrote:
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/news.xml | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/docs/news.xml b/docs/news.xml index ef855d895..fb0ded97c 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -37,6 +37,17 @@ <section title="New features"> </section> <section title="Improvements"> + <change> + <summary> + qemu: Generate predictable paths for qemu memory backends + </summary> + <description> + In some cases management applications need to know + paths passed to memory-backend-file objects upfront. + Libvirt now generates predictable paths so applications + can prepare the files if they need to do so. + </description> + </change>
Not quite sure this is in the right place... I think you added it to the comment section rather than that 3.10.0 section... At least that's what git am did for me The adjustment is rather obvious John
</section> <section title="Bug fixes"> </section>

On 11/07/2017 10:50 AM, Michal Privoznik wrote:
v3 of:
https://www.redhat.com/archives/libvir-list/2017-October/msg01091.html
diff to v2: - Pushed 1/4 and 2/4 from the original series - Split 3/4 into smaller patches
Michal Privoznik (5): qemu: Set alias for memory cell in qemuBuildMemoryCellBackendStr qemu: Rename qemuProcessBuildDestroyHugepagesPath qemu: Destroy whole memory tree qemu: Use predictable file names for memory-backend-file news: Document predictable file names for memory-backend-file
docs/news.xml | 11 ++ src/qemu/qemu_command.c | 9 +- src/qemu/qemu_conf.c | 55 ++++++++- src/qemu/qemu_conf.h | 9 +- src/qemu/qemu_driver.c | 17 +++ src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 137 +++++++++++++++------ src/qemu/qemu_process.h | 8 +- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 +- .../qemuxml2argv-hugepages-memaccess2.args | 9 +- 13 files changed, 218 insertions(+), 63 deletions(-)
There's a couple of things to clean up, but in general with those cleanups in place, Reviewed-by: John Ferlan <jferlan@redhat.com> John

On 11/07/2017 10:45 PM, John Ferlan wrote:
On 11/07/2017 10:50 AM, Michal Privoznik wrote:
v3 of:
https://www.redhat.com/archives/libvir-list/2017-October/msg01091.html
diff to v2: - Pushed 1/4 and 2/4 from the original series - Split 3/4 into smaller patches
Michal Privoznik (5): qemu: Set alias for memory cell in qemuBuildMemoryCellBackendStr qemu: Rename qemuProcessBuildDestroyHugepagesPath qemu: Destroy whole memory tree qemu: Use predictable file names for memory-backend-file news: Document predictable file names for memory-backend-file
docs/news.xml | 11 ++ src/qemu/qemu_command.c | 9 +- src/qemu/qemu_conf.c | 55 ++++++++- src/qemu/qemu_conf.h | 9 +- src/qemu/qemu_driver.c | 17 +++ src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 137 +++++++++++++++------ src/qemu/qemu_process.h | 8 +- .../qemuxml2argv-cpu-numa-memshared.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology.args | 3 +- .../qemuxml2argv-fd-memory-numa-topology2.args | 6 +- .../qemuxml2argv-fd-memory-numa-topology3.args | 9 +- .../qemuxml2argv-hugepages-memaccess2.args | 9 +- 13 files changed, 218 insertions(+), 63 deletions(-)
There's a couple of things to clean up, but in general with those cleanups in place,
Reviewed-by: John Ferlan <jferlan@redhat.com>
Thanks. Fixed all the raised points and pushed. Michal
participants (4)
-
Daniel P. Berrange
-
John Ferlan
-
Martin Kletzander
-
Michal Privoznik