From 5d198c2b2c6ef1caca95c6188d939ac6324eb073 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 6 Jan 2017 10:55:37 +0100 Subject: [PATCH] qemuDomainCreateNamespace: move mkdir to qemuDomainBuildNamespace Again, there is no need to create /var/lib/libvirt/$domain.* directories in CreateNamespace(). It is sufficient to create them as soon as we need them which is in BuildNamespace. This way we don't leave them around for the whole lifetime of domain. Signed-off-by: Michal Privoznik --- src/qemu/qemu_domain.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 54481214c1..137d68e47b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7369,6 +7369,13 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, if (devMountsSavePath[i] == devPath) continue; + if (virFileMakePath(devMountsSavePath[i]) < 0) { + virReportSystemError(errno, + _("Failed to create %s"), + devMountsSavePath[i]); + goto cleanup; + } + if (mount(devMountsPath[i], devMountsSavePath[i], NULL, mount_flags, NULL) < 0) { virReportSystemError(errno, @@ -7426,6 +7433,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, ret = 0; cleanup: virObjectUnref(cfg); + for (i = 0; i < ndevMountsPath; i++) + rmdir(devMountsSavePath[i]); virStringListFreeCount(devMountsPath, ndevMountsPath); virStringListFreeCount(devMountsSavePath, ndevMountsPath); return ret; @@ -7438,8 +7447,6 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); int ret = -1; - char **devMountsSavePath = NULL; - size_t ndevMountsSavePath = 0, i; if (!virBitmapIsBitSet(cfg->namespaces, QEMU_DOMAIN_NS_MOUNT) || !virQEMUDriverIsPrivileged(driver)) { @@ -7447,30 +7454,11 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, goto cleanup; } - if (qemuDomainGetPreservedMounts(driver, vm, - NULL, &devMountsSavePath, - &ndevMountsSavePath) < 0) - goto cleanup; - - for (i = 0; i < ndevMountsSavePath; i++) { - if (virFileMakePath(devMountsSavePath[i]) < 0) { - virReportSystemError(errno, - _("Failed to create %s"), - devMountsSavePath[i]); - goto cleanup; - } - } - if (qemuDomainEnableNamespace(vm, QEMU_DOMAIN_NS_MOUNT) < 0) goto cleanup; ret = 0; cleanup: - if (ret < 0) { - for (i = 0; i < ndevMountsSavePath; i++) - rmdir(devMountsSavePath[i]); - } - virStringListFreeCount(devMountsSavePath, ndevMountsSavePath); virObjectUnref(cfg); return ret; } -- GitLab