From 770942aa9ccd2553e0200f1a387a8b702a72ca7b Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 6 Feb 2014 19:25:31 -0800 Subject: [PATCH] librados: add exec to the c write operations api Nothing special needed here, just copying the input buffer and passing things through. Don't allow output data since it's not usually available for writes and unreliable when it is. Fixes: #7195 Signed-off-by: Josh Durgin --- src/include/rados/librados.h | 23 +++++++++++++++++++++-- src/librados/librados.cc | 12 ++++++++++++ src/test/librados/c_write_operations.cc | 22 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index bb25e7b184fee..ee1ab40748756 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -1859,8 +1859,27 @@ void rados_write_op_truncate(rados_write_op_t write_op, uint64_t offset); * @len length to zero */ void rados_write_op_zero(rados_write_op_t write_op, - uint64_t offset, - uint64_t len); + uint64_t offset, + uint64_t len); + +/** + * Execute an OSD class method on an object + * See rados_exec() for general description. + * + * @param write_op operation to add this action to + * @param cls the name of the class + * @param method the name of the method + * @param in_buf where to find input + * @param in_len length of in_buf in bytes + * @param prval where to store the return value from the method + */ +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); + /** * Perform a write operation synchronously * @param write_op operation to perform diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 69f91c12e19bf..b9382bef2055f 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -3142,6 +3142,18 @@ extern "C" void rados_write_op_zero(rados_write_op_t write_op, ((::ObjectOperation *)write_op)->zero(offset, len); } +extern "C" 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) +{ + bufferlist inbl; + inbl.append(in_buf, in_len); + ((::ObjectOperation *)write_op)->call(cls, method, inbl, NULL, NULL, prval); +} + extern "C" int rados_write_op_operate(rados_write_op_t write_op, rados_ioctx_t io, const char *oid, diff --git a/src/test/librados/c_write_operations.cc b/src/test/librados/c_write_operations.cc index 37f3b71f16855..d511172e2f034 100644 --- a/src/test/librados/c_write_operations.cc +++ b/src/test/librados/c_write_operations.cc @@ -115,3 +115,25 @@ TEST(LibRadosCWriteOps, Write) { ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster)); } + +TEST(LibRadosCWriteOps, Exec) { + rados_t cluster; + rados_ioctx_t ioctx; + std::string pool_name = get_temp_pool_name(); + ASSERT_EQ("", create_one_pool(pool_name, &cluster)); + rados_ioctx_create(cluster, pool_name.c_str(), &ioctx); + + int rval = 1; + rados_write_op_t op = rados_create_write_op(); + rados_write_op_exec(op, "hello", "record_hello", "test", 4, &rval); + ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0)); + rados_release_write_op(op); + ASSERT_EQ(0, rval); + + char hi[100]; + ASSERT_EQ(12, rados_read(ioctx, "test", hi, 100, 0)); + hi[12] = '\0'; + ASSERT_EQ(0, strcmp("Hello, test!", hi)); + + ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster)); +} -- 2.39.5