From: Adam Kupczyk Date: Wed, 2 Dec 2020 22:47:30 +0000 (-0500) Subject: os/bluestore: Prevented erasure of element from onode_map during iteration X-Git-Tag: v15.2.9~8^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=af61d0e16cce88099b831319dba646b5e1852170;p=ceph.git 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 (cherry picked from commit 6c8e8a757485d27bfa93d344f3e04aaf29c68cc4) --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index eb44f128dcd8..8ebf29920995 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1985,12 +1985,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; } } @@ -9630,7 +9630,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 @@ -15224,7 +15224,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 30876877ab1d..1b6bde9638e9 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1297,7 +1297,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;