mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
util: Introduce virFileMoveMount
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@redhat.com>
This commit is contained in:
parent
cd32783cd4
commit
41816751a7
@ -1605,6 +1605,7 @@ virFileMakeParentPath;
|
||||
virFileMakePath;
|
||||
virFileMakePathWithMode;
|
||||
virFileMatchesNameSuffix;
|
||||
virFileMoveMount;
|
||||
virFileNBDDeviceAssociate;
|
||||
virFileOpenAs;
|
||||
virFileOpenTty;
|
||||
|
@ -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;
|
||||
|
@ -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) */
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user