From: Josh Durgin Date: Fri, 7 Feb 2014 03:12:58 +0000 (-0800) Subject: librados: add global op flags to the c api X-Git-Tag: v0.78~154^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4f4121ae1989cb1ff99d8343493eeeefaeabb013;p=ceph.git librados: add global op flags to the c api 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 --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 4b4cd45e1e1b..01c09fe681e2 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -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 */ diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index 929e105209f7..db56c7e50c62 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -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); diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index 8693d6cba444..46e223ffac02 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -140,8 +140,8 @@ struct librados::IoCtxImpl { int getxattrs(const object_t& oid, map& 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); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 7c65ff61b3bd..501fcf052eb9 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -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); +} } diff --git a/src/test/librados/c_write_operations.cc b/src/test/librados/c_write_operations.cc index 906a386f41f6..37f3b71f1685 100644 --- a/src/test/librados/c_write_operations.cc +++ b/src/test/librados/c_write_operations.cc @@ -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);