mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virFileIsSharedFSType: Detect direct mount points
If the given path is already a mount point (e.g. a bind mount of a file, or simply a direct mount point of a FS), then our code fails to detect that because the first thing it does is cutting off part after last slash '/'. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
a7b4eb7d26
commit
98ca1d52a2
@ -3534,7 +3534,7 @@ virFileIsSharedFSType(const char *path,
|
|||||||
int fstypes)
|
int fstypes)
|
||||||
{
|
{
|
||||||
VIR_AUTOFREE(char *) dirpath = NULL;
|
VIR_AUTOFREE(char *) dirpath = NULL;
|
||||||
char *p;
|
char *p = NULL;
|
||||||
struct statfs sb;
|
struct statfs sb;
|
||||||
int statfs_ret;
|
int statfs_ret;
|
||||||
long long f_type = 0;
|
long long f_type = 0;
|
||||||
@ -3542,8 +3542,9 @@ virFileIsSharedFSType(const char *path,
|
|||||||
if (VIR_STRDUP(dirpath, path) < 0)
|
if (VIR_STRDUP(dirpath, path) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
do {
|
statfs_ret = statfs(dirpath, &sb);
|
||||||
|
|
||||||
|
while ((statfs_ret < 0) && (p != dirpath)) {
|
||||||
/* Try less and less of the path until we get to a
|
/* Try less and less of the path until we get to a
|
||||||
* directory we can stat. Even if we don't have 'x'
|
* directory we can stat. Even if we don't have 'x'
|
||||||
* permission on any directory in the path on the NFS
|
* permission on any directory in the path on the NFS
|
||||||
@ -3564,8 +3565,7 @@ virFileIsSharedFSType(const char *path,
|
|||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
statfs_ret = statfs(dirpath, &sb);
|
statfs_ret = statfs(dirpath, &sb);
|
||||||
|
}
|
||||||
} while ((statfs_ret < 0) && (p != dirpath));
|
|
||||||
|
|
||||||
if (statfs_ret < 0) {
|
if (statfs_ret < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
|
@ -453,8 +453,7 @@ mymain(void)
|
|||||||
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts1.txt", "/boot/vmlinuz", false);
|
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts1.txt", "/boot/vmlinuz", false);
|
||||||
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts2.txt", "/run/user/501/gvfs/some/file", false);
|
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts2.txt", "/run/user/501/gvfs/some/file", false);
|
||||||
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/file", true);
|
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/file", true);
|
||||||
/* TODO Detect bind mounts */
|
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false);
|
||||||
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", true);
|
|
||||||
|
|
||||||
return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user