]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add global op flags to the c api
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 7 Feb 2014 03:12:58 +0000 (19:12 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Feb 2014 20:34:32 +0000 (12:34 -0800)
The c++ api did not include these in the sync versions of the calls,
so add a flags argument to the IoCtxImpl functions for those, with
default arguments to avoid changing the many many callers.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/include/rados/librados.h
src/librados/IoCtxImpl.cc
src/librados/IoCtxImpl.h
src/librados/librados.cc
src/test/librados/c_write_operations.cc

index 4b4cd45e1e1b3770ff96dbb452357797ca1e9668..01c09fe681e2e60e6e3bb72f7cafa0d7ea5a23fb 100644 (file)
@@ -79,6 +79,26 @@ enum {
 /** @endcond */
 /** @} */
 
+/**
+ * @defgroup librados_h_operation_flags
+ * Flags for rados_read_op_opeprate(), rados_write_op_operate(),
+ * rados_aio_read_op_operate(), and rados_aio_write_op_operate().
+ * See librados.hpp for details.
+ * @{
+ */
+/** @cond TODO_enums_not_yet_in_asphyxiate */
+enum {
+  LIBRADOS_OPERATION_NOFLAG             = 0,
+  LIBRADOS_OPERATION_BALANCE_READS      = 1,
+  LIBRADOS_OPERATION_LOCALIZE_READS     = 2,
+  LIBRADOS_OPERATION_ORDER_READS_WRITES = 4,
+  LIBRADOS_OPERATION_IGNORE_CACHE       = 8,
+  LIBRADOS_OPERATION_SKIPRWLOCKS        = 16,
+  LIBRADOS_OPERATION_IGNORE_OVERLAY     = 32,
+};
+/** @endcond */
+/** @} */
+
 /*
  * snap id contants
  */
@@ -1831,11 +1851,13 @@ void rados_write_op_zero(rados_write_op_t write_op,
  * @io the ioctx that the object is in
  * @oid the object id
  * @mtime the time to set the mtime to, NULL for the current time
+ * @flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
  */
 int rados_write_op_operate(rados_write_op_t write_op,
-                           rados_ioctx_t io,
-                           const char *oid,
-                           time_t *mtime);
+                          rados_ioctx_t io,
+                          const char *oid,
+                          time_t *mtime,
+                          int flags);
 /**
  * Perform a write operation asynchronously
  * @param write_op operation to perform
@@ -1843,12 +1865,14 @@ int rados_write_op_operate(rados_write_op_t write_op,
  * @param completion what to do when operation has been attempted
  * @oid the object id
  * @mtime the time to set the mtime to, NULL for the current time
+ * @flags flags to apply to the entire operation (LIBRADOS_OPERATION_*)
  */
 int rados_aio_write_op_operate(rados_write_op_t write_op,
                                rados_ioctx_t io,
                                rados_completion_t completion,
                                const char *oid,
-                               time_t *mtime);
+                               time_t *mtime,
+                              int flags);
 
 
 /** @} Object Operations */
index 929e105209f7e55a60c1568ccf06759ec359e16b..db56c7e50c628b482fb77098068cd62a942ed839 100644 (file)
@@ -502,7 +502,7 @@ int librados::IoCtxImpl::clone_range(const object_t& dst_oid,
 }
 
 int librados::IoCtxImpl::operate(const object_t& oid, ::ObjectOperation *o,
-                                time_t *pmtime)
+                                time_t *pmtime, int flags)
 {
   utime_t ut;
   if (pmtime) {
@@ -529,7 +529,7 @@ int librados::IoCtxImpl::operate(const object_t& oid, ::ObjectOperation *o,
   int op = o->ops[0].op.op;
   ldout(client->cct, 10) << ceph_osd_op_name(op) << " oid=" << oid << " nspace=" << oloc.nspace << dendl;
   Objecter::Op *objecter_op = objecter->prepare_mutate_op(oid, oloc,
-                                                         *o, snapc, ut, 0,
+                                                         *o, snapc, ut, flags,
                                                          NULL, oncommit, &ver);
   lock->Lock();
   objecter->op_submit(objecter_op);
@@ -548,7 +548,9 @@ int librados::IoCtxImpl::operate(const object_t& oid, ::ObjectOperation *o,
 }
 
 int librados::IoCtxImpl::operate_read(const object_t& oid,
-                                     ::ObjectOperation *o, bufferlist *pbl)
+                                     ::ObjectOperation *o,
+                                     bufferlist *pbl,
+                                     int flags)
 {
   if (!o->size())
     return 0;
@@ -564,7 +566,7 @@ int librados::IoCtxImpl::operate_read(const object_t& oid,
   int op = o->ops[0].op.op;
   ldout(client->cct, 10) << ceph_osd_op_name(op) << " oid=" << oid << " nspace=" << oloc.nspace << dendl;
   Objecter::Op *objecter_op = objecter->prepare_read_op(oid, oloc,
-                                             *o, snap_seq, pbl, 0,
+                                             *o, snap_seq, pbl, flags,
                                              onack, &ver);
   lock->Lock();
   objecter->op_submit(objecter_op);
index 8693d6cba444e20c642368b77ea4b28f51b1c246..46e223ffac02e429b8d2fb766f8cb8f2b0718fbf 100644 (file)
@@ -140,8 +140,8 @@ struct librados::IoCtxImpl {
   int getxattrs(const object_t& oid, map<string, bufferlist>& attrset);
   int rmxattr(const object_t& oid, const char *name);
 
-  int operate(const object_t& oid, ::ObjectOperation *o, time_t *pmtime);
-  int operate_read(const object_t& oid, ::ObjectOperation *o, bufferlist *pbl);
+  int operate(const object_t& oid, ::ObjectOperation *o, time_t *pmtime, int flags=0);
+  int operate_read(const object_t& oid, ::ObjectOperation *o, bufferlist *pbl, int flags=0);
   int aio_operate(const object_t& oid, ::ObjectOperation *o,
                  AioCompletionImpl *c, const SnapContext& snap_context,
                  int flags);
index 7c65ff61b3bd56cc54f36db845b4e9cfcb85447c..501fcf052eb9d0fdd4d4dcdb8067b73b75469434 100644 (file)
@@ -3136,23 +3136,26 @@ extern "C" void rados_write_op_zero(rados_write_op_t write_op,
 extern "C" int rados_write_op_operate(rados_write_op_t write_op,
                                       rados_ioctx_t io,
                                       const char *oid,
-                                     time_t *mtime)
+                                     time_t *mtime,
+                                     int flags)
 {
   object_t obj(oid);
   ::ObjectOperation *oo = (::ObjectOperation *) write_op;
   librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
-  return ctx->operate(obj, oo, mtime);
+  return ctx->operate(obj, oo, mtime, flags);
 }
 
 extern "C" int rados_aio_write_op_operate(rados_write_op_t write_op,
-                                      rados_ioctx_t io,
-                                     rados_completion_t completion,
-                                      const char *oid,
-                                     time_t *mtime)
+                                         rados_ioctx_t io,
+                                         rados_completion_t completion,
+                                         const char *oid,
+                                         time_t *mtime,
+                                         int flags)
 {
   object_t obj(oid);
   ::ObjectOperation *oo = (::ObjectOperation *) write_op;
   librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
   librados::AioCompletionImpl *c = (librados::AioCompletionImpl*)completion;
-  return ctx->aio_operate(obj, oo, c, ctx->snapc, 0);
+  return ctx->aio_operate(obj, oo, c, ctx->snapc, flags);
+}
 }
index 906a386f41f60e3dafb1119bd73c8d8c0fadbaee..37f3b71f16855a0705ba78b1a81daa6ae0a9751c 100644 (file)
@@ -22,7 +22,7 @@ TEST(LibRadosCWriteOps, assertExists) {
   rados_write_op_assert_exists(op);
 
   // -2, ENOENT
-  ASSERT_EQ(-2, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(-2, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   rados_release_write_op(op);
 
   rados_write_op_t op2 = rados_create_write_op();
@@ -31,7 +31,7 @@ TEST(LibRadosCWriteOps, assertExists) {
 
   rados_completion_t completion;
   ASSERT_EQ(0, rados_aio_create_completion(NULL, NULL, NULL, &completion));
-  ASSERT_EQ(0, rados_aio_write_op_operate(op2, ioctx, completion, "test", NULL));
+  ASSERT_EQ(0, rados_aio_write_op_operate(op2, ioctx, completion, "test", NULL, 0));
   rados_aio_wait_for_complete(completion);
   ASSERT_EQ(-2, rados_aio_get_return_value(completion));
 
@@ -52,7 +52,7 @@ TEST(LibRadosCWriteOps, Xattrs) {
   ASSERT_TRUE(op);
   rados_write_op_create(op, LIBRADOS_CREATE_EXCLUSIVE, NULL);
   rados_write_op_setxattr(op, "key", "value", 5);
-  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   rados_release_write_op(op);
 
   // Check that xattr exists, if it does, delete it.
@@ -61,7 +61,7 @@ TEST(LibRadosCWriteOps, Xattrs) {
   rados_write_op_create(op, LIBRADOS_CREATE_IDEMPOTENT, NULL);
   rados_write_op_cmpxattr(op, "key", LIBRADOS_CMPXATTR_OP_EQ, "value", 5);
   rados_write_op_rmxattr(op, "key");
-  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   rados_release_write_op(op);
 
   // Check the xattr exits, if it does, add it again (will fail) with -125
@@ -70,7 +70,7 @@ TEST(LibRadosCWriteOps, Xattrs) {
   ASSERT_TRUE(op);
   rados_write_op_cmpxattr(op, "key", LIBRADOS_CMPXATTR_OP_EQ, "value", 5);
   rados_write_op_setxattr(op, "key", "value", 5);
-  ASSERT_EQ(-125, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(-125, rados_write_op_operate(op, ioctx, "test", NULL, 0));
 
   rados_release_write_op(op);
   ASSERT_EQ(0, destroy_one_pool(pool_name, &cluster));
@@ -89,7 +89,7 @@ TEST(LibRadosCWriteOps, Write) {
   rados_write_op_create(op, LIBRADOS_CREATE_EXCLUSIVE, NULL);
   rados_write_op_write(op, "four", 4, 0);
   rados_write_op_write_full(op, "hi", 2);
-  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   char hi[4];
   ASSERT_EQ(2, rados_read(ioctx, "test", hi, 4, 0));
   rados_release_write_op(op);
@@ -99,7 +99,7 @@ TEST(LibRadosCWriteOps, Write) {
   ASSERT_TRUE(op);
   rados_write_op_truncate(op, 1);
   rados_write_op_append(op, "hi", 2);
-  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   ASSERT_EQ(3, rados_read(ioctx, "test", hi, 4, 0));
   rados_release_write_op(op);
 
@@ -108,7 +108,7 @@ TEST(LibRadosCWriteOps, Write) {
   ASSERT_TRUE(op);
   rados_write_op_zero(op, 0, 3);
   rados_write_op_remove(op);
-  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL));
+  ASSERT_EQ(0, rados_write_op_operate(op, ioctx, "test", NULL, 0));
   // ENOENT
   ASSERT_EQ(-2, rados_read(ioctx, "test", hi, 4, 0));
   rados_release_write_op(op);