From: Kotresh HR Date: Wed, 4 Mar 2020 12:08:49 +0000 (+0530) Subject: libcephfs/pybind: Add debug_get_fd_caps, debug_get_file_caps, get_cap_return_timeout X-Git-Tag: v16.1.0~2070^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4fee2e7f5c0ce2afed18c4bef407a514658f380e;p=ceph.git libcephfs/pybind: Add debug_get_fd_caps, debug_get_file_caps, get_cap_return_timeout Fixes: https://tracker.ceph.com/issues/44171 Signed-off-by: Kotresh HR --- diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index 9fee58933fd..44658b00d82 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -227,6 +227,9 @@ cdef extern from "cephfs/libcephfs.h" nogil: int ceph_get_path_replication(ceph_mount_info *cmount, const char *path) int ceph_get_pool_id(ceph_mount_info *cmount, const char *pool_name) int ceph_get_pool_replication(ceph_mount_info *cmount, int pool_id) + int ceph_debug_get_fd_caps(ceph_mount_info *cmount, int fd) + int ceph_debug_get_file_caps(ceph_mount_info *cmount, const char *path) + uint32_t ceph_get_cap_return_timeout(ceph_mount_info *cmount) class Error(Exception): @@ -2238,3 +2241,62 @@ cdef class LibCephFS(object): raise make_ex(ret, "error in get_pool_replication") return ret + + def debug_get_fd_caps(self, fd): + """ + Get the capabilities currently issued to the client given the fd. + + :param fd: the file descriptor to get issued + """ + + self.require_state("mounted") + if not isinstance(fd, int): + raise TypeError('fd must be an int') + + cdef: + int _fd = fd + + with nogil: + ret = ceph_debug_get_fd_caps(self.cluster, _fd) + if ret < 0: + raise make_ex(ret, "error in debug_get_fd_caps") + + return ret + + def debug_get_file_caps(self, path): + """ + Get the capabilities currently issued to the client given the path. + + :param path: the path of the file/directory to get the capabilities of. + """ + + self.require_state("mounted") + path = cstr(path, 'path') + + cdef: + char* _path = path + + with nogil: + ret = ceph_debug_get_file_caps(self.cluster, _path) + if ret < 0: + raise make_ex(ret, "error in debug_get_file_caps") + + return ret + + def get_cap_return_timeout(self): + """ + Get the amount of time that the client has to return caps + + In the event that a client does not return its caps, the MDS may blacklist + it after this timeout. Applications should check this value and ensure + that they set the delegation timeout to a value lower than this. + """ + + self.require_state("mounted") + + with nogil: + ret = ceph_get_cap_return_timeout(self.cluster) + if ret < 0: + raise make_ex(ret, "error in get_cap_return_timeout") + + return ret diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index 6ea8962f24a..a5b08102cb7 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -575,3 +575,14 @@ def test_replication(): assert_equal(cnt, 3) cephfs.close(fd) cephfs.unlink(b'/file-rep') + +@with_setup(setup_test) +def test_caps(): + fd = cephfs.open(b'/file-caps', 'w', 0o755) + timeout = cephfs.get_cap_return_timeout() + assert_equal(timeout, 300) + fd_caps = cephfs.debug_get_fd_caps(fd) + file_caps = cephfs.debug_get_file_caps(b'/file-caps') + assert_equal(fd_caps, file_caps) + cephfs.close(fd) + cephfs.unlink(b'/file-caps')