mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 03:21:19 +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;
|
virFileMakePath;
|
||||||
virFileMakePathWithMode;
|
virFileMakePathWithMode;
|
||||||
virFileMatchesNameSuffix;
|
virFileMatchesNameSuffix;
|
||||||
|
virFileMoveMount;
|
||||||
virFileNBDDeviceAssociate;
|
virFileNBDDeviceAssociate;
|
||||||
virFileOpenAs;
|
virFileOpenAs;
|
||||||
virFileOpenTty;
|
virFileOpenTty;
|
||||||
|
@ -7332,7 +7332,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
|
|||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
const unsigned long mount_flags = MS_MOVE;
|
|
||||||
char *devPath = NULL;
|
char *devPath = NULL;
|
||||||
char **devMountsPath = NULL, **devMountsSavePath = NULL;
|
char **devMountsPath = NULL, **devMountsSavePath = NULL;
|
||||||
size_t ndevMountsPath = 0, i;
|
size_t ndevMountsPath = 0, i;
|
||||||
@ -7376,13 +7375,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount(devMountsPath[i], devMountsSavePath[i],
|
if (virFileMoveMount(devMountsPath[i], devMountsSavePath[i]) < 0)
|
||||||
NULL, mount_flags, NULL) < 0) {
|
|
||||||
virReportSystemError(errno,
|
|
||||||
_("Unable to move %s mount"),
|
|
||||||
devMountsPath[i]);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemuDomainSetupAllDisks(driver, vm, devPath) < 0)
|
if (qemuDomainSetupAllDisks(driver, vm, devPath) < 0)
|
||||||
@ -7403,12 +7397,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainSetupAllRNGs(driver, vm, devPath) < 0)
|
if (qemuDomainSetupAllRNGs(driver, vm, devPath) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (mount(devPath, "/dev", NULL, mount_flags, NULL) < 0) {
|
if (virFileMoveMount(devPath, "/dev") < 0)
|
||||||
virReportSystemError(errno,
|
|
||||||
_("Failed to mount %s on /dev"),
|
|
||||||
devPath);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < ndevMountsPath; i++) {
|
for (i = 0; i < ndevMountsPath; i++) {
|
||||||
if (devMountsSavePath[i] == devPath)
|
if (devMountsSavePath[i] == devPath)
|
||||||
@ -7420,14 +7410,8 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount(devMountsSavePath[i], devMountsPath[i],
|
if (virFileMoveMount(devMountsSavePath[i], devMountsPath[i]) < 0)
|
||||||
NULL, mount_flags, NULL) < 0) {
|
|
||||||
virReportSystemError(errno,
|
|
||||||
_("Failed to mount %s on %s"),
|
|
||||||
devMountsSavePath[i],
|
|
||||||
devMountsPath[i]);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -3610,6 +3610,24 @@ virFileBindMountDevice(const char *src,
|
|||||||
return 0;
|
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) */
|
#else /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -3630,6 +3648,16 @@ virFileBindMountDevice(const char *src ATTRIBUTE_UNUSED,
|
|||||||
_("mount is not supported on this platform."));
|
_("mount is not supported on this platform."));
|
||||||
return -1;
|
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) */
|
#endif /* !defined(__linux__) || !defined(HAVE_SYS_MOUNT_H) */
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,6 +318,9 @@ int virFileSetupDev(const char *path,
|
|||||||
int virFileBindMountDevice(const char *src,
|
int virFileBindMountDevice(const char *src,
|
||||||
const char *dst);
|
const char *dst);
|
||||||
|
|
||||||
|
int virFileMoveMount(const char *src,
|
||||||
|
const char *dst);
|
||||||
|
|
||||||
int virFileGetACLs(const char *file,
|
int virFileGetACLs(const char *file,
|
||||||
void **acl);
|
void **acl);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user