]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add individual op flags for c write operations
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 7 Feb 2014 03:19:51 +0000 (19:19 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Feb 2014 20:34:32 +0000 (12:34 -0800)
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 <josh.durgin@inktank.com>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados/librados.cc

index 01c09fe681e2e60e6e3bb72f7cafa0d7ea5a23fb..bb25e7b184fee0db95bc709aaca13a8f2349dd3b 100644 (file)
@@ -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
index 193e3e2478d97c858405d2feba0d9ed20eff4c91..a7cd2d66c0ac43916ff99b70a27a478cafa814fb 100644 (file)
@@ -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 {
index 501fcf052eb9d0fdd4d4dcdb8067b73b75469434..69f91c12e19bf45f167aeb5ff5c9e6553aa52387 100644 (file)
@@ -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);