From 5b33fefcde39724bb746f6af66e741012dbb2f0a Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Wed, 8 Jan 2020 19:55:57 +0530 Subject: [PATCH] pybind: Add listxattr Signed-off-by: Varsha Rao --- src/pybind/cephfs/cephfs.pyx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index f568caf59fb..099262fca4d 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -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 = 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. -- 2.39.5