From 732ad1364e8693945641f2435500dfa475f0b58f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 1 May 2017 10:24:03 -0400 Subject: [PATCH] kv: move 'bluestore-kv' hackery out of KeyValueDB into ceph-kvstore-tool This avoids contaminating libkv with ObjectStore/BlueStore. It also makes the blustore kv startup slightly less weird (no need to skip the open step). Fixes: http://tracker.ceph.com/issues/19778 Signed-off-by: Sage Weil --- src/kv/KeyValueDB.cc | 15 --------------- src/os/bluestore/BlueStore.cc | 7 ++----- src/os/bluestore/BlueStore.h | 2 +- src/tools/ceph_kvstore_tool.cc | 30 +++++++++++++++++++++++++----- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/kv/KeyValueDB.cc b/src/kv/KeyValueDB.cc index 42036e3c593..7a917b7a183 100644 --- a/src/kv/KeyValueDB.cc +++ b/src/kv/KeyValueDB.cc @@ -12,9 +12,6 @@ #ifdef HAVE_KINETIC #include "KineticStore.h" #endif -#ifdef HAVE_LIBAIO -#include "os/bluestore/BlueStore.h" -#endif KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type, const string& dir, @@ -37,18 +34,6 @@ KeyValueDB *KeyValueDB::create(CephContext *cct, const string& type, } #endif -#ifdef HAVE_LIBAIO - if (type == "bluestore-kv") { - // note: we'll leak this! the only user is ceph-kvstore-tool and - // we don't care. - BlueStore *bluestore = new BlueStore(cct, dir); - KeyValueDB *db = nullptr; - int r = bluestore->start_kv_only(&db); - if (r < 0) - return nullptr; // yes, we leak. - return db; - } -#endif if ((type == "memdb") && cct->check_experimental_feature_enabled("memdb")) { return new MemDB(cct, dir, p); diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 7b6c563edd2..1d69e922677 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -4130,7 +4130,7 @@ bool BlueStore::test_mount_in_use() return ret; } -int BlueStore::_open_db(bool create, bool kv_no_open) +int BlueStore::_open_db(bool create) { int r; assert(!db); @@ -4369,9 +4369,6 @@ int BlueStore::_open_db(bool create, bool kv_no_open) if (kv_backend == "rocksdb") options = cct->_conf->bluestore_rocksdb_options; db->init(options); - if (kv_no_open) { - return 0; - } if (create) r = db->create_and_open(err); else @@ -4968,7 +4965,7 @@ int BlueStore::_mount(bool kv_only) if (r < 0) goto out_fsid; - r = _open_db(false, kv_only); + r = _open_db(false); if (r < 0) goto out_bdev; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index f910cca1180..67b34dbaada 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1906,7 +1906,7 @@ private: int _open_bdev(bool create); void _close_bdev(); - int _open_db(bool create, bool kv_no_open=false); + int _open_db(bool create); void _close_db(); int _open_fm(bool create); void _close_fm(); diff --git a/src/tools/ceph_kvstore_tool.cc b/src/tools/ceph_kvstore_tool.cc index df9ef469cc4..adca8a71be2 100644 --- a/src/tools/ceph_kvstore_tool.cc +++ b/src/tools/ceph_kvstore_tool.cc @@ -28,6 +28,10 @@ #include "kv/KeyValueDB.h" #include "common/url_escape.h" +#ifdef HAVE_LIBAIO +#include "os/bluestore/BlueStore.h" +#endif + using namespace std; class StoreTool @@ -37,12 +41,28 @@ class StoreTool public: StoreTool(string type, const string &path) : store_path(path) { - KeyValueDB *db_ptr = KeyValueDB::create(g_ceph_context, type, path); - int r = db_ptr->open(std::cerr); - if (r < 0) { - cerr << "failed to open type " << type << " path " << path << ": " - << cpp_strerror(r) << std::endl; + KeyValueDB *db_ptr; + if (type == "bluestore-kv") { +#ifdef HAVE_LIBAIO + // note: we'll leak this! the only user is ceph-kvstore-tool and + // we don't care. + BlueStore *bluestore = new BlueStore(g_ceph_context, path); + int r = bluestore->start_kv_only(&db_ptr); + if (r < 0) { + exit(1); + } +#else + cerr << "bluestore not compiled in" << std::endl; exit(1); +#endif + } else { + db_ptr = KeyValueDB::create(g_ceph_context, type, path); + int r = db_ptr->open(std::cerr); + if (r < 0) { + cerr << "failed to open type " << type << " path " << path << ": " + << cpp_strerror(r) << std::endl; + exit(1); + } } db.reset(db_ptr); } -- 2.47.3