From bc03fbb40906b86a5bff844d1ab234ae48dbe89c Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 6 Feb 2014 19:19:51 -0800 Subject: [PATCH] librados: add individual op flags for c write operations Move flag validation to a static function so it can be shared with the c++ api. Refer to the new C constants from the c++ api so that it's easy to keep them in sync. Signed-off-by: Josh Durgin --- src/include/rados/librados.h | 16 ++++++++++++++++ src/include/rados/librados.hpp | 4 ++-- src/librados/librados.cc | 17 +++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 01c09fe681e2e..bb25e7b184fee 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -59,6 +59,15 @@ extern "C" { #define LIBRADOS_CREATE_EXCLUSIVE 1 #define LIBRADOS_CREATE_IDEMPOTENT 0 +/* + * Flags that can be set on a per-op basis via + * rados_read_op_set_flags() and rados_write_op_set_flags(). + */ +// fail a create operation if the object already exists +#define LIBRADOS_OP_FLAG_EXCL 1 +// allow the transaction to succeed even if the flagged op fails +#define LIBRADOS_OP_FLAG_FAILOK 2 + /** * @defgroup librados_h_xattr_comp xattr comparison operations * Operators for comparing xattrs on objects, and aborting the @@ -1741,6 +1750,13 @@ rados_write_op_t rados_create_write_op(); */ void rados_release_write_op(rados_write_op_t write_op); +/** + * Set flags for the last operation added to this write_op. + * At least one op must have been added to the write_op. + * @param flags see librados.h constants beginning with LIBRADOS_OP_FLAG + */ +void rados_write_op_set_flags(rados_write_op_t write_op, int flags); + /** * Ensure that the object exists before writing * @param write_op operation to add this action to diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 193e3e2478d97..a7cd2d66c0ac4 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -124,8 +124,8 @@ namespace librados * ops added to an ObjectOperation. */ enum ObjectOperationFlags { - OP_EXCL = 1, - OP_FAILOK = 2, + OP_EXCL = LIBRADOS_OP_FLAG_EXCL, + OP_FAILOK = LIBRADOS_OP_FLAG_FAILOK, }; class ObjectOperationCompletion { diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 501fcf052eb9d..69f91c12e19bf 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -75,16 +75,20 @@ size_t librados::ObjectOperation::size() return o->size(); } -void librados::ObjectOperation::set_op_flags(ObjectOperationFlags flags) +static void set_op_flags(::ObjectOperation *o, int flags) { int rados_flags = 0; - if (flags & OP_EXCL) + if (flags & LIBRADOS_OP_FLAG_EXCL) rados_flags |= CEPH_OSD_OP_FLAG_EXCL; - if (flags & OP_FAILOK) + if (flags & LIBRADOS_OP_FLAG_FAILOK) rados_flags |= CEPH_OSD_OP_FLAG_FAILOK; + o->set_last_op_flags(rados_flags); +} +void librados::ObjectOperation::set_op_flags(ObjectOperationFlags flags) +{ ::ObjectOperation *o = (::ObjectOperation *)impl; - o->set_last_op_flags(rados_flags); + ::set_op_flags(o, (int)flags); } void librados::ObjectOperation::cmpxattr(const char *name, uint8_t op, const bufferlist& v) @@ -3038,6 +3042,11 @@ extern "C" void rados_release_write_op(rados_write_op_t write_op) delete (::ObjectOperation*)write_op; } +extern "C" void rados_write_op_set_flags(rados_write_op_t write_op, int flags) +{ + set_op_flags((::ObjectOperation *)write_op, flags); +} + extern "C" void rados_write_op_assert_exists(rados_write_op_t write_op) { ((::ObjectOperation *)write_op)->stat(NULL, (utime_t *)NULL, NULL); -- 2.39.5