From: Adam C. Emerson Date: Thu, 8 Dec 2016 20:34:49 +0000 (-0500) Subject: os: Add CephContext to ObjectStore and ObjectMap bases X-Git-Tag: v12.0.0~384^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f002a2fc969168f27fe25fcfcdfd1d8618e7110d;p=ceph.git os: Add CephContext to ObjectStore and ObjectMap bases Preparatory to removing g_ceph_context and g_conf uses Signed-off-by: Adam C. Emerson --- diff --git a/src/os/ObjectMap.h b/src/os/ObjectMap.h index c4efc7fbc202..f7c2f5f1d1c2 100644 --- a/src/os/ObjectMap.h +++ b/src/os/ObjectMap.h @@ -30,6 +30,7 @@ class SequencerPosition; */ class ObjectMap { public: + CephContext* cct; /// Set keys and values from specified map virtual int set_keys( const ghobject_t &oid, ///< [in] object containing map @@ -146,6 +147,7 @@ public: } + ObjectMap(CephContext* cct) : cct(cct) {} virtual ~ObjectMap() {} }; diff --git a/src/os/ObjectStore.cc b/src/os/ObjectStore.cc index d03ab3b99e97..215abc10a759 100644 --- a/src/os/ObjectStore.cc +++ b/src/os/ObjectStore.cc @@ -67,7 +67,7 @@ ObjectStore *ObjectStore::create(CephContext *cct, osflagbits_t flags) { if (type == "filestore") { - return new FileStore(data, journal, flags); + return new FileStore(cct, data, journal, flags); } if (type == "memstore") { return new MemStore(cct, data); diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 304e352b3a36..befbf102f389 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -70,6 +70,7 @@ protected: string path; public: + CephContext* cct; /** * create - create an ObjectStore instance. * @@ -126,6 +127,7 @@ public: * created in ...::queue_transaction(s) */ struct Sequencer_impl : public RefCountedObject { + CephContext* cct; virtual void flush() = 0; /** @@ -143,7 +145,7 @@ public: Context *c ///< [in] context to call upon flush/commit ) = 0; ///< @return true if idle, false otherwise - Sequencer_impl() : RefCountedObject(NULL, 0) {} + Sequencer_impl(CephContext* cct) : RefCountedObject(NULL, 0), cct(cct) {} virtual ~Sequencer_impl() {} }; typedef boost::intrusive_ptr Sequencer_implRef; @@ -1484,12 +1486,14 @@ public: } public: - explicit ObjectStore(const std::string& path_) : path(path_), logger(NULL) {} + ObjectStore(CephContext* cct, + const std::string& path_) : path(path_), cct(cct), + logger(nullptr) {} virtual ~ObjectStore() {} // no copying - explicit ObjectStore(const ObjectStore& o); - const ObjectStore& operator=(const ObjectStore& o); + explicit ObjectStore(const ObjectStore& o) = delete; + const ObjectStore& operator=(const ObjectStore& o) = delete; // versioning virtual int upgrade() { diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 219a3578a136..34d8980bbfbb 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2554,8 +2554,7 @@ static void aio_cb(void *priv, void *priv2) } BlueStore::BlueStore(CephContext *cct, const string& path) - : ObjectStore(path), - cct(cct), + : ObjectStore(cct, path), bluefs(NULL), bluefs_shared_bdev(0), db(NULL), @@ -6923,7 +6922,7 @@ int BlueStore::_do_wal_op(TransContext *txc, bluestore_wal_op_t& wo) int BlueStore::_wal_replay() { dout(10) << __func__ << " start" << dendl; - OpSequencerRef osr = new OpSequencer; + OpSequencerRef osr = new OpSequencer(cct); int count = 0; KeyValueDB::Iterator it = db->get_iterator(PREFIX_WAL); for (it->lower_bound(string()); it->valid(); it->next(), ++count) { @@ -6982,7 +6981,7 @@ int BlueStore::queue_transactions( osr = static_cast(posr->p.get()); dout(10) << __func__ << " existing " << osr << " " << *osr << dendl; } else { - osr = new OpSequencer; + osr = new OpSequencer(cct); osr->parent = posr; posr->p = osr; dout(10) << __func__ << " new " << osr << " " << *osr << dendl; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index f41a8c5c478e..4cc50aecfd31 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1370,9 +1370,10 @@ public: std::atomic_int kv_committing_serially = {0}; - OpSequencer() + OpSequencer(CephContext* cct) //set the qlock to PTHREAD_MUTEX_RECURSIVE mode - : parent(NULL) { + : Sequencer_impl(cct), + parent(NULL) { } ~OpSequencer() { assert(q.empty()); @@ -1505,7 +1506,6 @@ public: // -------------------------------------------------------- // members private: - CephContext *cct; BlueFS *bluefs; unsigned bluefs_shared_bdev; ///< which bluefs bdev we are sharing KeyValueDB *db; diff --git a/src/os/filestore/DBObjectMap.h b/src/os/filestore/DBObjectMap.h index d23a246165b8..1f9cc0edeb60 100644 --- a/src/os/filestore/DBObjectMap.h +++ b/src/os/filestore/DBObjectMap.h @@ -115,9 +115,10 @@ public: } }; - explicit DBObjectMap(KeyValueDB *db) : db(db), header_lock("DBOBjectMap"), - cache_lock("DBObjectMap::CacheLock"), - caches(g_conf->filestore_omap_header_cache_size) + DBObjectMap(CephContext* cct, KeyValueDB *db) + : ObjectMap(cct), db(db), header_lock("DBOBjectMap"), + cache_lock("DBObjectMap::CacheLock"), + caches(cct->_conf->filestore_omap_header_cache_size) {} int set_keys( diff --git a/src/os/filestore/FileStore.cc b/src/os/filestore/FileStore.cc index ace293675bee..1af0dcc37cc8 100644 --- a/src/os/filestore/FileStore.cc +++ b/src/os/filestore/FileStore.cc @@ -516,8 +516,10 @@ int FileStore::lfn_unlink(const coll_t& cid, const ghobject_t& o, return 0; } -FileStore::FileStore(const std::string &base, const std::string &jdev, osflagbits_t flags, const char *name, bool do_update) : - JournalingObjectStore(base), +FileStore::FileStore(CephContext* cct, const std::string &base, + const std::string &jdev, osflagbits_t flags, + const char *name, bool do_update) : + JournalingObjectStore(cct, base), internal_name(name), basedir(base), journalpath(jdev), generic_flags(flags), @@ -1644,7 +1646,7 @@ int FileStore::mount() goto close_current_fd; } - DBObjectMap *dbomap = new DBObjectMap(omap_store); + DBObjectMap *dbomap = new DBObjectMap(cct, omap_store); ret = dbomap->init(do_update); if (ret < 0) { delete dbomap; @@ -2073,7 +2075,7 @@ int FileStore::queue_transactions(Sequencer *posr, vector& tls, osr = static_cast(posr->p.get()); dout(5) << "queue_transactions existing " << osr << " " << *osr << dendl; } else { - osr = new OpSequencer(next_osr_id.inc()); + osr = new OpSequencer(cct, next_osr_id.inc()); osr->set_cct(g_ceph_context); osr->parent = posr; posr->p = osr; diff --git a/src/os/filestore/FileStore.h b/src/os/filestore/FileStore.h index 300d6fd49136..2288965805ce 100644 --- a/src/os/filestore/FileStore.h +++ b/src/os/filestore/FileStore.h @@ -343,8 +343,9 @@ private: } } - explicit OpSequencer(int i) - : qlock("FileStore::OpSequencer::qlock", false, false), + OpSequencer(CephContext* cct, int i) + : Sequencer_impl(cct), + qlock("FileStore::OpSequencer::qlock", false, false), parent(0), apply_lock("FileStore::OpSequencer::apply_lock", false, false), id(i) {} @@ -438,8 +439,8 @@ public: bool force_clear_omap=false); public: - FileStore(const std::string &base, const std::string &jdev, - osflagbits_t flags = 0, + FileStore(CephContext* cct, const std::string &base, const std::string &jdev, + osflagbits_t flags = 0, const char *internal_name = "filestore", bool update_to=false); ~FileStore(); diff --git a/src/os/filestore/JournalingObjectStore.h b/src/os/filestore/JournalingObjectStore.h index 8b3bdaaba17f..5e07065ec613 100644 --- a/src/os/filestore/JournalingObjectStore.h +++ b/src/os/filestore/JournalingObjectStore.h @@ -129,10 +129,10 @@ public: } public: - explicit JournalingObjectStore(const std::string& path) - : ObjectStore(path), + JournalingObjectStore(CephContext* cct, const std::string& path) + : ObjectStore(cct, path), journal(NULL), - finisher(g_ceph_context, "JournalObjectStore", "fn_jrn_objstore"), + finisher(cct, "JournalObjectStore", "fn_jrn_objstore"), apply_manager(journal, finisher), replaying(false) {} diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index 912a5ebcb9be..6416ee36ab16 100755 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -625,8 +625,7 @@ KStore::OnodeRef KStore::Collection::get_onode( #define dout_prefix *_dout << "kstore(" << path << ") " KStore::KStore(CephContext *cct, const string& path) - : ObjectStore(path), - cct(cct), + : ObjectStore(cct, path), db(NULL), path_fd(-1), fsid_fd(-1), @@ -2135,7 +2134,7 @@ int KStore::queue_transactions( osr = static_cast(posr->p.get()); dout(10) << __func__ << " existing " << osr << " " << *osr << dendl; } else { - osr = new OpSequencer; + osr = new OpSequencer(cct); osr->parent = posr; posr->p = osr; dout(10) << __func__ << " new " << osr << " " << *osr << dendl; diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index b0533b073645..ea513a97274b 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -263,9 +263,10 @@ public: Sequencer *parent; - OpSequencer() + OpSequencer(CephContext* cct) //set the qlock to PTHREAD_MUTEX_RECURSIVE mode - : parent(NULL) { + : Sequencer_impl(cct), + parent(NULL) { } ~OpSequencer() { assert(q.empty()); @@ -309,7 +310,6 @@ public: // -------------------------------------------------------- // members private: - CephContext *cct; KeyValueDB *db; uuid_d fsid; int path_fd; ///< open handle to $path diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index be3e30641850..5b5e771312db 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -679,6 +679,8 @@ int MemStore::queue_transactions(Sequencer *osr, // Sequencer with a mutex. this guarantees ordering on a given sequencer, // while allowing operations on different sequencers to happen in parallel struct OpSequencer : public Sequencer_impl { + OpSequencer(CephContext* cct) : + Sequencer_impl(cct) {} std::mutex mutex; void flush() override {} bool flush_commit(Context*) override { return true; } @@ -687,7 +689,7 @@ int MemStore::queue_transactions(Sequencer *osr, std::unique_lock lock; if (osr) { if (!osr->p) { - osr->p = new OpSequencer(); + osr->p = new OpSequencer(cct); } auto seq = static_cast(osr->p.get()); lock = std::unique_lock(seq->mutex); diff --git a/src/os/memstore/MemStore.h b/src/os/memstore/MemStore.h index 2dc577aba5ea..ee1dadafd79b 100644 --- a/src/os/memstore/MemStore.h +++ b/src/os/memstore/MemStore.h @@ -30,9 +30,6 @@ #include "include/assert.h" class MemStore : public ObjectStore { -private: - CephContext *const cct; - public: struct Object : public RefCountedObject { std::mutex xattr_mutex; @@ -241,8 +238,7 @@ private: public: MemStore(CephContext *cct, const string& path) - : ObjectStore(path), - cct(cct), + : ObjectStore(cct, path), coll_lock("MemStore::coll_lock"), finisher(cct), used_bytes(0) {} diff --git a/src/test/ObjectMap/test_object_map.cc b/src/test/ObjectMap/test_object_map.cc index a38e579e16f3..e7eeda2646fc 100644 --- a/src/test/ObjectMap/test_object_map.cc +++ b/src/test/ObjectMap/test_object_map.cc @@ -525,7 +525,7 @@ public: virtual void SetUp() { char *path = getenv("OBJECT_MAP_PATH"); if (!path) { - db.reset(new DBObjectMap(new KeyValueDBMemory())); + db.reset(new DBObjectMap(g_ceph_context, new KeyValueDBMemory())); tester.db = db.get(); return; } @@ -536,7 +536,7 @@ public: KeyValueDB *store = KeyValueDB::create(g_ceph_context, "leveldb", strpath); assert(!store->create_and_open(cerr)); - db.reset(new DBObjectMap(store)); + db.reset(new DBObjectMap(g_ceph_context, store)); tester.db = db.get(); } diff --git a/src/test/bench/small_io_bench_fs.cc b/src/test/bench/small_io_bench_fs.cc index 7569b332d968..b02780ed2230 100644 --- a/src/test/bench/small_io_bench_fs.cc +++ b/src/test/bench/small_io_bench_fs.cc @@ -132,7 +132,7 @@ int main(int argc, char **argv) ops.insert(make_pair(vm["write-ratio"].as(), Bencher::WRITE)); ops.insert(make_pair(1-vm["write-ratio"].as(), Bencher::READ)); - FileStore fs(vm["filestore-path"].as(), + FileStore fs(g_ceph_context, vm["filestore-path"].as(), vm["journal-path"].as()); ObjectStore::Sequencer osr(__func__); diff --git a/src/test/filestore/TestFileStore.cc b/src/test/filestore/TestFileStore.cc index 6d857be41163..8cc6665394eb 100644 --- a/src/test/filestore/TestFileStore.cc +++ b/src/test/filestore/TestFileStore.cc @@ -30,7 +30,7 @@ TEST(FileStore, create) { { map pm; - FileStore fs("a", "b"); + FileStore fs(g_ceph_context, "a", "b"); TestFileStore::create_backend(fs, 0); fs.collect_metadata(&pm); ASSERT_EQ(pm["filestore_backend"], "generic"); @@ -38,7 +38,7 @@ TEST(FileStore, create) #if defined(__linux__) { map pm; - FileStore fs("a", "b"); + FileStore fs(g_ceph_context, "a", "b"); TestFileStore::create_backend(fs, BTRFS_SUPER_MAGIC); fs.collect_metadata(&pm); ASSERT_EQ(pm["filestore_backend"], "btrfs"); @@ -46,7 +46,7 @@ TEST(FileStore, create) # ifdef HAVE_LIBXFS { map pm; - FileStore fs("a", "b"); + FileStore fs(g_ceph_context, "a", "b"); TestFileStore::create_backend(fs, XFS_SUPER_MAGIC); fs.collect_metadata(&pm); ASSERT_EQ(pm["filestore_backend"], "xfs"); diff --git a/src/test/librbd/test_mock_AioImageRequest.cc b/src/test/librbd/test_mock_AioImageRequest.cc index 8e91b72a15d2..b481a8400112 100644 --- a/src/test/librbd/test_mock_AioImageRequest.cc +++ b/src/test/librbd/test_mock_AioImageRequest.cc @@ -128,6 +128,7 @@ AioObjectRead* AioObjectRead } // namespace librbd #include "librbd/AioImageRequest.cc" + template class librbd::AioImageRequest; namespace librbd { diff --git a/src/test/objectstore/test_idempotent.cc b/src/test/objectstore/test_idempotent.cc index 6b465b12f279..6df2cedb0dec 100644 --- a/src/test/objectstore/test_idempotent.cc +++ b/src/test/objectstore/test_idempotent.cc @@ -66,7 +66,8 @@ int main(int argc, char **argv) { KeyValueDB *_db = KeyValueDB::create(g_ceph_context, "leveldb", db_path); assert(!_db->create_and_open(std::cerr)); boost::scoped_ptr db(_db); - boost::scoped_ptr store(new FileStore(store_path, store_dev)); + boost::scoped_ptr store(new FileStore(cct.get(), store_path, + store_dev)); ObjectStore::Sequencer osr(__func__); coll_t coll(spg_t(pg_t(0,12),shard_id_t::NO_SHARD)); diff --git a/src/test/objectstore/test_idempotent_sequence.cc b/src/test/objectstore/test_idempotent_sequence.cc index 9d49e4d2e488..c4049beb80bf 100644 --- a/src/test/objectstore/test_idempotent_sequence.cc +++ b/src/test/objectstore/test_idempotent_sequence.cc @@ -78,10 +78,10 @@ int verify_at = 0; std::string status_file; int run_diff(std::string& a_path, std::string& a_journal, - std::string& b_path, std::string& b_journal) + std::string& b_path, std::string& b_journal) { - FileStore *a = new FileStore(a_path, a_journal, 0, "a"); - FileStore *b = new FileStore(b_path, b_journal, 0, "b"); + FileStore *a = new FileStore(g_ceph_context, a_path, a_journal, 0, "a"); + FileStore *b = new FileStore(g_ceph_context, b_path, b_journal, 0, "b"); int ret = 0; { @@ -101,7 +101,8 @@ int run_diff(std::string& a_path, std::string& a_journal, int run_get_last_op(std::string& filestore_path, std::string& journal_path) { - FileStore *store = new FileStore(filestore_path, journal_path); + FileStore *store = new FileStore(g_ceph_context, filestore_path, + journal_path); int err = store->mount(); if (err) { @@ -135,7 +136,8 @@ int run_sequence_to(int val, std::string& filestore_path, if (!is_seed_set) seed = (int) time(NULL); - FileStore *store = new FileStore(filestore_path, journal_path); + FileStore *store = new FileStore(g_ceph_context, filestore_path, + journal_path); int err; diff --git a/src/test/test_trans.cc b/src/test/test_trans.cc index 691b3cb0b794..db297f63db97 100644 --- a/src/test/test_trans.cc +++ b/src/test/test_trans.cc @@ -51,7 +51,7 @@ int main(int argc, const char **argv) cout << "#dev " << filename << std::endl; cout << "#mb " << mb << std::endl; - ObjectStore *fs = new FileStore(filename, NULL); + ObjectStore *fs = new FileStore(cct.get(), filename, NULL); if (fs->mount() < 0) { cout << "mount failed" << std::endl; return -1; diff --git a/src/test/xattr_bench.cc b/src/test/xattr_bench.cc index d1cb8cb3297b..2e016925fa15 100644 --- a/src/test/xattr_bench.cc +++ b/src/test/xattr_bench.cc @@ -165,7 +165,8 @@ int main(int argc, char **argv) { string store_path(args[1]); string store_dev(args[2]); - boost::scoped_ptr store(new FileStore(store_path, store_dev)); + boost::scoped_ptr store(new FileStore(cct.get(), store_path, + store_dev)); std::cerr << "mkfs starting" << std::endl; assert(!store->mkfs()); diff --git a/src/tools/ceph_osdomap_tool.cc b/src/tools/ceph_osdomap_tool.cc index 0fb6d98a1f1c..1ba13f082f1f 100644 --- a/src/tools/ceph_osdomap_tool.cc +++ b/src/tools/ceph_osdomap_tool.cc @@ -91,7 +91,7 @@ int main(int argc, char **argv) { std::cerr << "Enabling paranoid checks" << std::endl; store->options.paranoid_checks = true; }*/ - DBObjectMap omap(store); + DBObjectMap omap(cct.get(), store); stringstream out; int r = store->open(out); if (r < 0) {