]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/cephfs: add cephfs python API removexattr() 30641/head
authorzhangbingyi <zhangbingyi@umcloud.com>
Tue, 8 Oct 2019 10:29:56 +0000 (18:29 +0800)
committerzhangbingyi <zhangbingyi@umcloud.com>
Tue, 8 Oct 2019 10:29:56 +0000 (18:29 +0800)
Signed-off-by: bingyi zhang <zhangbingyi@umcloud.com>
src/pybind/cephfs/cephfs.pyx
src/test/pybind/test_cephfs.py

index a1a621b6c45a95533930eac4147f46a985674643..882a970ff4b0d5aeb26b647da2248360e84b5a62 100644 (file)
@@ -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):
         """
index 584d150eaeddd2745bc038f0e8ae2f965fdb4e8e..35af865f4feb5ed6c972f0c65d3ce21f868ccbba 100644 (file)
@@ -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():