]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs/pybind: Add debug_get_fd_caps, debug_get_file_caps, get_cap_return_timeout
authorKotresh HR <khiremat@redhat.com>
Wed, 4 Mar 2020 12:08:49 +0000 (17:38 +0530)
committerKotresh HR <khiremat@redhat.com>
Tue, 14 Apr 2020 10:39:34 +0000 (16:09 +0530)
Fixes: https://tracker.ceph.com/issues/44171
Signed-off-by: Kotresh HR <khiremat@redhat.com>
src/pybind/cephfs/cephfs.pyx
src/test/pybind/test_cephfs.py

index 9fee58933fd5088f22b57e4bb8532487305a9b53..44658b00d8283bd518a87e3630aa699641af92ca 100644 (file)
@@ -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
index 6ea8962f24a9a7dd596391fecec3a7189c11508d..a5b08102cb7d2e59e502b5f19167e47b189a86b1 100644 (file)
@@ -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')