From 2629e7ac19d1e9b344b622321edd6ae155ab6e0f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Oct 2024 22:52:10 +0100 Subject: [PATCH] mds/{LocalLockC,SimpleLock}: un-inline methods using `MutationRef` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit e8bc28407117 added a forward declaration for `MutationRef` but that doesn't work as long as the header constructs and destructs instances, causing errors such as: build/debug/boost/include/boost/smart_ptr/intrusive_ptr.hpp: In instantiation of ‘boost::intrusive_ptr::~intrusive_ptr() [with T = MutationImpl]’: src/mds/SimpleLock.h:424:5: required from here 424 | ceph_assert(!get_xlock_by()); | ~~~~~~~~~~~~^~ build/debug/boost/include/boost/smart_ptr/intrusive_ptr.hpp:100:44: error: ‘intrusive_ptr_release’ was not declared in this scope; did you mean ‘ceph::common::intrusive_ptr_release’? 100 | if( px != 0 ) intrusive_ptr_release( px ); | ~~~~~~~~~~~~~~~~~~~~~^~~~~~ | ceph::common::intrusive_ptr_release This never occurred previously because `Mutation.h` happened to be already included by somebody else. Signed-off-by: Max Kellermann --- src/mds/SimpleLock.cc | 52 +++++++++++++++++++++++++++++++++++++++++++ src/mds/SimpleLock.h | 52 ++++++------------------------------------- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/mds/SimpleLock.cc b/src/mds/SimpleLock.cc index df61384a3ca67..671e0c1c3d52a 100644 --- a/src/mds/SimpleLock.cc +++ b/src/mds/SimpleLock.cc @@ -16,6 +16,56 @@ #include "SimpleLock.h" #include "Mutation.h" +SimpleLock::unstable_bits_t *SimpleLock::more() const { + if (!_unstable) + _unstable.reset(new unstable_bits_t); + return _unstable.get(); +} + +void SimpleLock::try_clear_more() { + if (_unstable && _unstable->empty()) { + _unstable.reset(); + } +} + +void SimpleLock::get_xlock(MutationRef who, client_t client) { + ceph_assert(!has_xlock_by()); + ceph_assert(state == LOCK_XLOCK || is_locallock() || + state == LOCK_LOCK /* if we are a peer */); + parent->get(MDSCacheObject::PIN_LOCK); + more()->num_xlock++; + more()->xlock_by = who; + more()->xlock_by_client = client; +} + +void SimpleLock::set_xlock_done() { + ceph_assert(more()->xlock_by); + ceph_assert(state == LOCK_XLOCK || is_locallock() || + state == LOCK_LOCK /* if we are a peer */); + if (!is_locallock()) + state = LOCK_XLOCKDONE; + more()->xlock_by.reset(); +} + +void SimpleLock::put_xlock() { + ceph_assert(state == LOCK_XLOCK || state == LOCK_XLOCKDONE || + state == LOCK_XLOCKSNAP || state == LOCK_LOCK_XLOCK || + state == LOCK_LOCK || /* if we are a leader of a peer */ + state == LOCK_PREXLOCK || state == LOCK_SYNC || + is_locallock()); + --more()->num_xlock; + parent->put(MDSCacheObject::PIN_LOCK); + if (more()->num_xlock == 0) { + more()->xlock_by.reset(); + more()->xlock_by_client = -1; + try_clear_more(); + } +} + +MutationRef SimpleLock::get_xlock_by() const { + return have_more() ? more()->xlock_by : MutationRef(); +} + void SimpleLock::dump(ceph::Formatter *f) const { ceph_assert(f != NULL); if (is_sync_and_unlocked()) { @@ -90,6 +140,8 @@ int SimpleLock::get_cap_mask() const { SimpleLock::unstable_bits_t::unstable_bits_t() : lock_caches(member_offset(MDLockCache::LockItem, item_lock)) {} +SimpleLock::unstable_bits_t::~unstable_bits_t() noexcept = default; + void SimpleLock::add_cache(MDLockCacheItem& item) { more()->lock_caches.push_back(&item.item_lock); state_flags |= CACHED; diff --git a/src/mds/SimpleLock.h b/src/mds/SimpleLock.h index 48607d29c2d37..0f68f0674ea7c 100644 --- a/src/mds/SimpleLock.h +++ b/src/mds/SimpleLock.h @@ -25,7 +25,6 @@ #include "MDSCacheObject.h" #include "MDSContext.h" -#include "Mutation.h" // for MutationRef (complete definition is needed) // -- lock types -- // see CEPH_LOCK_* @@ -425,37 +424,9 @@ public: } // xlock - void get_xlock(MutationRef who, client_t client) { - ceph_assert(!has_xlock_by()); - ceph_assert(state == LOCK_XLOCK || is_locallock() || - state == LOCK_LOCK /* if we are a peer */); - parent->get(MDSCacheObject::PIN_LOCK); - more()->num_xlock++; - more()->xlock_by = who; - more()->xlock_by_client = client; - } - void set_xlock_done() { - ceph_assert(more()->xlock_by); - ceph_assert(state == LOCK_XLOCK || is_locallock() || - state == LOCK_LOCK /* if we are a peer */); - if (!is_locallock()) - state = LOCK_XLOCKDONE; - more()->xlock_by.reset(); - } - void put_xlock() { - ceph_assert(state == LOCK_XLOCK || state == LOCK_XLOCKDONE || - state == LOCK_XLOCKSNAP || state == LOCK_LOCK_XLOCK || - state == LOCK_LOCK || /* if we are a leader of a peer */ - state == LOCK_PREXLOCK || state == LOCK_SYNC || - is_locallock()); - --more()->num_xlock; - parent->put(MDSCacheObject::PIN_LOCK); - if (more()->num_xlock == 0) { - more()->xlock_by.reset(); - more()->xlock_by_client = -1; - try_clear_more(); - } - } + void get_xlock(MutationRef who, client_t client); + void set_xlock_done(); + void put_xlock(); bool is_xlocked() const { return have_more() && more()->num_xlock > 0; } @@ -468,9 +439,7 @@ public: bool is_xlocked_by_client(client_t c) const { return have_more() ? more()->xlock_by_client == c : false; } - MutationRef get_xlock_by() const { - return have_more() ? more()->xlock_by : MutationRef(); - } + MutationRef get_xlock_by() const; bool has_xlock_by() const noexcept { return have_more() && more()->xlock_by; } @@ -635,6 +604,7 @@ private: // XXX not in mempool struct unstable_bits_t { unstable_bits_t(); + ~unstable_bits_t() noexcept; bool empty() { return @@ -659,16 +629,8 @@ private: }; bool have_more() const { return _unstable ? true : false; } - unstable_bits_t *more() const { - if (!_unstable) - _unstable.reset(new unstable_bits_t); - return _unstable.get(); - } - void try_clear_more() { - if (_unstable && _unstable->empty()) { - _unstable.reset(); - } - } + unstable_bits_t *more() const; + void try_clear_more(); int num_rdlock = 0; -- 2.39.5