]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/{LocalLockC,SimpleLock}: un-inline methods using `MutationRef`
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 29 Oct 2024 21:52:10 +0000 (22:52 +0100)
committerMax Kellermann <max.kellermann@ionos.com>
Thu, 17 Apr 2025 16:00:16 +0000 (18:00 +0200)
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<T>::~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 <max.kellermann@ionos.com>
src/mds/SimpleLock.cc
src/mds/SimpleLock.h

index df61384a3ca672bc95652fa2bac1cf8d66947e4b..671e0c1c3d52abbc666f1945c732e003dddc8973 100644 (file)
 #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;
index 48607d29c2d3721e727adbfefdb101223c8d4d36..0f68f0674ea7ca7fe76ca539d941544835cd042a 100644 (file)
@@ -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;