From: zhangjiao Date: Tue, 3 Dec 2019 04:21:57 +0000 (+0800) Subject: pybind/rados: add WriteOp::writesame() and test WriteOp::writesame() X-Git-Tag: v15.1.0~598^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=65cbfc850845bc736b9d1ee6f9f4aaf7df3df2ab;p=ceph.git pybind/rados: add WriteOp::writesame() and test WriteOp::writesame() Signed-off-by: Zhang Jiao --- diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 64611b61ca66..3a69700a5f4b 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -306,6 +306,7 @@ cdef extern from "rados/librados.h" nogil: void rados_write_op_truncate(rados_write_op_t write_op, uint64_t offset) void rados_write_op_zero(rados_write_op_t write_op, uint64_t offset, uint64_t len) void rados_write_op_exec(rados_write_op_t write_op, const char *cls, const char *method, const char *in_buf, size_t in_len, int *prval) + void rados_write_op_writesame(rados_write_op_t write_op, const char *buffer, size_t data_len, size_t write_len, uint64_t offset) void rados_read_op_omap_get_vals2(rados_read_op_t read_op, const char * start_after, const char * filter_prefix, uint64_t max_return, rados_omap_iter_t * iter, unsigned char *pmore, int * prval) void rados_read_op_omap_get_keys2(rados_read_op_t read_op, const char * start_after, uint64_t max_return, rados_omap_iter_t * iter, unsigned char *pmore, int * prval) void rados_read_op_omap_get_vals_by_keys(rados_read_op_t read_op, const char * const* keys, size_t keys_len, rados_omap_iter_t * iter, int * prval) @@ -2164,6 +2165,25 @@ cdef class WriteOp(object): with nogil: rados_write_op_exec(self.write_op, _cls, _method, _data, _data_len, NULL) + @requires(('to_write', bytes), ('write_len', int), ('offset', int)) + def writesame(self, to_write, write_len, offset=0): + """ + Write the same buffer multiple times + :param to_write: data to write + :type to_write: bytes + :param write_len: total number of bytes to write + :type len: int + :param offset: byte offset in the object to begin writing at + :type offset: int + """ + cdef: + char *_to_write = to_write + size_t _data_len = len(to_write) + size_t _write_len = write_len + uint64_t _offset = offset + with nogil: + rados_write_op_writesame(self.write_op, _to_write, _data_len, _write_len, _offset) + class WriteOpCtx(WriteOp, OpCtx): """write operation context manager""" diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 705629ce19ab..3d32a379c94f 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -538,6 +538,12 @@ class TestIoctx(object): self.ioctx.operate_write_op(write_op, "object") eq(self.ioctx.read('object'), b"Hello, ebs!") + def test_writesame_op(self): + with WriteOpCtx() as write_op: + write_op.writesame(b'rzx', 9) + self.ioctx.operate_write_op(write_op, 'abc') + eq(self.ioctx.read('abc'), b'rzxrzxrzx') + def test_get_omap_vals_by_keys(self): keys = ("1", "2", "3", "4") values = (b"aaa", b"bbb", b"ccc", b"\x04\x04\x04\x04")