ReplicatedPG: copy: implement CopyFromCallback::finish, remove CopyOp::ctx

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>
This commit is contained in:
Greg Farnum 2013-10-01 15:45:10 -07:00
parent 613841a670
commit da1b9b6c10
2 changed files with 26 additions and 12 deletions

View 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()

View 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;