]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Refactor pin() to get more control over its logic
authorAdam Kupczyk <akupczyk@redhat.com>
Sun, 29 Nov 2020 12:46:12 +0000 (13:46 +0100)
committerIgor Fedotov <ifedotov@suse.com>
Tue, 2 Feb 2021 11:21:20 +0000 (14:21 +0300)
Got rid of OnodeCacheShard pin() and unpin() functions.
Moved their validator logic right into Onode put and get functions.

Signed-off-by: Adam Kupczyk <akupczyk@redhat.com>
(cherry picked from commit eaf1b2366aa7701b10eca4ed3e53d51909e8011b)

src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 4d855529f1f6e1dbf3ca78a5fc8ec0dd041cc550..c6f67f95066cc2f575427543cc7f867acc711d6c 100644 (file)
@@ -3548,32 +3548,36 @@ BlueStore::BlobRef BlueStore::ExtentMap::split_blob(
 //
 void BlueStore::Onode::get() {
   if (++nref == 2) {
-    c->get_onode_cache()->pin(this, [&]() {
-        bool was_pinned = pinned;
-        pinned = nref >= 2;
-        // additional increment for newly pinned instance
-        bool r = !was_pinned && pinned;
-        if (r) {
-          ++nref;
-        }
-        return cached && r;
-      });
+    OnodeCacheShard* ocs = c->get_onode_cache();
+    std::lock_guard l(ocs->lock);
+    bool was_pinned = pinned;
+    pinned = nref >= 2;
+    // additional increment for newly pinned instance
+    bool r = !was_pinned && pinned;
+    if (r) {
+      ++nref;
+    }
+    if (cached && r) {
+      ocs->_pin(this);
+    }
   }
 }
 void BlueStore::Onode::put() {
   int n = --nref;
   if (n == 2) {
-    c->get_onode_cache()->unpin(this, [&]() {
-        bool was_pinned = pinned;
-        pinned = pinned && nref > 2; // intentionally use > not >= as we have
-                                     // +1 due to pinned state
-        bool r = was_pinned && !pinned;
-        // additional decrement for newly unpinned instance
-        if (r) {
-          n = --nref;
-        }
-        return cached && r;
-      });
+    OnodeCacheShard* ocs = c->get_onode_cache();
+    std::lock_guard l(ocs->lock);
+    bool was_pinned = pinned;
+    pinned = pinned && nref > 2; // intentionally use > not >= as we have
+    // +1 due to pinned state
+    bool r = was_pinned && !pinned;
+    // additional decrement for newly unpinned instance
+    if (r) {
+      n = --nref;
+    }
+    if (cached && r) {
+      ocs->_unpin(this);
+    }
   }
   if (n == 0) {
     delete this;
index 6f47428f83e6d7cd9e688b3eb3b082108f16610e..f0536080141b77eacff70c44815d2875039d6f20 100644 (file)
@@ -1215,20 +1215,6 @@ public:
     virtual void _add(Onode* o, int level) = 0;
     virtual void _rm(Onode* o) = 0;
 
-    void pin(Onode* o, std::function<bool ()> validator) {
-      std::lock_guard l(lock);
-      if (validator()) {
-        _pin(o);
-      }
-    }
-
-    void unpin(Onode* o, std::function<bool()> validator) {
-      std::lock_guard l(lock);
-      if (validator()) {
-        _unpin(o);
-      }
-    }
-
     virtual void move_pinned(OnodeCacheShard *to, Onode *o) = 0;
     virtual void add_stats(uint64_t *onodes, uint64_t *pinned_onodes) = 0;
     bool empty() {