|
|
a5a3f0 |
From 691b33e397a7bd726160bc74202c8d0fdd944892 Mon Sep 17 00:00:00 2001
|
|
|
a5a3f0 |
Message-Id: <691b33e397a7bd726160bc74202c8d0fdd944892@dist-git>
|
|
|
a5a3f0 |
From: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a5a3f0 |
Date: Wed, 10 Oct 2018 17:25:55 +0200
|
|
|
a5a3f0 |
Subject: [PATCH] virFileIsSharedFSType: Detect direct mount points
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
RHEL-7.7: https://bugzilla.redhat.com/show_bug.cgi?id=1632711
|
|
|
a5a3f0 |
RHEL-8.0: https://bugzilla.redhat.com/show_bug.cgi?id=1634782
|
|
|
a5a3f0 |
RHEL-7.6.z: https://bugzilla.redhat.com/show_bug.cgi?id=1635705
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
If the given path is already a mount point (e.g. a bind mount of
|
|
|
a5a3f0 |
a file, or simply a direct mount point of a FS), then our code
|
|
|
a5a3f0 |
fails to detect that because the first thing it does is cutting
|
|
|
a5a3f0 |
off part after last slash '/'.
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
Conflicts:
|
|
|
a5a3f0 |
src/util/virfile.c - VIR_AUTOFREE() stuff
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a5a3f0 |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
a5a3f0 |
(cherry picked from commit 98ca1d52a2a871e1c068504450b4dc15db063ef4)
|
|
|
a5a3f0 |
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a5a3f0 |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
a5a3f0 |
---
|
|
|
a5a3f0 |
src/util/virfile.c | 9 +++++----
|
|
|
a5a3f0 |
tests/virfiletest.c | 3 +--
|
|
|
a5a3f0 |
2 files changed, 6 insertions(+), 6 deletions(-)
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
diff --git a/src/util/virfile.c b/src/util/virfile.c
|
|
|
a5a3f0 |
index 46466ed136..05ecf7bf21 100644
|
|
|
a5a3f0 |
--- a/src/util/virfile.c
|
|
|
a5a3f0 |
+++ b/src/util/virfile.c
|
|
|
a5a3f0 |
@@ -3609,7 +3609,8 @@ int
|
|
|
a5a3f0 |
virFileIsSharedFSType(const char *path,
|
|
|
a5a3f0 |
int fstypes)
|
|
|
a5a3f0 |
{
|
|
|
a5a3f0 |
- char *dirpath, *p;
|
|
|
a5a3f0 |
+ char *dirpath;
|
|
|
a5a3f0 |
+ char *p = NULL;
|
|
|
a5a3f0 |
struct statfs sb;
|
|
|
a5a3f0 |
int statfs_ret;
|
|
|
a5a3f0 |
long long f_type = 0;
|
|
|
a5a3f0 |
@@ -3617,8 +3618,9 @@ virFileIsSharedFSType(const char *path,
|
|
|
a5a3f0 |
if (VIR_STRDUP(dirpath, path) < 0)
|
|
|
a5a3f0 |
return -1;
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
- do {
|
|
|
a5a3f0 |
+ statfs_ret = statfs(dirpath, &sb);
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
+ while ((statfs_ret < 0) && (p != dirpath)) {
|
|
|
a5a3f0 |
/* Try less and less of the path until we get to a
|
|
|
a5a3f0 |
* directory we can stat. Even if we don't have 'x'
|
|
|
a5a3f0 |
* permission on any directory in the path on the NFS
|
|
|
a5a3f0 |
@@ -3640,8 +3642,7 @@ virFileIsSharedFSType(const char *path,
|
|
|
a5a3f0 |
*p = '\0';
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
statfs_ret = statfs(dirpath, &sb);
|
|
|
a5a3f0 |
-
|
|
|
a5a3f0 |
- } while ((statfs_ret < 0) && (p != dirpath));
|
|
|
a5a3f0 |
+ }
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
VIR_FREE(dirpath);
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
|
|
|
a5a3f0 |
index 85f22063fe..80ea34bfa4 100644
|
|
|
a5a3f0 |
--- a/tests/virfiletest.c
|
|
|
a5a3f0 |
+++ b/tests/virfiletest.c
|
|
|
a5a3f0 |
@@ -454,8 +454,7 @@ mymain(void)
|
|
|
a5a3f0 |
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts1.txt", "/boot/vmlinuz", false);
|
|
|
a5a3f0 |
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts2.txt", "/run/user/501/gvfs/some/file", false);
|
|
|
a5a3f0 |
DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/file", true);
|
|
|
a5a3f0 |
- /* TODO Detect bind mounts */
|
|
|
a5a3f0 |
- DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", true);
|
|
|
a5a3f0 |
+ DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false);
|
|
|
a5a3f0 |
|
|
|
a5a3f0 |
return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
|
a5a3f0 |
}
|
|
|
a5a3f0 |
--
|
|
|
a5a3f0 |
2.19.1
|
|
|
a5a3f0 |
|