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