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