]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: introduce ceph_get_instance_id()
authorYan, Zheng <zyan@redhat.com>
Thu, 28 Jun 2018 06:07:53 +0000 (14:07 +0800)
committerYan, Zheng <zyan@redhat.com>
Thu, 28 Jun 2018 08:16:49 +0000 (16:16 +0800)
the function return gloabl ID of current instance

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/pybind/cephfs/cephfs.pyx
src/pybind/rados/rados.pyx

index 77ebb5107b5a885e7c5840e9cc315508bef79fff..8f524ec8f3121559b16bfcd9c121b09b4f859b2b 100644 (file)
@@ -327,6 +327,17 @@ int ceph_release(struct ceph_mount_info *cmount);
  */
 void ceph_shutdown(struct ceph_mount_info *cmount);
 
+/**
+ * Get a global id for current instance
+ *
+ * The handle should not be mounted. This should be called on completion of
+ * all libcephfs functions.
+ *
+ * @param cmount the mount handle
+ * @returns instance global id
+ */
+uint64_t ceph_get_instance_id(struct ceph_mount_info *cmount);
+
 /**
  * Extract the CephContext from the mount point handle.
  *
index e2d4b513731a5c15b2057f5135041c51dd3bf02b..39b5e3d56831070e9c4c225c9553a2a33987e8ed 100644 (file)
@@ -378,6 +378,13 @@ extern "C" void ceph_shutdown(struct ceph_mount_info *cmount)
   cmount = nullptr;
 }
 
+extern "C" uint64_t ceph_get_instance_id(struct ceph_mount_info *cmount)
+{
+  if (cmount->is_initialized())
+    return cmount->get_client()->get_nodeid().v;
+  return 0;
+}
+
 extern "C" int ceph_conf_read_file(struct ceph_mount_info *cmount, const char *path)
 {
   return cmount->conf_read_file(path);
index 049d5be664dcb8cb863313be942e344d419ba807..4983f2477f618ca96970eba1d05309f6007f1553 100644 (file)
@@ -112,6 +112,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_mount(ceph_mount_info *cmount, const char *root)
     int ceph_unmount(ceph_mount_info *cmount)
     int ceph_abort_conn(ceph_mount_info *cmount)
+    uint64_t ceph_get_instance_id(ceph_mount_info *cmount)
     int ceph_fstatx(ceph_mount_info *cmount, int fd, statx *stx, unsigned want, unsigned flags)
     int ceph_statx(ceph_mount_info *cmount, const char *path, statx *stx, unsigned want, unsigned flags)
     int ceph_statfs(ceph_mount_info *cmount, const char *path, statvfs *stbuf)
@@ -571,6 +572,15 @@ cdef class LibCephFS(object):
             raise make_ex(ret, "error calling ceph_abort_conn")
         self.state = "initialized"
 
+    def get_instance_id(self):
+        """
+        Get a global id for current instance
+        """
+        self.require_state("initialized", "mounted")
+        with nogil:
+            ret = ceph_get_instance_id(self.cluster)
+        return ret;
+
     def statfs(self, path):
         """
         Perform a statfs on the ceph file system.  This call fills in file system wide statistics
index a795fd7344e6c2baaecc91a2c372a415cd2ab2d7..6f03e25a0e3af9ac296386cda9174046d4eb55d5 100644 (file)
@@ -130,6 +130,7 @@ cdef extern from "rados/librados.h" nogil:
     int rados_create_with_context(rados_t *cluster, rados_config_t cct)
     int rados_connect(rados_t cluster)
     void rados_shutdown(rados_t cluster)
+    uint64_t rados_get_instance_id(rados_t cluster)
     int rados_conf_read_file(rados_t cluster, const char *path)
     int rados_conf_parse_argv_remainder(rados_t cluster, int argc, const char **argv, const char **remargv)
     int rados_conf_parse_env(rados_t cluster, const char *var)
@@ -882,6 +883,15 @@ Rados object in state %s." % self.state)
             raise make_ex(ret, "error connecting to the cluster")
         self.state = "connected"
 
+    def get_instance_id(self):
+        """
+        Get a global id for current instance
+        """
+        self.require_state("connected")
+        with nogil:
+            ret = rados_get_instance_id(self.cluster)
+        return ret;
+
     def get_cluster_stats(self):
         """
         Read usage info about the cluster