Merge pull request #65937 from ifed01/wip-ifed-kvstore-tool-cleanup

tools/kvstore_tool: reduce BlueStore.h exposure.

Reviewed-by: Kefu Chai <tchaikov@gmail.com>
This commit is contained in:
Igor Fedotov 2025-12-23 17:36:18 +03:00 committed by GitHub
commit ec0e508444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 25 deletions

View File

@ -34,13 +34,8 @@ StoreTool::StoreTool(const string& type,
}
if (type == "bluestore-kv") {
#ifdef WITH_BLUESTORE
if (load_bluestore(path, read_only, to_repair) != 0)
exit(1);
#else
cerr << "bluestore not compiled in" << std::endl;
exit(1);
#endif
} else {
auto db_ptr = KeyValueDB::create(g_ceph_context, type, path);
if (!to_repair) {
@ -55,21 +50,24 @@ StoreTool::StoreTool(const string& type,
}
}
#ifdef WITH_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) {
return -EINVAL;
}
db = decltype(db){db_ptr, Deleter(bluestore)};
db = decltype(db){db_ptr, Deleter((ObjectStore*)bluestore)};
return 0;
#else
cerr << "bluestore not compiled in" << std::endl;
return -1;
#endif // WITH_BLUESTORE
}
#endif // WITH_BLUESTORE
uint32_t StoreTool::traverse(const string& prefix,
const bool do_crc,

View File

@ -10,34 +10,27 @@
#include "acconfig.h"
#include "include/buffer_fwd.h"
#include "kv/KeyValueDB.h"
#ifdef WITH_BLUESTORE
#include "os/bluestore/BlueStore.h"
#endif
#include "os/ObjectStore.h"
class KeyValueDB;
class StoreTool
{
#ifdef WITH_BLUESTORE
struct Deleter {
BlueStore *bluestore;
Deleter()
: bluestore(nullptr) {}
Deleter(BlueStore *store)
: bluestore(store) {}
ObjectStore *store = nullptr;
Deleter() {}
Deleter(ObjectStore *_store)
: store(_store) {}
void operator()(KeyValueDB *db) {
if (bluestore) {
bluestore->umount();
delete bluestore;
if (store) {
store->umount();
delete store;
} else {
delete db;
}
}
};
std::unique_ptr<KeyValueDB, Deleter> db;
#else
std::unique_ptr<KeyValueDB> db;
#endif
const std::string store_path;
@ -80,8 +73,6 @@ public:
int print_stats() const;
int build_size_histogram(const std::string& prefix) const;
#ifdef WITH_BLUESTORE
private:
int load_bluestore(const std::string& path, bool read_only, bool need_open_db);
#endif // WITH_BLUESTORE
};