render / rpms / libvirt

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