]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/rados: add WriteOp::set_xattr()
authorzhangjiao <zhangjiao@cmss.chinamobile.com>
Sat, 23 Nov 2019 09:27:41 +0000 (17:27 +0800)
committerzhangjiao <zhangjiao@cmss.chinamobile.com>
Mon, 2 Dec 2019 10:16:24 +0000 (18:16 +0800)
Signed-off-by: Zhang Jiao <zhangjiao@cmss.chinamobile.com>
src/pybind/rados/rados.pyx

index 4ad8152d1ba73379e9ec7aa713d5401d5e090230..36f41aaf6cbce3b0fcbf92df4c6e755cf97bd1cb 100644 (file)
@@ -294,7 +294,8 @@ cdef extern from "rados/librados.h" nogil:
     void rados_write_op_omap_rm_keys(rados_write_op_t write_op, const char * const* keys, size_t keys_len)
     void rados_write_op_omap_clear(rados_write_op_t write_op)
     void rados_write_op_set_flags(rados_write_op_t write_op, int flags)
-
+    void rados_write_op_setxattr(rados_write_op_t write_op, const char *name, const char *value, size_t value_len)
+    
     void rados_write_op_create(rados_write_op_t write_op, int exclusive, const char *category)
     void rados_write_op_append(rados_write_op_t write_op, const char *buffer, size_t len)
     void rados_write_op_write_full(rados_write_op_t write_op, const char *buffer, size_t len)
@@ -2046,6 +2047,23 @@ cdef class WriteOp(object):
         with nogil:
             rados_write_op_set_flags(self.write_op, _flags)
 
+    @requires(('xattr_name', str_type), ('xattr_value', bytes))
+    def set_xattr(self, xattr_name, xattr_value):
+        """
+        Set an extended attribute on an object.
+        :param xattr_name: name of the xattr
+        :type xattr_name: str
+        :param xattr_value: buffer to set xattr to
+        :type xattr_value: bytes
+        """
+        xattr_name = cstr(xattr_name, 'xattr_name')
+        cdef:
+            char *_xattr_name = xattr_name
+            char *_xattr_value = xattr_value
+            size_t _xattr_value_len = len(xattr_value)
+        with nogil:
+            rados_write_op_setxattr(self.write_op, _xattr_name, _xattr_value, _xattr_value_len)
+
     @requires(('to_write', bytes))
     def append(self, to_write):
         """