From 6c8e8a757485d27bfa93d344f3e04aaf29c68cc4 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Wed, 2 Dec 2020 17:47:30 -0500 Subject: [PATCH] os/bluestore: Prevented erasure of element from onode_map during iteration When onode.exists == false getting reference and then releasing it might delete it from container. It must not happen during iteration. Signed-off-by: Adam Kupczyk --- src/os/bluestore/BlueStore.cc | 8 ++++---- src/os/bluestore/BlueStore.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 8e5b0e73ac2..6122aecfa73 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1902,12 +1902,12 @@ void BlueStore::OnodeSpace::rename( cache->_trim(); } -bool BlueStore::OnodeSpace::map_any(std::function f) +bool BlueStore::OnodeSpace::map_any(std::function f) { std::lock_guard l(cache->lock); ldout(cache->cct, 20) << __func__ << dendl; for (auto& i : onode_map) { - if (f(i.second)) { + if (f(i.second.get())) { return true; } } @@ -9072,7 +9072,7 @@ void BlueStore::_reap_collections() while (p != removed_colls.end()) { CollectionRef c = *p; dout(10) << __func__ << " " << c << " " << c->cid << dendl; - if (c->onode_map.map_any([&](OnodeRef o) { + if (c->onode_map.map_any([&](Onode* o) { ceph_assert(!o->exists); if (o->flushing_count.load()) { dout(10) << __func__ << " " << c << " " << c->cid << " " << o->oid @@ -14958,7 +14958,7 @@ int BlueStore::_remove_collection(TransContext *txc, const coll_t &cid, } size_t nonexistent_count = 0; ceph_assert((*c)->exists); - if ((*c)->onode_map.map_any([&](OnodeRef o) { + if ((*c)->onode_map.map_any([&](Onode* o) { if (o->exists) { dout(1) << __func__ << " " << o->oid << " " << o << " exists in onode_map" << dendl; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 942b88286b1..bce2b198031 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1308,7 +1308,7 @@ public: void dump(CephContext *cct); /// return true if f true for any item - bool map_any(std::function f); + bool map_any(std::function f); }; class OpSequencer; -- 2.47.3