]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind: Add listxattr
authorVarsha Rao <varao@redhat.com>
Wed, 8 Jan 2020 14:25:57 +0000 (19:55 +0530)
committerVarsha Rao <varao@redhat.com>
Thu, 23 Jan 2020 13:02:44 +0000 (18:32 +0530)
Signed-off-by: Varsha Rao <varao@redhat.com>
src/pybind/cephfs/cephfs.pyx

index f568caf59fb00ae6783138e8a8e8cc2842e6b498..099262fca4d58da69c8ff3f91460655a1c815e89 100644 (file)
@@ -158,6 +158,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_getxattr(ceph_mount_info *cmount, const char *path, const char *name,
                       void *value, size_t size)
     int ceph_removexattr(ceph_mount_info *cmount, const char *path, const char *name)
+    int ceph_listxattr(ceph_mount_info *cmount, const char *path, char *list, size_t size)
     int ceph_write(ceph_mount_info *cmount, int fd, const char *buf, int64_t size, int64_t offset)
     int ceph_read(ceph_mount_info *cmount, int fd, char *buf, int64_t size, int64_t offset)
     int ceph_flock(ceph_mount_info *cmount, int fd, int operation, uint64_t owner)
@@ -1202,6 +1203,34 @@ cdef class LibCephFS(object):
         if ret < 0:
             raise make_ex(ret, "error in removexattr")
 
+    def listxattr(self, path, size=65536):
+        """
+        List the extended attribute keys set on a file.
+
+        :param path: path of the file.
+        :param size: the size of list buffer to be filled with extended attribute keys.
+        """
+        self.require_state("mounted")
+
+        path = cstr(path, 'path')
+
+        cdef:
+            char *_path = path
+            char *ret_buf = NULL
+            size_t ret_length = size
+
+        try:
+            ret_buf = <char *>realloc_chk(ret_buf, ret_length)
+            with nogil:
+                ret = ceph_listxattr(self.cluster, _path, ret_buf, ret_length)
+
+            if ret < 0:
+                raise make_ex(ret, "error in listxattr")
+
+            return ret, ret_buf[:ret]
+        finally:
+            free(ret_buf)
+
     def stat(self, path, follow_symlink=True):
         """
         Get a file's extended statistics and attributes.