]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: add two more ObjectOperation::exec()
authorYehuda Sadeh <yehuda@inktank.com>
Thu, 28 Feb 2013 17:56:43 +0000 (09:56 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 8 May 2013 17:54:54 +0000 (10:54 -0700)
 - one that also gets out bufferlist and ret value pointer
 - one that gets a callback context

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/include/rados/librados.hpp
src/librados/librados.cc
src/osdc/Objecter.h

index f02738162359230a350c2d0c09f26ce0c5aa3a5f..697969f2fbcde4633091232af9dd2f422fcaea99 100644 (file)
@@ -110,6 +110,13 @@ namespace librados
     OP_FAILOK = 2,
   };
 
+
+  class ObjectOperationCompletion {
+  public:
+    virtual ~ObjectOperationCompletion() {}
+    virtual void handle_completion(int r, bufferlist& outbl) = 0;
+  };
+
   /*
    * ObjectOperation : compound object operation
    * Batch multiple object operations into a single request, to be applied
@@ -131,6 +138,8 @@ namespace librados
     void src_cmpxattr(const std::string& src_oid,
                      const char *name, int op, uint64_t v);
     void exec(const char *cls, const char *method, bufferlist& inbl);
+    void exec(const char *cls, const char *method, bufferlist& inbl, bufferlist *obl, int *prval);
+    void exec(const char *cls, const char *method, bufferlist& inbl, ObjectOperationCompletion *completion);
     /**
      * Guard operation with a check that object version == ver
      *
index c8a25a76a7e7a85903581c79b6225b11da865c73..2125c42462933ca0f622f0335faa0595a1b368dd 100644 (file)
@@ -133,6 +133,36 @@ void librados::ObjectOperation::exec(const char *cls, const char *method, buffer
   o->call(cls, method, inbl);
 }
 
+void librados::ObjectOperation::exec(const char *cls, const char *method, bufferlist& inbl, bufferlist *outbl, int *prval)
+{
+  ::ObjectOperation *o = (::ObjectOperation *)impl;
+  o->call(cls, method, inbl, outbl, NULL, prval);
+}
+
+class ObjectOpCompletionCtx : public Context {
+  librados::ObjectOperationCompletion *completion;
+  bufferlist bl;
+public:
+  ObjectOpCompletionCtx(librados::ObjectOperationCompletion *c) : completion(c) {}
+  void finish(int r) {
+    completion->handle_completion(r, bl);
+    delete completion;
+  }
+
+  bufferlist *outbl() {
+    return &bl;
+  }
+};
+
+void librados::ObjectOperation::exec(const char *cls, const char *method, bufferlist& inbl, librados::ObjectOperationCompletion *completion)
+{
+  ::ObjectOperation *o = (::ObjectOperation *)impl;
+
+  ObjectOpCompletionCtx *ctx = new ObjectOpCompletionCtx(completion);
+
+  o->call(cls, method, inbl, ctx->outbl(), ctx, NULL);
+}
+
 void librados::ObjectReadOperation::stat(uint64_t *psize, time_t *pmtime, int *prval)
 {
   ::ObjectOperation *o = (::ObjectOperation *)impl;
index c54ae3d96eb003059b17ba236687f7f3626382b0..b92cc274e438629bf2f2c8aed5b1ab18ce8568a5 100644 (file)
@@ -121,8 +121,15 @@ struct ObjectOperation {
       osd_op.indata.append(name);
     osd_op.indata.append(data);
   }
-  void add_call(int op, const char *cname, const char *method, bufferlist &indata) {
+  void add_call(int op, const char *cname, const char *method, bufferlist &indata,
+                bufferlist *outbl, Context *ctx, int *prval) {
     OSDOp& osd_op = add_op(op);
+
+    unsigned p = ops.size() - 1;
+    out_handler[p] = ctx;
+    out_bl[p] = outbl;
+    out_rval[p] = prval;
+
     osd_op.op.op = op;
     osd_op.op.cls.class_len = strlen(cname);
     osd_op.op.cls.method_len = strlen(method);
@@ -546,7 +553,12 @@ struct ObjectOperation {
 
   // object classes
   void call(const char *cname, const char *method, bufferlist &indata) {
-    add_call(CEPH_OSD_OP_CALL, cname, method, indata);
+    add_call(CEPH_OSD_OP_CALL, cname, method, indata, NULL, NULL, NULL);
+  }
+
+  void call(const char *cname, const char *method, bufferlist &indata, bufferlist *outdata,
+           Context *ctx, int *prval) {
+    add_call(CEPH_OSD_OP_CALL, cname, method, indata, outdata, ctx, prval);
   }
 
   // watch/notify