render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
8d8641
From babe3d8cfbf85c23a71cb167008065bc63cc2fb0 Mon Sep 17 00:00:00 2001
8d8641
Message-Id: <babe3d8cfbf85c23a71cb167008065bc63cc2fb0@dist-git>
8d8641
From: Michal Privoznik <mprivozn@redhat.com>
8d8641
Date: Mon, 4 Feb 2019 10:37:50 +0100
8d8641
Subject: [PATCH] virfile: Detect ceph as shared FS
8d8641
8d8641
RHEL-7.7: https://bugzilla.redhat.com/show_bug.cgi?id=1665553
8d8641
RHEL-7.6.z: https://bugzilla.redhat.com/show_bug.cgi?id=1672178
8d8641
8d8641
Ceph can be mounted just like any other filesystem and in fact is
8d8641
a shared and cluster filesystem. The filesystem magic constant
8d8641
was taken from kernel sources as it is not in magic.h yet.
8d8641
8d8641
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8d8641
Reviewed-by: Erik Skultety <eskultet@redhat.com>
8d8641
(cherry picked from commit 6dd2a2ae6386b1d51edcc9a434f56d7f9dc2cb35)
8d8641
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
8d8641
Message-Id: <60cef73c5369ea9b37bf0663ee7f06e2605abd46.1549273057.git.mprivozn@redhat.com>
8d8641
Reviewed-by: Erik Skultety <eskultet@redhat.com>
8d8641
---
8d8641
 src/util/virfile.c            | 9 ++++++++-
8d8641
 src/util/virfile.h            | 1 +
8d8641
 src/util/virstoragefile.c     | 3 ++-
8d8641
 tests/virfiledata/mounts3.txt | 2 ++
8d8641
 tests/virfilemock.c           | 5 +++++
8d8641
 tests/virfiletest.c           | 2 ++
8d8641
 6 files changed, 20 insertions(+), 2 deletions(-)
8d8641
8d8641
diff --git a/src/util/virfile.c b/src/util/virfile.c
8d8641
index 716b55d770..471d309062 100644
8d8641
--- a/src/util/virfile.c
8d8641
+++ b/src/util/virfile.c
8d8641
@@ -3537,6 +3537,9 @@ int virFilePrintf(FILE *fp, const char *msg, ...)
8d8641
 # ifndef FUSE_SUPER_MAGIC
8d8641
 #  define FUSE_SUPER_MAGIC 0x65735546
8d8641
 # endif
8d8641
+# ifndef CEPH_SUPER_MAGIC
8d8641
+#  define CEPH_SUPER_MAGIC 0x00C36400
8d8641
+# endif
8d8641
 
8d8641
 # define PROC_MOUNTS "/proc/mounts"
8d8641
 
8d8641
@@ -3682,6 +3685,9 @@ virFileIsSharedFSType(const char *path,
8d8641
     if ((fstypes & VIR_FILE_SHFS_CIFS) &&
8d8641
         (f_type == CIFS_SUPER_MAGIC))
8d8641
         return 1;
8d8641
+    if ((fstypes & VIR_FILE_SHFS_CEPH) &&
8d8641
+        (f_type == CEPH_SUPER_MAGIC))
8d8641
+        return 1;
8d8641
 
8d8641
     return 0;
8d8641
 }
8d8641
@@ -3845,7 +3851,8 @@ int virFileIsSharedFS(const char *path)
8d8641
                                  VIR_FILE_SHFS_OCFS |
8d8641
                                  VIR_FILE_SHFS_AFS |
8d8641
                                  VIR_FILE_SHFS_SMB |
8d8641
-                                 VIR_FILE_SHFS_CIFS);
8d8641
+                                 VIR_FILE_SHFS_CIFS |
8d8641
+                                 VIR_FILE_SHFS_CEPH);
8d8641
 }
8d8641
 
8d8641
 
8d8641
diff --git a/src/util/virfile.h b/src/util/virfile.h
8d8641
index 6f1e802fde..1d16e96b59 100644
8d8641
--- a/src/util/virfile.h
8d8641
+++ b/src/util/virfile.h
8d8641
@@ -205,6 +205,7 @@ enum {
8d8641
     VIR_FILE_SHFS_AFS = (1 << 3),
8d8641
     VIR_FILE_SHFS_SMB = (1 << 4),
8d8641
     VIR_FILE_SHFS_CIFS = (1 << 5),
8d8641
+    VIR_FILE_SHFS_CEPH = (1 << 6),
8d8641
 };
8d8641
 
8d8641
 int virFileIsSharedFSType(const char *path, int fstypes) ATTRIBUTE_NONNULL(1);
8d8641
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
8d8641
index 58f67278da..0b15219c3e 100644
8d8641
--- a/src/util/virstoragefile.c
8d8641
+++ b/src/util/virstoragefile.c
8d8641
@@ -1366,7 +1366,8 @@ int virStorageFileIsClusterFS(const char *path)
8d8641
      */
8d8641
     return virFileIsSharedFSType(path,
8d8641
                                  VIR_FILE_SHFS_GFS2 |
8d8641
-                                 VIR_FILE_SHFS_OCFS);
8d8641
+                                 VIR_FILE_SHFS_OCFS |
8d8641
+                                 VIR_FILE_SHFS_CEPH);
8d8641
 }
8d8641
 
8d8641
 #ifdef LVS
8d8641
diff --git a/tests/virfiledata/mounts3.txt b/tests/virfiledata/mounts3.txt
8d8641
index 134c6e8f81..68eded048c 100644
8d8641
--- a/tests/virfiledata/mounts3.txt
8d8641
+++ b/tests/virfiledata/mounts3.txt
8d8641
@@ -33,3 +33,5 @@ host:/nfs /nfs nfs4 rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,
8d8641
 dev /nfs/blah devtmpfs rw,nosuid,relatime,size=10240k,nr_inodes=4093060,mode=755 0 0
8d8641
 host:/gv0 /gluster fuse.glusterfs rw 0 0
8d8641
 root@host:/tmp/mkdir /gluster/sshfs fuse.sshfs rw 0 0
8d8641
+192.168.0.1:/ceph/data /ceph ceph rw,noatime,name=cephfs,secret=<hidden>,acl,wsize=16777216 0 0
8d8641
+192.168.0.1,192.168.0.2,192.168.0.3:/ceph/data2 /ceph/multi ceph rw,noatime,name=cephfs,secret=<hidden>,acl,wsize=16777216 0 0
8d8641
diff --git a/tests/virfilemock.c b/tests/virfilemock.c
8d8641
index ae5c8d025a..eb5182df66 100644
8d8641
--- a/tests/virfilemock.c
8d8641
+++ b/tests/virfilemock.c
8d8641
@@ -88,6 +88,9 @@ setmntent(const char *filename, const char *type)
8d8641
 #ifndef FUSE_SUPER_MAGIC
8d8641
 # define FUSE_SUPER_MAGIC 0x65735546
8d8641
 #endif
8d8641
+#ifndef CEPH_SUPER_MAGIC
8d8641
+# define CEPH_SUPER_MAGIC 0x00c36400
8d8641
+#endif
8d8641
 
8d8641
 
8d8641
 static int
8d8641
@@ -134,6 +137,8 @@ statfs_mock(const char *mtab,
8d8641
             ftype = CIFS_SUPER_MAGIC;
8d8641
         } else if (STRPREFIX(mb.mnt_type, "fuse")) {
8d8641
             ftype = FUSE_SUPER_MAGIC;
8d8641
+        } else if (STRPREFIX(mb.mnt_type, "ceph")) {
8d8641
+            ftype = CEPH_SUPER_MAGIC;
8d8641
         } else {
8d8641
             /* Everything else is EXT4. We don't care really for other paths. */
8d8641
             ftype = EXT4_SUPER_MAGIC;
8d8641
diff --git a/tests/virfiletest.c b/tests/virfiletest.c
8d8641
index a246d601ba..972c07fdc5 100644
8d8641
--- a/tests/virfiletest.c
8d8641
+++ b/tests/virfiletest.c
8d8641
@@ -458,6 +458,8 @@ mymain(void)
8d8641
     DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/gluster/file", true);
8d8641
     DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/gluster/sshfs/file", false);
8d8641
     DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/some/symlink/file", true);
8d8641
+    DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/ceph/file", true);
8d8641
+    DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/ceph/multi/file", true);
8d8641
 
8d8641
     return ret != 0 ? EXIT_FAILURE : EXIT_SUCCESS;
8d8641
 }
8d8641
-- 
8d8641
2.20.1
8d8641