From 7e3eae583c20869efebb1e89c8b1e4c407e0a797 Mon Sep 17 00:00:00 2001 From: zhangjiao Date: Fri, 8 Nov 2019 21:09:31 +0800 Subject: [PATCH] pybind/rados: add Ioctx::writesame() and test Ioctx::writesame() Signed-off-by: Zhang Jiao --- src/pybind/rados/rados.pyx | 34 ++++++++++++++++++++++++++++++++++ src/test/pybind/test_rados.py | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 4ad8152d1ba7..3093bb265f0e 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -214,6 +214,7 @@ cdef extern from "rados/librados.h" nogil: int rados_stat(rados_ioctx_t io, const char *o, uint64_t *psize, time_t *pmtime) int rados_write(rados_ioctx_t io, const char *oid, const char *buf, size_t len, uint64_t off) int rados_write_full(rados_ioctx_t io, const char *oid, const char *buf, size_t len) + int rados_writesame(rados_ioctx_t io, const char *oid, const char *buf, size_t data_len, size_t write_len, uint64_t off) int rados_append(rados_ioctx_t io, const char *oid, const char *buf, size_t len) int rados_read(rados_ioctx_t io, const char *oid, char *buf, size_t len, uint64_t off) int rados_remove(rados_ioctx_t io, const char *oid) @@ -2795,6 +2796,39 @@ returned %d, but should return zero on success." % (self.name, ret)) raise LogicError("Ioctx.write_full(%s): rados_write_full \ returned %d, but should return zero on success." % (self.name, ret)) + @requires(('key', str_type), ('data', bytes), ('write_len', int), ('offset', int)) + def writesame(self, key, data, write_len, offset=0): + """ + Write the same buffer multiple times + :param key: name of the object + :type key: str + :param data: data to write + :type data: bytes + :param write_len: total number of bytes to write + :type write_len: int + :param offset: byte offset in the object to begin writing at + :type offset: int + + :raises: :class:`TypeError` + :raises: :class:`LogicError` + """ + self.require_ioctx_open() + + key = cstr(key, 'key') + cdef: + char *_key = key + char *_data = data + size_t _data_len = len(data) + size_t _write_len = write_len + uint64_t _offset = offset + + with nogil: + ret = rados_writesame(self.io, _key, _data, _data_len, _write_len, _offset) + if ret < 0: + raise make_ex(ret, "Ioctx.writesame(%s): failed to write %s" + % (self.name, key)) + assert(ret == 0) + @requires(('key', str_type), ('data', bytes)) def append(self, key, data): """ diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 285d0a1a900a..8542aea87708 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -316,6 +316,10 @@ class TestIoctx(object): self.ioctx.write_full('abc', b'd') eq(self.ioctx.read('abc'), b'd') + def test_writesame(self): + self.ioctx.writesame('ob', b'rzx', 9) + eq(self.ioctx.read('ob'), b'rzxrzxrzx') + def test_append(self): self.ioctx.write('abc', b'a') self.ioctx.append('abc', b'b') -- 2.47.3