render / rpms / libvirt

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