From 773b7673a921b26d5b8e205cd9a9e3852de5467b Mon Sep 17 00:00:00 2001 From: zhangbingyi Date: Tue, 8 Oct 2019 18:29:56 +0800 Subject: [PATCH] pybind/cephfs: add cephfs python API removexattr() Signed-off-by: bingyi zhang --- src/pybind/cephfs/cephfs.pyx | 21 +++++++++++++++++++++ src/test/pybind/test_cephfs.py | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index a1a621b6c45a..882a970ff4b0 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -132,6 +132,7 @@ cdef extern from "cephfs/libcephfs.h" nogil: const void *value, size_t size, int flags) 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_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) @@ -1096,6 +1097,26 @@ cdef class LibCephFS(object): if ret < 0: raise make_ex(ret, "error in setxattr") + def removexattr(self, path, name): + """ + Remove an extended attribute of a file. + + :param path: path of the file. + :param name: name of the extended attribute to remove. + """ + self.require_state("mounted") + + name = cstr(name, 'name') + path = cstr(path, 'path') + + cdef: + char *_path = path + char *_name = name + + with nogil: + ret = ceph_removexattr(self.cluster, _path, _name) + if ret < 0: + raise make_ex(ret, "error in removexattr") def stat(self, path, follow_symlink=True): """ diff --git a/src/test/pybind/test_cephfs.py b/src/test/pybind/test_cephfs.py index 584d150eaedd..35af865f4feb 100644 --- a/src/test/pybind/test_cephfs.py +++ b/src/test/pybind/test_cephfs.py @@ -111,6 +111,9 @@ def test_xattr(): # Pass explicit size, and we'll get the value assert_equal(300, len(cephfs.getxattr("/", "user.big", 300))) + cephfs.removexattr("/", "user.key") + # user.key is already removed + assert_raises(libcephfs.NoData, cephfs.getxattr, "/", "user.key") @with_setup(setup_test) def test_rename(): -- 2.47.3