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