This is a simple wrapper over mount(). However, not every system out there is capable of moving a mount point. Therefore, instead of having to deal with this fact in all the places of our code we can have a simple wrapper and deal with this fact at just one place. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 22 +++------------------- src/util/virfile.c | 28 ++++++++++++++++++++++++++++ src/util/virfile.h | 3 +++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d02d23b35..70ed87b95 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1605,6 +1605,7 @@ virFileMakeParentPath; virFileMakePath; virFileMakePathWithMode; virFileMatchesNameSuffix; +virFileMoveMount; virFileNBDDeviceAssociate; virFileOpenAs; virFileOpenTty; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 473d0c1a2..8602f01c7 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7332,7 +7332,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - const unsigned long mount_flags = MS_MOVE; char *devPath = NULL; char **devMountsPath = NULL, **devMountsSavePath = NULL; size_t ndevMountsPath = 0, i; @@ -7376,13 +7375,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, goto cleanup; } - if (mount(devMountsPath[i], devMountsSavePath[i], - NULL, mount_flags, NULL) < 0) { - virReportSystemError(errno, - _("Unable to move %s mount"), - devMountsPath[i]); + if (virFileMoveMount(devMountsPath[i], devMountsSavePath[i]) < 0) goto cleanup; - } } if (qemuDomainSetupAllDisks(driver, vm, devPath) < 0) @@ -7403,12 +7397,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, if (qemuDomainSetupAllRNGs(driver, vm, devPath) < 0) goto cleanup; - if (mount(devPath, "/dev", NULL, mount_flags, NULL) < 0) { - virReportSystemError(errno, - _("Failed to mount %s on /dev"), - devPath); + if (virFileMoveMount(devPath, "/dev") < 0) goto cleanup; - } for (i = 0; i < ndevMountsPath; i++) { if (devMountsSavePath[i] == devPath) @@ -7420,14 +7410,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, goto cleanup; } - if (mount(devMountsSavePath[i], devMountsPath[i], - NULL, mount_flags, NULL) < 0) { - virReportSystemError(errno, - _("Failed to mount %s on %s"), - devMountsSavePath[i], - devMountsPath[i]); + if (virFileMoveMount(devMountsSavePath[i], devMountsPath[i]) < 0) goto cleanup; - } } ret = 0; diff --git a/src/util/virfile.c b/src/util/virfile.c index 99157be16..bf8099e34 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3610,6 +3610,24 @@ virFileBindMountDevice(const char *src, return 0; } + +int +virFileMoveMount(const char *src, + const char *dst) +{ + const unsigned long mount_flags = MS_MOVE; + + if (mount(src, dst, NULL, mount_flags, NULL) < 0) { + virReportSystemError(errno, + _("Unable to move %s mount to %s"), + src, dst); + return -1; + } + + return 0; +} + + #else /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */ int @@ -3630,6 +3648,16 @@ virFileBindMountDevice(const char *src ATTRIBUTE_UNUSED, _("mount is not supported on this platform.")); return -1; } + + +int +virFileMoveMount(const char *src ATTRIBUTE_UNUSED, + const char *dst ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, "%s", + _("mount move is not supported on this platform.")); + return -1; +} #endif /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */ diff --git a/src/util/virfile.h b/src/util/virfile.h index 571e5bdc8..0343acd5b 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -318,6 +318,9 @@ int virFileSetupDev(const char *path, int virFileBindMountDevice(const char *src, const char *dst); +int virFileMoveMount(const char *src, + const char *dst); + int virFileGetACLs(const char *file, void **acl); -- 2.11.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list