c873f9
From 945cc03b42ec947876cda10dff1bf76a446abbf1 Mon Sep 17 00:00:00 2001
c873f9
Message-Id: <945cc03b42ec947876cda10dff1bf76a446abbf1@dist-git>
c873f9
From: Michal Privoznik <mprivozn@redhat.com>
c873f9
Date: Wed, 3 Oct 2018 17:04:13 +0200
c873f9
Subject: [PATCH] virFileIsSharedFSType: Check for fuse.glusterfs too
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
GlusterFS is typically safe when it comes to migration. It's a
c873f9
network FS after all. However, it can be mounted via FUSE driver
c873f9
they provide. If that is the case we fail to identify it and
c873f9
think migration is not safe and require VIR_MIGRATE_UNSAFE flag.
c873f9
c873f9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c873f9
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
c873f9
(cherry picked from commit 478da65fb46c866973886848ae17f1e16199a77d)
c873f9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c873f9
---
c873f9
 src/util/virfile.c | 77 ++++++++++++++++++++++++++++++++++++++++++++--
c873f9
 1 file changed, 75 insertions(+), 2 deletions(-)
c873f9
c873f9
diff --git a/src/util/virfile.c b/src/util/virfile.c
c873f9
index 378d03ecf0..c87e26bf5b 100644
c873f9
--- a/src/util/virfile.c
c873f9
+++ b/src/util/virfile.c
c873f9
@@ -3534,6 +3534,76 @@ int virFilePrintf(FILE *fp, const char *msg, ...)
c873f9
 # ifndef HUGETLBFS_MAGIC
c873f9
 #  define HUGETLBFS_MAGIC 0x958458f6
c873f9
 # endif
c873f9
+# ifndef FUSE_SUPER_MAGIC
c873f9
+#  define FUSE_SUPER_MAGIC 0x65735546
c873f9
+# endif
c873f9
+
c873f9
+# define PROC_MOUNTS "/proc/mounts"
c873f9
+
c873f9
+static int
c873f9
+virFileIsSharedFixFUSE(const char *path,
c873f9
+                       long *f_type)
c873f9
+{
c873f9
+    char *dirpath = NULL;
c873f9
+    const char **mounts = NULL;
c873f9
+    size_t nmounts = 0;
c873f9
+    char *p;
c873f9
+    FILE *f = NULL;
c873f9
+    struct mntent mb;
c873f9
+    char mntbuf[1024];
c873f9
+    int ret = -1;
c873f9
+
c873f9
+    if (VIR_STRDUP(dirpath, path) < 0)
c873f9
+        return -1;
c873f9
+
c873f9
+    if (!(f = setmntent(PROC_MOUNTS, "r"))) {
c873f9
+        virReportSystemError(errno,
c873f9
+                             _("Unable to open %s"),
c873f9
+                             PROC_MOUNTS);
c873f9
+        goto cleanup;
c873f9
+    }
c873f9
+
c873f9
+    while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
c873f9
+        if (STRNEQ("fuse.glusterfs", mb.mnt_type))
c873f9
+            continue;
c873f9
+
c873f9
+        if (VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mb.mnt_dir) < 0)
c873f9
+            goto cleanup;
c873f9
+    }
c873f9
+
c873f9
+    /* Add NULL sentinel so that this is a virStringList */
c873f9
+    if (VIR_REALLOC_N(mounts, nmounts + 1) < 0)
c873f9
+        goto cleanup;
c873f9
+    mounts[nmounts] = NULL;
c873f9
+
c873f9
+    do {
c873f9
+        if ((p = strrchr(dirpath, '/')) == NULL) {
c873f9
+            virReportSystemError(EINVAL,
c873f9
+                                 _("Invalid relative path '%s'"), path);
c873f9
+            goto cleanup;
c873f9
+        }
c873f9
+
c873f9
+        if (p == dirpath)
c873f9
+            *(p+1) = '\0';
c873f9
+        else
c873f9
+            *p = '\0';
c873f9
+
c873f9
+        if (virStringListHasString(mounts, dirpath)) {
c873f9
+            VIR_DEBUG("Found gluster FUSE mountpoint=%s for path=%s. "
c873f9
+                      "Fixing shared FS type", dirpath, path);
c873f9
+            *f_type = GFS2_MAGIC;
c873f9
+            break;
c873f9
+        }
c873f9
+    } while (p != dirpath);
c873f9
+
c873f9
+    ret = 0;
c873f9
+ cleanup:
c873f9
+    endmntent(f);
c873f9
+    VIR_FREE(mounts);
c873f9
+    VIR_FREE(dirpath);
c873f9
+    return ret;
c873f9
+}
c873f9
+
c873f9
 
c873f9
 int
c873f9
 virFileIsSharedFSType(const char *path,
c873f9
@@ -3581,6 +3651,11 @@ virFileIsSharedFSType(const char *path,
c873f9
         return -1;
c873f9
     }
c873f9
 
c873f9
+    if (sb.f_type == FUSE_SUPER_MAGIC) {
c873f9
+        VIR_DEBUG("Found FUSE mount for path=%s. Trying to fix it", path);
c873f9
+        virFileIsSharedFixFUSE(path, (long *) &sb.f_type);
c873f9
+    }
c873f9
+
c873f9
     VIR_DEBUG("Check if path %s with FS magic %lld is shared",
c873f9
               path, (long long int)sb.f_type);
c873f9
 
c873f9
@@ -3673,8 +3748,6 @@ virFileGetDefaultHugepageSize(unsigned long long *size)
c873f9
     return ret;
c873f9
 }
c873f9
 
c873f9
-# define PROC_MOUNTS "/proc/mounts"
c873f9
-
c873f9
 int
c873f9
 virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
c873f9
                      size_t *ret_nfs)
c873f9
-- 
c873f9
2.19.0
c873f9