]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os: Add CephContext to ObjectStore and ObjectMap bases
authorAdam C. Emerson <aemerson@redhat.com>
Thu, 8 Dec 2016 20:34:49 +0000 (15:34 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 22 Dec 2016 18:55:37 +0000 (13:55 -0500)
Preparatory to removing g_ceph_context and g_conf uses

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
22 files changed:
src/os/ObjectMap.h
src/os/ObjectStore.cc
src/os/ObjectStore.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/filestore/DBObjectMap.h
src/os/filestore/FileStore.cc
src/os/filestore/FileStore.h
src/os/filestore/JournalingObjectStore.h
src/os/kstore/KStore.cc
src/os/kstore/KStore.h
src/os/memstore/MemStore.cc
src/os/memstore/MemStore.h
src/test/ObjectMap/test_object_map.cc
src/test/bench/small_io_bench_fs.cc
src/test/filestore/TestFileStore.cc
src/test/librbd/test_mock_AioImageRequest.cc
src/test/objectstore/test_idempotent.cc
src/test/objectstore/test_idempotent_sequence.cc
src/test/test_trans.cc
src/test/xattr_bench.cc
src/tools/ceph_osdomap_tool.cc

index c4efc7fbc202a1b3d978ee83263bef3bd25860db..f7c2f5f1d1c24e9effccff732f408a62232acfa9 100644 (file)
@@ -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() {}
 };
 
index d03ab3b99e9768fbe500fc72ad8f390b197c62e6..215abc10a7593609d81b12268a1737fba971c1de 100644 (file)
@@ -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);
index 304e352b3a3688d8f3846ff289713582beec8adf..befbf102f3892413da3abc300f10e38b7833afe6 100644 (file)
@@ -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_impl> 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() {
index 219a3578a1360736373aa02fb9575ac38dd7fc37..34d8980bbfbb05555e1dca3f9a42c15823570161 100644 (file)
@@ -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<OpSequencer *>(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;
index f41a8c5c478e55cf66f1f59e8e96e617d99aefa2..4cc50aecfd31a2764590e61f136bf6777355188c 100644 (file)
@@ -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;
index d23a246165b876a813d4052c55ee4cf8fe2c7cbc..1f9cc0edeb60435befb99ce3807ae1d95bea4bd9 100644 (file)
@@ -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(
index ace293675beedaa646dad0ee02971aba2e776c95..1af0dcc37cc8d4603b49b12878a5ece03a97c3fd 100644 (file)
@@ -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<Transaction>& tls,
     osr = static_cast<OpSequencer *>(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;
index 300d6fd49136ee44a49b1eb49b1102c8224b0655..2288965805cebbb466ca7488b6943ff910fbd4d9 100644 (file)
@@ -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();
 
index 8b3bdaaba17fd16897575e2c13a85cd2598094ce..5e07065ec61335312f902fbd526ac8e00847fbaa 100644 (file)
@@ -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) {}
 
index 912a5ebcb9be5e1e13e7ba4bc9941a07cf975fa8..6416ee36ab161acc412451f6b743d0e32a3d90f1 100755 (executable)
@@ -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<OpSequencer *>(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;
index b0533b0736451ea122908e0a326d9a2402d693c3..ea513a97274b17f8d063765ecfc00884c0e841ed 100644 (file)
@@ -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
index be3e30641850e1096c7c06994bd5ff61a955c543..5b5e771312db33d1c729ae6f177f0c097e4f510c 100644 (file)
@@ -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<std::mutex> lock;
   if (osr) {
     if (!osr->p) {
-      osr->p = new OpSequencer();
+      osr->p = new OpSequencer(cct);
     }
     auto seq = static_cast<OpSequencer*>(osr->p.get());
     lock = std::unique_lock<std::mutex>(seq->mutex);
index 2dc577aba5ea7e00e49b424fce3932bc709ba522..ee1dadafd79b1634cfafce44d2ad95513aaa9544 100644 (file)
@@ -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) {}
index a38e579e16f30757ae88f04f11d37c0ec448fb02..e7eeda2646fc241c84f33f75ca8d158dcfccfe2d 100644 (file)
@@ -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();
   }
 
index 7569b332d968fb316d014b3df5f1ee7e0aba6e64..b02780ed2230b9b8a454c0c35a29762a56753abc 100644 (file)
@@ -132,7 +132,7 @@ int main(int argc, char **argv)
   ops.insert(make_pair(vm["write-ratio"].as<double>(), Bencher::WRITE));
   ops.insert(make_pair(1-vm["write-ratio"].as<double>(), Bencher::READ));
 
-  FileStore fs(vm["filestore-path"].as<string>(),
+  FileStore fs(g_ceph_context, vm["filestore-path"].as<string>(),
               vm["journal-path"].as<string>());
   ObjectStore::Sequencer osr(__func__);
 
index 6d857be41163e3ce41997d537d75d7e368164c71..8cc6665394eb55f5664f6ca3ffd8177d1af9cd7f 100644 (file)
@@ -30,7 +30,7 @@ TEST(FileStore, create)
 {
   {
     map<string,string> 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<string,string> 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<string,string> 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");
index 8e91b72a15d2d1a4c34d18b220c954eed72c9232..b481a8400112218460c52ab4888870e4b5d55256 100644 (file)
@@ -128,6 +128,7 @@ AioObjectRead<librbd::MockTestImageCtx>* AioObjectRead<librbd::MockTestImageCtx>
 } // namespace librbd
 
 #include "librbd/AioImageRequest.cc"
+
 template class librbd::AioImageRequest<librbd::MockTestImageCtx>;
 
 namespace librbd {
index 6b465b12f279c2e35793749389d42605f7a0d9e6..6df2cedb0dec930f8505ae0721b97f3327f0f3db 100644 (file)
@@ -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<KeyValueDB> db(_db);
-  boost::scoped_ptr<ObjectStore> store(new FileStore(store_path, store_dev));
+  boost::scoped_ptr<ObjectStore> 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));
index 9d49e4d2e488d21f57bdb8442674f0bd0b936adc..c4049beb80bf43ee4ae3868c6acf32ca39b1d572 100644 (file)
@@ -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;
 
index 691b3cb0b79486db6062042619a30e763e48c0fd..db297f63db9766852f948ffe7f72b5660ebd684e 100644 (file)
@@ -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;
index d1cb8cb3297b360ef0dc19b4e43976548ff14f36..2e016925fa157f31280b01d160ad1747b5bba381 100644 (file)
@@ -165,7 +165,8 @@ int main(int argc, char **argv) {
   string store_path(args[1]);
   string store_dev(args[2]);
 
-  boost::scoped_ptr<ObjectStore> store(new FileStore(store_path, store_dev));
+  boost::scoped_ptr<ObjectStore> store(new FileStore(cct.get(), store_path,
+                                                    store_dev));
 
   std::cerr << "mkfs starting" << std::endl;
   assert(!store->mkfs());
index 0fb6d98a1f1cccc70a397b7afa443065fb5f35bd..1ba13f082f1f3f390757b75bf6d06d7af9ddf9f7 100644 (file)
@@ -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) {