#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
*/
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
* 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 {
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)
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);