]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph-kvstore-tool: fix crash on db close. 68406/head
authorIgor Fedotov <igor.fedotov@croit.io>
Fri, 23 Jan 2026 19:15:30 +0000 (22:15 +0300)
committerIgor Fedotov <igor.fedotov@croit.io>
Wed, 15 Apr 2026 22:14:29 +0000 (01:14 +0300)
Fixes: https://tracker.ceph.com/issues/74332
Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
(cherry picked from commit c5c46e0b6c1888d3072b5a3d8c5d0cfe08031b2e)

src/tools/kvstore_tool.cc
src/tools/kvstore_tool.h

index 5431ef68f046b5f4833119c295ddb6e00a600e78..93365dfe14091ca8d66b668b222927ecc9c286b7 100644 (file)
@@ -51,22 +51,34 @@ StoreTool::StoreTool(const string& type,
 }
 
 
+#ifdef WITH_BLUESTORE
+void close_delete_bluestore(ObjectStore* store)
+{
+  auto bluestore = dynamic_cast<BlueStore*>(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,
index 8c2fec6cd266a19674cfc1528b71cc40d60a27c7..52779878c9b54d5f466964528911147bc505c3c3 100644 (file)
@@ -17,14 +17,14 @@ class KeyValueDB;
 class StoreTool
 {
   struct Deleter {
-    ObjectStore *store = nullptr;
+    ObjectStore* store = nullptr;
+    std::function<void(ObjectStore*)> cb;
     Deleter() {}
-    Deleter(ObjectStore *_store)
-      : store(_store) {}
+    Deleter(ObjectStore* _store, std::function<void(ObjectStore*)> _cb)
+      : store(_store), cb(_cb) {}
     void operator()(KeyValueDB *db) {
-      if (store) {
-       store->umount();
-       delete store;
+      if (cb) {
+        cb(store);
       } else {
        delete db;
       }