]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add exec to the c write operations api
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 7 Feb 2014 03:25:31 +0000 (19:25 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Feb 2014 20:34:32 +0000 (12:34 -0800)
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 <josh.durgin@inktank.com>
src/include/rados/librados.h
src/librados/librados.cc
src/test/librados/c_write_operations.cc

index bb25e7b184fee0db95bc709aaca13a8f2349dd3b..ee1ab407487564cf455848dd71c94a2cffd635cb 100644 (file)
@@ -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
index 69f91c12e19bf45f167aeb5ff5c9e6553aa52387..b9382bef2055ff4043446392f567047f002cd50b 100644 (file)
@@ -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,
index 37f3b71f16855a0705ba78b1a81daa6ae0a9751c..d511172e2f0343e0e70342f8097cc62e8e5b7476 100644 (file)
@@ -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));
+}