From: Igor Fedotov Date: Fri, 23 Jan 2026 19:15:30 +0000 (+0300) Subject: tools/ceph-kvstore-tool: fix crash on db close. X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c5c46e0b6c1888d3072b5a3d8c5d0cfe08031b2e;p=ceph.git tools/ceph-kvstore-tool: fix crash on db close. Fixes: https://tracker.ceph.com/issues/74332 Signed-off-by: Igor Fedotov --- diff --git a/src/tools/kvstore_tool.cc b/src/tools/kvstore_tool.cc index f9f684091f04..7d9a9fb3f8ec 100644 --- a/src/tools/kvstore_tool.cc +++ b/src/tools/kvstore_tool.cc @@ -51,22 +51,34 @@ StoreTool::StoreTool(const string& type, } +#ifdef WITH_BLUESTORE +void close_delete_bluestore(ObjectStore* store) +{ + auto bluestore = dynamic_cast(store); + ceph_assert(bluestore); + bluestore->close_db_environment(); + delete bluestore; +} + int StoreTool::load_bluestore(const string& path, bool read_only, bool to_repair) { -#ifdef WITH_BLUESTORE - auto bluestore = new BlueStore(g_ceph_context, path); - KeyValueDB *db_ptr; - int r = bluestore->open_db_environment(&db_ptr, read_only, to_repair); - if (r < 0) { + auto bluestore = new BlueStore(g_ceph_context, path); + KeyValueDB *db_ptr; + int r = bluestore->open_db_environment(&db_ptr, read_only, to_repair); + if (r < 0) { return -EINVAL; - } - db = decltype(db){db_ptr, Deleter((ObjectStore*)bluestore)}; - return 0; + } + db = decltype(db){db_ptr, Deleter(bluestore, close_delete_bluestore)}; + return 0; +} #else + +int StoreTool::load_bluestore(const string& path, bool read_only, bool to_repair) +{ cerr << "bluestore not compiled in" << std::endl; return -1; -#endif // WITH_BLUESTORE } +#endif // WITH_BLUESTORE uint32_t StoreTool::traverse(const string& prefix, diff --git a/src/tools/kvstore_tool.h b/src/tools/kvstore_tool.h index 0cc6a7efbc3b..11ad30b5f1fd 100644 --- a/src/tools/kvstore_tool.h +++ b/src/tools/kvstore_tool.h @@ -17,14 +17,14 @@ class KeyValueDB; class StoreTool { struct Deleter { - ObjectStore *store = nullptr; + ObjectStore* store = nullptr; + std::function cb; Deleter() {} - Deleter(ObjectStore *_store) - : store(_store) {} + Deleter(ObjectStore* _store, std::function _cb) + : store(_store), cb(_cb) {} void operator()(KeyValueDB *db) { - if (store) { - store->umount(); - delete store; + if (cb) { + cb(store); } else { delete db; }