From: Adam C. Emerson Date: Thu, 8 Dec 2016 02:50:42 +0000 (-0500) Subject: os: Complete removal of g_ceph_context and g_conf X-Git-Tag: v12.0.0~384^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=921d6e050e5c14a560a17a970752711aeb11ac05;p=ceph.git os: Complete removal of g_ceph_context and g_conf And so it continues. Signed-off-by: Adam C. Emerson --- diff --git a/src/os/FuseStore.cc b/src/os/FuseStore.cc index bf767b11db27..06b869cb1589 100644 --- a/src/os/FuseStore.cc +++ b/src/os/FuseStore.cc @@ -20,7 +20,7 @@ #include #endif -#define dout_context g_ceph_context +#define dout_context store->cct #define dout_subsys ceph_subsys_fuse #include "common/debug.h" #undef dout_prefix @@ -106,7 +106,8 @@ enum { FN_HASH_VAL, }; -static int parse_fn(const char *path, coll_t *cid, ghobject_t *oid, string *key, +static int parse_fn(CephContext* cct, const char *path, coll_t *cid, + ghobject_t *oid, string *key, uint32_t *hash, uint32_t *hash_bits) { list v; @@ -121,7 +122,7 @@ static int parse_fn(const char *path, coll_t *cid, ghobject_t *oid, string *key, if (!*p) break; } - dout(10) << __func__ << " path " << path << " -> " << v << dendl; + ldout(cct, 10) << __func__ << " path " << path << " -> " << v << dendl; if (v.empty()) return FN_ROOT; @@ -229,17 +230,18 @@ static int parse_fn(const char *path, coll_t *cid, ghobject_t *oid, string *key, static int os_getattr(const char *path, struct stat *stbuf) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int t = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int t = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (t < 0) return t; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); stbuf->st_size = 0; @@ -380,17 +382,19 @@ static int os_readdir(const char *path, off_t offset, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << " offset " << offset << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << " offset " << offset + << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int t = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int t = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (t < 0) return t; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); // we can't shift 32 bits or else off_t will go negative @@ -461,13 +465,13 @@ static int os_readdir(const char *path, } else { last = ghobject_t::get_max(); } - dout(10) << __func__ << std::hex - << " offset " << offset << " hash " - << hobject_t::_reverse_bits(hash_value) - << std::dec - << "/" << hash_bits - << " first " << next << " last " << last - << dendl; + ldout(fs->store->cct, 10) << __func__ << std::hex + << " offset " << offset << " hash " + << hobject_t::_reverse_bits(hash_value) + << std::dec + << "/" << hash_bits + << " first " << next << " last " << last + << dendl; while (true) { vector ls; int r = fs->store->collection_list( @@ -541,17 +545,18 @@ static int os_readdir(const char *path, static int os_open(const char *path, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int t = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int t = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (t < 0) return t; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); bufferlist *pbl = 0; @@ -695,17 +700,18 @@ static int os_open(const char *path, struct fuse_file_info *fi) static int os_mkdir(const char *path, mode_t mode) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int f = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int f = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (f < 0) return f; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); ObjectStore::Transaction t; @@ -755,23 +761,26 @@ static int os_mkdir(const char *path, mode_t mode) static int os_chmod(const char *path, mode_t mode) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; return 0; } static int os_create(const char *path, mode_t mode, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int f = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int f = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (f < 0) return f; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); ObjectStore::Transaction t; @@ -835,13 +844,13 @@ static int os_create(const char *path, mode_t mode, struct fuse_file_info *fi) static int os_release(const char *path, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << dendl; fuse_context *fc = fuse_get_context(); FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; std::lock_guard l(fs->lock); FuseStore::OpenFile *o = reinterpret_cast(fi->fh); if (--o->ref == 0) { - dout(10) << __func__ << " closing last " << o->path << dendl; + ldout(fs->store->cct, 10) << __func__ << " closing last " << o->path << dendl; fs->open_files.erase(o->path); delete o; } @@ -851,10 +860,10 @@ static int os_release(const char *path, struct fuse_file_info *fi) static int os_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << " offset " << offset - << " size " << size << dendl; fuse_context *fc = fuse_get_context(); FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << " offset " << offset + << " size " << size << dendl; std::lock_guard l(fs->lock); FuseStore::OpenFile *o = reinterpret_cast(fi->fh); if (!o) @@ -872,10 +881,10 @@ static int os_read(const char *path, char *buf, size_t size, off_t offset, static int os_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << " offset " << offset - << " size " << size << dendl; fuse_context *fc = fuse_get_context(); FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << " offset " << offset + << " size " << size << dendl; std::lock_guard l(fs->lock); FuseStore::OpenFile *o = reinterpret_cast(fi->fh); if (!o) @@ -904,17 +913,18 @@ static int os_write(const char *path, const char *buf, size_t size, int os_flush(const char *path, struct fuse_file_info *fi) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int f = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int f = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (f < 0) return f; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); FuseStore::OpenFile *o = reinterpret_cast(fi->fh); @@ -962,17 +972,18 @@ int os_flush(const char *path, struct fuse_file_info *fi) static int os_unlink(const char *path) { - dout(10) << __func__ << " " << path << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int f = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int f = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (f < 0) return f; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); ObjectStore::Transaction t; @@ -1033,12 +1044,15 @@ static int os_unlink(const char *path) static int os_truncate(const char *path, off_t size) { - dout(10) << __func__ << " " << path << " size " << size << dendl; + fuse_context *fc = fuse_get_context(); + FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << " size " << size << dendl; coll_t cid; ghobject_t oid; string key; uint32_t hash_value, hash_bits; - int f = parse_fn(path, &cid, &oid, &key, &hash_value, &hash_bits); + int f = parse_fn(fs->store->cct, path, &cid, &oid, &key, &hash_value, + &hash_bits); if (f < 0) return f; @@ -1052,8 +1066,6 @@ static int os_truncate(const char *path, off_t size) if (f != FN_OBJECT_DATA) return -EPERM; - fuse_context *fc = fuse_get_context(); - FuseStore *fs = static_cast(fc->private_data); std::lock_guard l(fs->lock); if (fs->open_files.count(path)) { @@ -1078,9 +1090,9 @@ static int os_truncate(const char *path, off_t size) static int os_statfs(const char *path, struct statvfs *stbuf) { - dout(10) << __func__ << " " << path << dendl; fuse_context *fc = fuse_get_context(); FuseStore *fs = static_cast(fc->private_data); + ldout(fs->store->cct, 10) << __func__ << " " << path << dendl; std::lock_guard l(fs->lock); struct store_statfs_t s; @@ -1139,7 +1151,7 @@ int FuseStore::main() "-d", // debug }; int c = 3; - if (g_conf->fuse_debug) + if (store->cct->_conf->fuse_debug) ++c; return fuse_main(c, (char**)v, &fs_oper, (void*)this); } @@ -1156,7 +1168,7 @@ int FuseStore::start() "-d", // debug }; int c = 3; - if (g_conf->fuse_debug) + if (store->cct->_conf->fuse_debug) ++c; fuse_args a = FUSE_ARGS_INIT(c, (char**)v); info->args = a; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 0481cfafc5c6..79ce675b3c10 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -1,4 +1,3 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index 515221292120..2f3708fdc748 100755 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -29,7 +29,7 @@ #include "common/Formatter.h" -#define dout_context g_ceph_context +#define dout_context cct #define dout_subsys ceph_subsys_kstore /* @@ -249,7 +249,8 @@ static void get_coll_key_range(const coll_t& cid, int bits, static int get_key_object(const string& key, ghobject_t *oid); -static void get_object_key(const ghobject_t& oid, string *key) +static void get_object_key(CephContext* cct, const ghobject_t& oid, + string *key) { key->clear(); @@ -458,7 +459,7 @@ void KStore::OnodeHashLRU::clear() } void KStore::OnodeHashLRU::rename(const ghobject_t& old_oid, - const ghobject_t& new_oid) + const ghobject_t& new_oid) { std::lock_guard l(lock); dout(30) << __func__ << " " << old_oid << " -> " << new_oid << dendl; @@ -475,14 +476,14 @@ void KStore::OnodeHashLRU::rename(const ghobject_t& old_oid, OnodeRef o = po->second; // install a non-existent onode it its place - po->second.reset(new Onode(old_oid, o->key)); + po->second.reset(new Onode(cct, old_oid, o->key)); lru.push_back(*po->second); // fix oid, key onode_map.insert(make_pair(new_oid, o)); _touch(o); o->oid = new_oid; - get_object_key(new_oid, &o->key); + get_object_key(cct, new_oid, &o->key); } bool KStore::OnodeHashLRU::get_next( @@ -563,7 +564,7 @@ KStore::Collection::Collection(KStore *ns, coll_t c) : store(ns), cid(c), lock("KStore::Collection::lock", true, false), - onode_map() + onode_map(store->cct) { } @@ -576,8 +577,8 @@ KStore::OnodeRef KStore::Collection::get_onode( spg_t pgid; if (cid.is_pg(&pgid)) { if (!oid.match(cnode.bits, pgid.ps())) { - derr << __func__ << " oid " << oid << " not part of " << pgid - << " bits " << cnode.bits << dendl; + lderr(store->cct) << __func__ << " oid " << oid << " not part of " + << pgid << " bits " << cnode.bits << dendl; ceph_abort(); } } @@ -587,14 +588,14 @@ KStore::OnodeRef KStore::Collection::get_onode( return o; string key; - get_object_key(oid, &key); + get_object_key(store->cct, oid, &key); - dout(20) << __func__ << " oid " << oid << " key " - << pretty_binary_string(key) << dendl; + ldout(store->cct, 20) << __func__ << " oid " << oid << " key " + << pretty_binary_string(key) << dendl; bufferlist v; int r = store->db->get(PREFIX_OBJ, key, &v); - dout(20) << " r " << r << " v.len " << v.length() << dendl; + ldout(store->cct, 20) << " r " << r << " v.len " << v.length() << dendl; Onode *on; if (v.length() == 0) { assert(r == -ENOENT); @@ -602,12 +603,12 @@ KStore::OnodeRef KStore::Collection::get_onode( return OnodeRef(); // new - on = new Onode(oid, key); + on = new Onode(store->cct, oid, key); on->dirty = true; } else { // loaded assert(r >=0); - on = new Onode(oid, key); + on = new Onode(store->cct, oid, key); on->exists = true; bufferlist::iterator p = v.begin(); ::decode(on->onode, p); @@ -654,7 +655,7 @@ KStore::~KStore() void KStore::_init_logger() { // XXX - PerfCountersBuilder b(g_ceph_context, "KStore", + PerfCountersBuilder b(cct, "KStore", l_kstore_first, l_kstore_last); b.add_time_avg(l_kstore_state_prepare_lat, "state_prepare_lat", "Average prepare state latency"); b.add_time_avg(l_kstore_state_kv_queued_lat, "state_kv_queued_lat", "Average kv_queued state latency"); @@ -662,13 +663,13 @@ void KStore::_init_logger() b.add_time_avg(l_kstore_state_finishing_lat, "state_finishing_lat", "Average finishing state latency"); b.add_time_avg(l_kstore_state_done_lat, "state_done_lat", "Average done state latency"); logger = b.create_perf_counters(); - g_ceph_context->get_perfcounters_collection()->add(logger); + cct->get_perfcounters_collection()->add(logger); } void KStore::_shutdown_logger() { // XXX - g_ceph_context->get_perfcounters_collection()->remove(logger); + cct->get_perfcounters_collection()->remove(logger); delete logger; } @@ -804,7 +805,7 @@ int KStore::_open_db(bool create) string kv_backend; if (create) { - kv_backend = g_conf->kstore_backend; + kv_backend = cct->_conf->kstore_backend; } else { r = read_meta("kv_backend", &kv_backend); if (r < 0) { @@ -838,16 +839,14 @@ int KStore::_open_db(bool create) } } - db = KeyValueDB::create(g_ceph_context, - kv_backend, - fn); + db = KeyValueDB::create(cct, kv_backend, fn); if (!db) { derr << __func__ << " error creating db" << dendl; return -EIO; } string options; if (kv_backend == "rocksdb") - options = g_conf->kstore_rocksdb_options; + options = cct->_conf->kstore_rocksdb_options; db->init(options); stringstream err; if (create) @@ -945,7 +944,7 @@ int KStore::mkfs() if (r < 0) goto out_close_fsid; - r = write_meta("kv_backend", g_conf->kstore_backend); + r = write_meta("kv_backend", cct->_conf->kstore_backend); if (r < 0) goto out_close_db; @@ -973,8 +972,8 @@ int KStore::mount() { dout(1) << __func__ << " path " << path << dendl; - if (g_conf->kstore_fsck_on_mount) { - int rc = fsck(g_conf->kstore_fsck_on_mount_deep); + if (cct->_conf->kstore_fsck_on_mount) { + int rc = fsck(cct->_conf->kstore_fsck_on_mount_deep); if (rc < 0) return rc; } @@ -1472,7 +1471,7 @@ int KStore::_collection_list( temp = true; } else { string k; - get_object_key(start, &k); + get_object_key(cct, start, &k); if (start.hobj.is_temp()) { temp = true; assert(k >= temp_start_key && k < temp_end_key); @@ -1487,7 +1486,7 @@ int KStore::_collection_list( if (end.hobj.is_max()) { pend = temp ? temp_end_key : end_key; } else { - get_object_key(end, &end_key); + get_object_key(cct, end, &end_key); if (end.hobj.is_temp()) { if (temp) pend = end_key; @@ -1886,7 +1885,7 @@ void KStore::_assign_nid(TransContext *txc, OnodeRef o) o->onode.nid = ++nid_last; dout(20) << __func__ << " " << o->oid << " nid " << o->onode.nid << dendl; if (nid_last > nid_max) { - nid_max += g_conf->kstore_nid_prealloc; + nid_max += cct->_conf->kstore_nid_prealloc; bufferlist bl; ::encode(nid_max, bl); txc->t->set(PREFIX_SUPER, "nid_max", bl); @@ -1912,9 +1911,9 @@ void KStore::_txc_state_proc(TransContext *txc) case TransContext::STATE_PREPARE: txc->log_state_latency(logger, l_kstore_state_prepare_lat); txc->state = TransContext::STATE_KV_QUEUED; - if (!g_conf->kstore_sync_transaction) { + if (!cct->_conf->kstore_sync_transaction) { std::lock_guard l(kv_lock); - if (g_conf->kstore_sync_submit_transaction) { + if (cct->_conf->kstore_sync_submit_transaction) { int r = db->submit_transaction(txc->t); assert(r == 0); } @@ -2047,7 +2046,7 @@ void KStore::_osr_reap_done(OpSequencer *osr) } if (txc->first_collection) { - txc->first_collection->onode_map.trim(g_conf->kstore_onode_map_size); + txc->first_collection->onode_map.trim(cct->_conf->kstore_onode_map_size); } osr->q.pop_front(); @@ -2082,7 +2081,7 @@ void KStore::_kv_sync_thread() // one transaction to force a sync KeyValueDB::Transaction t = db->get_transaction(); - if (!g_conf->kstore_sync_submit_transaction) { + if (!cct->_conf->kstore_sync_submit_transaction) { for (std::deque::iterator it = kv_committing.begin(); it != kv_committing.end(); ++it) { @@ -2614,7 +2613,7 @@ int KStore::_do_write(TransContext *txc, uint64_t stripe_size = o->onode.stripe_size; if (!stripe_size) { - o->onode.stripe_size = g_conf->kstore_default_stripe_size; + o->onode.stripe_size = cct->_conf->kstore_default_stripe_size; stripe_size = o->onode.stripe_size; } @@ -2844,7 +2843,7 @@ int KStore::_do_remove(TransContext *txc, o->exists = false; o->onode = kstore_onode_t(); txc->onodes.erase(o); - get_object_key(o->oid, &key); + get_object_key(cct, o->oid, &key); txc->t->rmkey(PREFIX_OBJ, key); return 0; } diff --git a/src/os/kstore/KStore.h b/src/os/kstore/KStore.h index ea513a97274b..8499abe7a30a 100644 --- a/src/os/kstore/KStore.h +++ b/src/os/kstore/KStore.h @@ -57,6 +57,7 @@ public: /// an in-memory object struct Onode { + CephContext* cct; std::atomic_int nref; ///< reference count ghobject_t oid; @@ -76,8 +77,9 @@ public: map pending_stripes; ///< unwritten stripes - Onode(const ghobject_t& o, const string& k) - : nref(0), + Onode(CephContext* cct, const ghobject_t& o, const string& k) + : cct(cct), + nref(0), oid(o), key(k), dirty(false), @@ -104,6 +106,7 @@ public: typedef boost::intrusive_ptr OnodeRef; struct OnodeHashLRU { + CephContext* cct; typedef boost::intrusive::list< Onode, boost::intrusive::member_hook< @@ -115,7 +118,7 @@ public: ceph::unordered_map onode_map; ///< forward lookups lru_list_t lru; ///< lru - OnodeHashLRU() {} + OnodeHashLRU(CephContext* cct) : cct(cct) {} void add(const ghobject_t& oid, OnodeRef o); void _touch(OnodeRef o); diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index 5b5e771312db..4ff957527c59 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -29,7 +29,7 @@ #include "MemStore.h" #include "include/compat.h" -#define dout_context g_ceph_context +#define dout_context cct #define dout_subsys ceph_subsys_filestore #undef dout_prefix #define dout_prefix *_dout << "memstore(" << path << ") " @@ -225,10 +225,10 @@ int MemStore::statfs(struct store_statfs_t *st) { dout(10) << __func__ << dendl; st->reset(); - st->total = g_conf->memstore_device_bytes; + st->total = cct->_conf->memstore_device_bytes; st->available = MAX(int64_t(st->total) - int64_t(used_bytes), 0ll); dout(10) << __func__ << ": used_bytes: " << used_bytes - << "/" << g_conf->memstore_device_bytes << dendl; + << "/" << cct->_conf->memstore_device_bytes << dendl; return 0; }