From: Sage Weil Date: Fri, 14 Nov 2014 19:21:05 +0000 (-0800) Subject: osdc/Objecter: expose LingerOp instead of linger_id X-Git-Tag: v0.91~100 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5f90c20dd41170bb30cd2e2bba11393cb7c6fa51;p=ceph.git osdc/Objecter: expose LingerOp instead of linger_id We want a reference-counted handle, not an id. Signed-off-by: Sage Weil --- diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index d960f8e393e44..8caae8cbd4f0a 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -1054,11 +1054,11 @@ int librados::IoCtxImpl::watch(const object_t& oid, prepare_assert_ops(&wr); wr.watch(*cookie, CEPH_OSD_WATCH_OP_WATCH); bufferlist bl; - wc->linger_id = objecter->linger_mutate(oid, oloc, wr, - snapc, ceph_clock_now(NULL), bl, - *cookie, 0, - NULL, onfinish, &wc->on_error, - &objver); + wc->linger_op = objecter->linger_watch(oid, oloc, wr, + snapc, ceph_clock_now(NULL), bl, + *cookie, 0, + NULL, onfinish, &wc->on_error, + &objver); lock->Unlock(); mylock.Lock(); @@ -1175,22 +1175,22 @@ int librados::IoCtxImpl::notify(const object_t& oid, bufferlist& bl, // Issue RADOS op C_SaferCond onack; version_t objver; - wc->linger_id = objecter->linger_read(oid, oloc, rd, snap_seq, inbl, NULL, 0, - &onack, &objver); + wc->linger_op = objecter->linger_notify(oid, oloc, rd, snap_seq, inbl, NULL, 0, + &onack, &objver); lock->Unlock(); - ldout(client->cct, 10) << __func__ << " issued linger op " << wc->linger_id << dendl; + ldout(client->cct, 10) << __func__ << " issued linger op " << wc->linger_op << dendl; int r_issue = onack.wait(); - ldout(client->cct, 10) << __func__ << " linger op " << wc->linger_id << " acked (" << r_issue << ")" << dendl; + ldout(client->cct, 10) << __func__ << " linger op " << wc->linger_op << " acked (" << r_issue << ")" << dendl; if (r_issue == 0) { - ldout(client->cct, 10) << __func__ << "waiting for watch_notify message for linger op " << wc->linger_id << dendl; + ldout(client->cct, 10) << __func__ << "waiting for watch_notify message for linger op " << wc->linger_op << dendl; mylock_all.Lock(); while (!done_all) cond_all.Wait(mylock_all); mylock_all.Unlock(); } - ldout(client->cct, 10) << __func__ << " completed notify (linger op " << wc->linger_id << "), unregistering" << dendl; + ldout(client->cct, 10) << __func__ << " completed notify (linger op " << wc->linger_op << "), unregistering" << dendl; lock->Lock(); client->unregister_watch_notify_callback(cookie, NULL); // destroys wc diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index 927a19f826e6f..3ac48d217e259 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -227,7 +227,7 @@ namespace librados { struct WatchNotifyInfo : public RefCountedWaitObject { IoCtxImpl *io_ctx_impl; // parent const object_t oid; // the object - uint64_t linger_id; // we use this to unlinger when we are done + class Objecter::LingerOp *linger_op; // we use this to unlinger when we are done uint64_t cookie; // callback cookie int err; @@ -254,7 +254,7 @@ struct WatchNotifyInfo : public RefCountedWaitObject { const object_t& _oc) : io_ctx_impl(io_ctx_impl_), oid(_oc), - linger_id(0), + linger_op(NULL), cookie(0), err(0), watch_ctx(NULL), diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 6512c51f904a8..81fa7701d4b29 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -665,8 +665,10 @@ int librados::RadosClient::unregister_watch_notify_callback(uint64_t cookie, WatchNotifyInfo *ctx = iter->second; if (poid) *poid = ctx->oid; - if (ctx->linger_id) - objecter->unregister_linger(ctx->linger_id); + if (ctx->linger_op) { + objecter->linger_cancel(ctx->linger_op); + ctx->linger_op = NULL; + } watch_notify_info.erase(iter); lock.Unlock(); @@ -687,7 +689,7 @@ int librados::RadosClient::watch_check(uint64_t cookie) WatchNotifyInfo *ctx = iter->second; if (ctx->err) return ctx->err; - return objecter->linger_check(ctx->linger_id); + return objecter->linger_check(ctx->linger_op); } struct C_DoWatchNotify : public Context { diff --git a/src/osdc/Objecter.cc b/src/osdc/Objecter.cc index 1f40bc576fd59..db2aecc4948d2 100644 --- a/src/osdc/Objecter.cc +++ b/src/osdc/Objecter.cc @@ -554,18 +554,11 @@ void Objecter::_linger_ping(LingerOp *info, int r, utime_t sent) info->watch_lock.Unlock(); } -int Objecter::linger_check(uint64_t linger_id) +int Objecter::linger_check(LingerOp *info) { RWLock::WLocker wl(rwlock); - map::iterator iter = linger_ops.find(linger_id); - if (iter == linger_ops.end()) { - ldout(cct, 10) << __func__ << " " << linger_id << " dne" << dendl; - return -EBADF; - } - - LingerOp *info = iter->second; utime_t age = ceph_clock_now(NULL) - info->watch_valid_thru; - ldout(cct, 10) << __func__ << " " << linger_id + ldout(cct, 10) << __func__ << " " << info->linger_id << " err " << info->last_error << " age " << age << dendl; if (info->last_error) @@ -573,26 +566,24 @@ int Objecter::linger_check(uint64_t linger_id) return age.to_msec(); } -void Objecter::unregister_linger(uint64_t linger_id) +void Objecter::linger_cancel(LingerOp *info) { RWLock::WLocker wl(rwlock); - _unregister_linger(linger_id); + _linger_cancel(info); + info->put(); } -void Objecter::_unregister_linger(uint64_t linger_id) +void Objecter::_linger_cancel(LingerOp *info) { assert(rwlock.is_wlocked()); - ldout(cct, 20) << __func__ << " linger_id=" << linger_id << dendl; - - map::iterator iter = linger_ops.find(linger_id); - if (iter != linger_ops.end()) { - LingerOp *info = iter->second; + ldout(cct, 20) << __func__ << " linger_id=" << info->linger_id << dendl; + if (!info->canceled) { OSDSession *s = info->session; s->lock.get_write(); _session_linger_op_remove(s, info); s->lock.unlock(); - linger_ops.erase(iter); + linger_ops.erase(info->linger_id); info->canceled = true; info->put(); @@ -600,13 +591,14 @@ void Objecter::_unregister_linger(uint64_t linger_id) } } -ceph_tid_t Objecter::linger_mutate(const object_t& oid, const object_locator_t& oloc, - ObjectOperation& op, - const SnapContext& snapc, utime_t mtime, - bufferlist& inbl, uint64_t cookie, int flags, - Context *onack, Context *oncommit, - Context *onerror, - version_t *objver) +Objecter::LingerOp *Objecter::linger_watch(const object_t& oid, + const object_locator_t& oloc, + ObjectOperation& op, + const SnapContext& snapc, utime_t mtime, + bufferlist& inbl, uint64_t cookie, int flags, + Context *onack, Context *oncommit, + Context *onerror, + version_t *objver) { LingerOp *info = new LingerOp; info->target.base_oid = oid; @@ -629,14 +621,18 @@ ceph_tid_t Objecter::linger_mutate(const object_t& oid, const object_locator_t& RWLock::WLocker wl(rwlock); _linger_submit(info); logger->inc(l_osdc_linger_active); - return info->linger_id; + + info->get(); // for the caller + return info; } -ceph_tid_t Objecter::linger_read(const object_t& oid, const object_locator_t& oloc, - ObjectOperation& op, - snapid_t snap, bufferlist& inbl, bufferlist *poutbl, int flags, - Context *onfinish, - version_t *objver) +Objecter::LingerOp *Objecter::linger_notify(const object_t& oid, + const object_locator_t& oloc, + ObjectOperation& op, + snapid_t snap, bufferlist& inbl, + bufferlist *poutbl, int flags, + Context *onfinish, + version_t *objver) { LingerOp *info = new LingerOp; info->target.base_oid = oid; @@ -654,7 +650,8 @@ ceph_tid_t Objecter::linger_read(const object_t& oid, const object_locator_t& ol RWLock::WLocker wl(rwlock); _linger_submit(info); logger->inc(l_osdc_linger_active); - return info->linger_id; + info->get(); // for the caller + return info; } void Objecter::_linger_submit(LingerOp *info) @@ -734,7 +731,7 @@ void Objecter::_scan_requests(OSDSession *s, { assert(rwlock.is_wlocked()); - list unregister_lingers; + list unregister_lingers; RWLock::Context lc(rwlock, RWLock::Context::TakenForWrite); @@ -761,8 +758,10 @@ void Objecter::_scan_requests(OSDSession *s, case RECALC_OP_TARGET_POOL_DNE: _check_linger_pool_dne(op, &unregister); if (unregister) { - ldout(cct, 10) << " need to unregister linger op " << op->linger_id << dendl; - unregister_lingers.push_back(op->linger_id); + ldout(cct, 10) << " need to unregister linger op " + << op->linger_id << dendl; + op->get(); + unregister_lingers.push_back(op); } break; } @@ -824,8 +823,11 @@ void Objecter::_scan_requests(OSDSession *s, s->lock.unlock(); - for (list::iterator iter = unregister_lingers.begin(); iter != unregister_lingers.end(); ++iter) { - _unregister_linger(*iter); + for (list::iterator iter = unregister_lingers.begin(); + iter != unregister_lingers.end(); + ++iter) { + _linger_cancel(*iter); + (*iter)->put(); } } @@ -1207,7 +1209,7 @@ void Objecter::C_Linger_Map_Latest::finish(int r) objecter->_check_linger_pool_dne(op, &unregister); if (unregister) { - objecter->_unregister_linger(op->linger_id); + objecter->_linger_cancel(op); } op->put(); diff --git a/src/osdc/Objecter.h b/src/osdc/Objecter.h index 63f956ee20dab..7bc50c84a8e68 100644 --- a/src/osdc/Objecter.h +++ b/src/osdc/Objecter.h @@ -1962,20 +1962,23 @@ public: } return op_submit(o, ctx_budget); } - ceph_tid_t linger_mutate(const object_t& oid, const object_locator_t& oloc, - ObjectOperation& op, - const SnapContext& snapc, utime_t mtime, - bufferlist& inbl, uint64_t cookie, int flags, - Context *onack, Context *onfinish, Context *onerror, - version_t *objver); - ceph_tid_t linger_read(const object_t& oid, const object_locator_t& oloc, - ObjectOperation& op, - snapid_t snap, bufferlist& inbl, bufferlist *poutbl, int flags, - Context *onack, - version_t *objver); - int linger_check(uint64_t linger_id); - void unregister_linger(uint64_t linger_id); - void _unregister_linger(uint64_t linger_id); + + // caller owns a ref + LingerOp *linger_watch(const object_t& oid, const object_locator_t& oloc, + ObjectOperation& op, + const SnapContext& snapc, utime_t mtime, + bufferlist& inbl, uint64_t cookie, int flags, + Context *onack, Context *onfinish, Context *onerror, + version_t *objver); + LingerOp *linger_notify(const object_t& oid, const object_locator_t& oloc, + ObjectOperation& op, + snapid_t snap, bufferlist& inbl, + bufferlist *poutbl, int flags, + Context *onack, + version_t *objver); + int linger_check(LingerOp *info); + void linger_cancel(LingerOp *info); // releases a reference + void _linger_cancel(LingerOp *info); /** * set up initial ops in the op vector, and allocate a final op slot.