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@xxxxxxxxxx> --- src/util/virfile.c | 8 ++++---- tests/virfiletest.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 2a7e87102a..666d703f99 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3534,15 +3534,16 @@ virFileIsSharedFSType(const char *path, int fstypes) { VIR_AUTOFREE(char *) dirpath = NULL; - char *p; + char *p = NULL; struct statfs sb; int statfs_ret; if (VIR_STRDUP(dirpath, path) < 0) 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 * directory we can stat. Even if we don't have 'x' * permission on any directory in the path on the NFS @@ -3563,8 +3564,7 @@ virFileIsSharedFSType(const char *path, *p = '\0'; statfs_ret = statfs(dirpath, &sb); - - } while ((statfs_ret < 0) && (p != dirpath)); + } if (statfs_ret < 0) { virReportSystemError(errno, diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 22c163f0a0..42d918aecc 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -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("mounts2.txt", "/run/user/501/gvfs/some/file", false); 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", true); + DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false); return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS; } -- 2.18.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list