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