From: Yan, Zheng Date: Thu, 28 Jun 2018 06:07:53 +0000 (+0800) Subject: libcephfs: introduce ceph_get_instance_id() X-Git-Tag: v14.0.1~901^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8827b782c3cea1ed65d74ec720e1febde6904e24;p=ceph.git libcephfs: introduce ceph_get_instance_id() the function return gloabl ID of current instance Signed-off-by: "Yan, Zheng" --- diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 77ebb5107b5a8..8f524ec8f3121 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -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. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index e2d4b513731a5..39b5e3d568310 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -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); diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 049d5be664dcb..4983f2477f618 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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 diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index a795fd7344e6c..6f03e25a0e3af 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -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