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