]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ReplicatedPG: copy: implement CopyFromCallback::finish, remove CopyOp::ctx
authorGreg Farnum <greg@inktank.com>
Tue, 1 Oct 2013 22:45:10 +0000 (15:45 -0700)
committerGreg Farnum <greg@inktank.com>
Tue, 1 Oct 2013 23:53:35 +0000 (16:53 -0700)
We implement enough of the CopyFromCallback that CopyOp no longer needs
a direct reference to the OpContext, so we remove it and replace all
references with calls to cop->cb->complete().

Signed-off-by: Greg Farnum <greg@inktank.com>
src/osd/ReplicatedPG.cc
src/osd/ReplicatedPG.h

index f83f2312bf33c8508c3d845943921745b8e7ab17..8d8dde1b36534ea978287740ed7c3d86cb398c64 100644 (file)
@@ -4399,7 +4399,7 @@ int ReplicatedPG::start_copy(OpContext *ctx, CopyCallback *cb, ObjectContextRef
     cancel_copy(cop);
   }
 
-  CopyOpRef cop(new CopyOp(ctx, cb, obc, src, oloc, version, temp_dest_oid));
+  CopyOpRef cop(new CopyOp(cb, obc, src, oloc, version, temp_dest_oid));
   copy_ops[dest] = cop;
   ctx->copy_op = cop;
   ++obc->copyfrom_readside;
@@ -4486,11 +4486,10 @@ void ReplicatedPG::process_copy_chunk(hobject_t oid, tid_t tid, int r)
   }
 
   dout(20) << __func__ << " complete; committing" << dendl;
-  execute_ctx(cop->ctx);
+  cop->cb->complete(cop->rval);
 
   copy_ops.erase(obc->obs.oi.soid);
   --obc->copyfrom_readside;
-  cop->ctx->copy_op.reset();
   kick_object_context_blocked(obc);
 }
 
@@ -4574,8 +4573,7 @@ int ReplicatedPG::finish_copy(OpContext *ctx)
 
 void ReplicatedPG::cancel_copy(CopyOpRef cop)
 {
-  OpContext *ctx = cop->ctx;
-  dout(10) << __func__ << " " << ctx->obc->obs.oi.soid << " ctx " << ctx
+  dout(10) << __func__ << " " << cop->obc->obs.oi.soid
           << " from " << cop->src << " " << cop->oloc << " v" << cop->version
           << dendl;
 
@@ -4587,11 +4585,9 @@ void ReplicatedPG::cancel_copy(CopyOpRef cop)
 
   copy_ops.erase(cop->obc->obs.oi.soid);
   --cop->obc->copyfrom_readside;
-  ctx->copy_op.reset();
 
   kick_object_context_blocked(cop->obc);
-
-  delete ctx;
+  cop->cb->complete(-ECANCELED);
 }
 
 void ReplicatedPG::cancel_copy_ops()
index 6ca252214c0b6e8891a25dd40024b32cc77a8bfa..00611104555ab08ce44aa01c51302a6c3f127990 100644 (file)
@@ -96,7 +96,6 @@ public:
   class CopyCallback;
 
   struct CopyOp {
-    OpContext *ctx;
     CopyCallback *cb;
     ObjectContextRef obc;
     hobject_t src;
@@ -117,9 +116,9 @@ public:
     hobject_t temp_oid;
     object_copy_cursor_t temp_cursor;
 
-    CopyOp(OpContext *c, CopyCallback *cb_, ObjectContextRef _obc, hobject_t s, object_locator_t l,
+    CopyOp(CopyCallback *cb_, ObjectContextRef _obc, hobject_t s, object_locator_t l,
            version_t v, const hobject_t& dest)
-      : ctx(c), cb(cb_), obc(_obc), src(s), oloc(l), version(v),
+      : cb(cb_), obc(_obc), src(s), oloc(l), version(v),
        objecter_tid(0),
        size(0),
        rval(-1),
@@ -158,6 +157,10 @@ public:
 
     CopyCallback() : data_in_temp(false), data_size((uint64_t)-1),
        result_code(0) {}
+    /**
+     * @param r The copy return code. 0 for success; -ECANCELLED if
+     * the operation was cancelled by the local OSD; -errno for other issues.
+     */
     virtual void finish(int r) { result_code = r; }
   public:
     /// Give the CopyCallback ops to perform to complete the copy
@@ -174,7 +177,21 @@ public:
 
   class CopyFromCallback: public CopyCallback {
   protected:
-    virtual void finish(int r) {}
+    virtual void finish(int r) {
+      result_code = r;
+      if (r >= 0) {
+       ctx->pg->execute_ctx(ctx);
+      }
+      ctx->copy_op.reset();
+      ctx->copy_cb = NULL;
+      if (r < 0) {
+       if (r == -ECANCELED) { // toss it out; client resends
+         delete ctx;
+       } else {
+         ctx->pg->osd->reply_op_error(ctx->op, r);
+       }
+      }
+    }
   public:
     OpContext *ctx;
     hobject_t temp_obj;
@@ -183,6 +200,7 @@ public:
     void copy_complete_ops(ObjectStore::Transaction& t) {}
     ~CopyFromCallback() {}
   };
+  friend class CopyFromCallback;
 
   boost::scoped_ptr<PGBackend> pgbackend;