From b3082968b0a25fbd5173f630775733762e1fa045 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Tue, 21 Apr 2020 11:43:28 +0200 Subject: [PATCH] os/bluestore: Split _open_db function Created function that prepares environment for _open_db. Signed-off-by: Adam Kupczyk --- src/os/bluestore/BlueStore.cc | 31 ++++++++++++++++++++++--------- src/os/bluestore/BlueStore.h | 2 ++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 8e10a447692..2cf70b5847d 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5613,19 +5613,16 @@ void BlueStore::_sync_bluefs_and_fm() } } -int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) +int BlueStore::_prepare_db_environment(bool create, bool read_only, + std::string* _fn, std::string* _kv_backend) { int r; ceph_assert(!db); - ceph_assert(!(create && read_only)); - string fn = path + "/db"; - string options; - stringstream err; + std::string& fn=*_fn; + std::string& kv_backend=*_kv_backend; + fn = path + "/db"; std::shared_ptr merge_op(new Int64ArrayMergeOperator); - string kv_backend; - std::string sharding_def; - if (create) { kv_backend = cct->_conf->bluestore_kvbackend; } else { @@ -5765,7 +5762,23 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) FreelistManager::setup_merge_operators(db); db->set_merge_operator(PREFIX_STAT, merge_op); db->set_cache_size(cache_kv_ratio * cache_size); + return 0; +} +int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) +{ + int r; + ceph_assert(!(create && read_only)); + string options; + stringstream err; + string kv_dir_fn; + string kv_backend; + std::string sharding_def; + r = _prepare_db_environment(create, read_only, &kv_dir_fn, &kv_backend); + if (r < 0) { + derr << __func__ << " failed to prepare db environment: " << err.str() << dendl; + return -EIO; + } if (kv_backend == "rocksdb") { options = cct->_conf->bluestore_rocksdb_options; if (cct->_conf.get_val("bluestore_rocksdb_cf")) { @@ -5791,7 +5804,7 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) return -EIO; } dout(1) << __func__ << " opened " << kv_backend - << " path " << fn << " options " << options << dendl; + << " path " << kv_dir_fn << " options " << options << dendl; return 0; } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 4ae14fa5c60..44a3cfc538f 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2281,6 +2281,8 @@ private: */ int _open_db_and_around(bool read_only); void _close_db_and_around(bool read_only); + int _prepare_db_environment(bool create, bool read_only, + std::string* kv_dir, std::string* kv_backend); // updates legacy bluefs related recs in DB to a state valid for // downgrades from nautilus. -- 2.39.5