From: Yan, Zheng Date: Fri, 26 Apr 2019 03:52:01 +0000 (+0800) Subject: mds: cleanup Locker::acquire_locks() X-Git-Tag: v15.1.0~766^2~7 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=81f4e9cb95e2e0cf3ab908073248817031ccf51f;p=ceph.git mds: cleanup Locker::acquire_locks() define varible 'lock' in the loop that acquires locks Signed-off-by: "Yan, Zheng" --- diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index 2ecf82a81469..885ffd2976b2 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -446,24 +446,26 @@ bool Locker::acquire_locks(MDRequestRef& mdr, // make sure they match currently acquired locks. auto existing = mdr->locks.begin(); for (const auto& p : lov) { + auto lock = p.lock; + bool need_wrlock = p.is_wrlock(); bool need_remote_wrlock = p.is_remote_wrlock(); // already locked? - if (existing != mdr->locks.end() && existing->lock == p.lock) { + if (existing != mdr->locks.end() && existing->lock == lock) { // right kind? auto it = existing++; auto have = *it; // don't reference if (have.is_xlock() && p.is_xlock()) { - dout(10) << " already xlocked " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " already xlocked " << *lock << " " << *lock->get_parent() << dendl; continue; } if (have.is_remote_wrlock() && (!need_remote_wrlock || have.wrlock_target != p.wrlock_target)) { dout(10) << " unlocking remote_wrlock on wrong mds." << have.wrlock_target - << " " << *have.lock << " " << *have.lock->get_parent() << dendl; + << " " << *lock << " " << *lock->get_parent() << dendl; remote_wrlock_finish(it, mdr.get()); have.clear_remote_wrlock(); } @@ -472,24 +474,24 @@ bool Locker::acquire_locks(MDRequestRef& mdr, if (need_wrlock == have.is_wrlock() && need_remote_wrlock == have.is_remote_wrlock()) { if (need_wrlock) - dout(10) << " already wrlocked " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " already wrlocked " << *lock << " " << *lock->get_parent() << dendl; if (need_remote_wrlock) - dout(10) << " already remote_wrlocked " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " already remote_wrlocked " << *lock << " " << *lock->get_parent() << dendl; continue; } if (have.is_wrlock()) { if (!need_wrlock) - dout(10) << " unlocking extra " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " unlocking extra " << *lock << " " << *lock->get_parent() << dendl; else if (need_remote_wrlock) // acquire remote_wrlock first - dout(10) << " unlocking out-of-order " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " unlocking out-of-order " << *lock << " " << *lock->get_parent() << dendl; bool need_issue = false; wrlock_finish(it, mdr.get(), &need_issue); if (need_issue) - issue_set.insert(static_cast(have.lock->get_parent())); + issue_set.insert(static_cast(lock->get_parent())); } } else if (have.is_rdlock() && p.is_rdlock()) { - dout(10) << " already rdlocked " << *have.lock << " " << *have.lock->get_parent() << dendl; + dout(10) << " already rdlocked " << *lock << " " << *lock->get_parent() << dendl; continue; } } @@ -516,63 +518,65 @@ bool Locker::acquire_locks(MDRequestRef& mdr, } // lock - if (mdr->locking && p.lock != mdr->locking) { + if (mdr->locking && lock != mdr->locking) { cancel_locking(mdr.get(), &issue_set); } if (p.is_xlock()) { - marker.message = "failed to xlock, waiting"; - if (!xlock_start(p.lock, mdr)) + if (!xlock_start(lock, mdr)) { + marker.message = "failed to xlock, waiting"; goto out; - dout(10) << " got xlock on " << *p.lock << " " << *p.lock->get_parent() << dendl; + } + dout(10) << " got xlock on " << *lock << " " << *lock->get_parent() << dendl; } else if (need_wrlock || need_remote_wrlock) { - if (need_remote_wrlock && !mdr->is_remote_wrlocked(p)) { + if (need_remote_wrlock && !mdr->is_remote_wrlocked(lock)) { marker.message = "waiting for remote wrlocks"; - remote_wrlock_start(p, p.wrlock_target, mdr); + remote_wrlock_start(lock, p.wrlock_target, mdr); goto out; } if (need_wrlock) { - marker.message = "failed to wrlock, waiting"; - client_t _client = p.is_state_pin() ? p.lock->get_excl_client() : client; - if (need_remote_wrlock && !p.lock->can_wrlock(_client)) { + client_t _client = p.is_state_pin() ? lock->get_excl_client() : client; + if (need_remote_wrlock && !lock->can_wrlock(_client)) { marker.message = "failed to wrlock, dropping remote wrlock and waiting"; // can't take the wrlock because the scatter lock is gathering. need to // release the remote wrlock, so that the gathering process can finish. auto it = mdr->locks.end(); ++it; remote_wrlock_finish(it, mdr.get()); - remote_wrlock_start(p, p.wrlock_target, mdr); + remote_wrlock_start(lock, p.wrlock_target, mdr); goto out; } // nowait if we have already gotten remote wrlock - if (!wrlock_start(p, mdr)) { + if (!wrlock_start(lock, mdr)) { ceph_assert(!need_remote_wrlock); + marker.message = "failed to wrlock, waiting"; goto out; } - dout(10) << " got wrlock on " << *p.lock << " " << *p.lock->get_parent() << dendl; + dout(10) << " got wrlock on " << *lock << " " << *lock->get_parent() << dendl; } } else { ceph_assert(mdr->is_master()); - if (p.lock->needs_recover()) { + if (lock->needs_recover()) { if (mds->is_cluster_degraded()) { if (!mdr->is_queued_for_replay()) { // see comments in SimpleLock::set_state_rejoin() and // ScatterLock::encode_state_for_rejoin() drop_locks(mdr.get()); mds->wait_for_cluster_recovered(new C_MDS_RetryRequest(mdcache, mdr)); - dout(10) << " rejoin recovering " << *p.lock << " " << *p.lock->get_parent() + dout(10) << " rejoin recovering " << *lock << " " << *lock->get_parent() << ", waiting for cluster recovered" << dendl; marker.message = "rejoin recovering lock, waiting for cluster recovered"; return false; } } else { - p.lock->clear_need_recover(); + lock->clear_need_recover(); } } - marker.message = "failed to rdlock, waiting"; - if (!rdlock_start(p, mdr)) + if (!rdlock_start(lock, mdr)) { + marker.message = "failed to rdlock, waiting"; goto out; - dout(10) << " got rdlock on " << *p.lock << " " << *p.lock->get_parent() << dendl; + } + dout(10) << " got rdlock on " << *lock << " " << *lock->get_parent() << dendl; } } @@ -1400,9 +1404,10 @@ bool Locker::can_rdlock_set(MutationImpl::LockOpVec& lov) { dout(10) << "can_rdlock_set " << dendl; for (const auto& p : lov) { + auto lock = p.lock; ceph_assert(p.is_rdlock()); - if (!p.lock->can_rdlock(-1)) { - dout(10) << "can_rdlock_set can't rdlock " << *p << " on " << *p.lock->get_parent() << dendl; + if (!lock->can_rdlock(-1)) { + dout(10) << "can_rdlock_set can't rdlock " << *lock << " on " << *lock->get_parent() << dendl; return false; } }