]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Remove g_ceph_context and g_conf
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 7 Dec 2016 21:31:35 +0000 (16:31 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 22 Dec 2016 19:24:39 +0000 (14:24 -0500)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
32 files changed:
src/os/ObjectStore.cc
src/os/bluestore/Allocator.cc
src/os/bluestore/Allocator.h
src/os/bluestore/BitAllocator.cc
src/os/bluestore/BitAllocator.h
src/os/bluestore/BitMapAllocator.cc
src/os/bluestore/BitMapAllocator.h
src/os/bluestore/BitmapFreelistManager.cc
src/os/bluestore/BitmapFreelistManager.h
src/os/bluestore/BlockDevice.cc
src/os/bluestore/BlockDevice.h
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h
src/os/bluestore/BlueRocksEnv.cc
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/ExtentFreelistManager.cc
src/os/bluestore/ExtentFreelistManager.h
src/os/bluestore/FreelistManager.cc
src/os/bluestore/FreelistManager.h
src/os/bluestore/KernelDevice.cc
src/os/bluestore/KernelDevice.h
src/os/bluestore/NVMEDevice.cc
src/os/bluestore/NVMEDevice.h
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h
src/os/bluestore/bluefs_tool.cc
src/osdc/ObjectCacher.h
src/test/objectstore/Allocator_test.cc
src/test/objectstore/BitAllocator_test.cc
src/test/objectstore/test_bluefs.cc
src/test/objectstore/test_bluestore_types.cc

index 215abc10a7593609d81b12268a1737fba971c1de..7c86949fe463df1ca37a73554faaea1ecaa55459 100644 (file)
@@ -95,7 +95,7 @@ int ObjectStore::probe_block_device_fsid(
 #if defined(HAVE_LIBAIO)
   // first try bluestore -- it has a crc on its header and will fail
   // reliably.
-  r = BlueStore::get_block_device_fsid(path, fsid);
+  r = BlueStore::get_block_device_fsid(cct, path, fsid);
   if (r == 0) {
     lgeneric_dout(cct, 0) << __func__ << " " << path << " is bluestore, "
                          << *fsid << dendl;
index 638c7830e8ea95d46735ad4a22a6fe983f25f31f..8a4101eae2d817859debb0137ac1623cfd3fbe4e 100644 (file)
@@ -6,17 +6,17 @@
 #include "BitMapAllocator.h"
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_bluestore
 
-Allocator *Allocator::create(string type,
+Allocator *Allocator::create(CephContext* cct, string type,
                              int64_t size, int64_t block_size)
 {
   if (type == "stupid") {
-    return new StupidAllocator;
+    return new StupidAllocator(cct);
   } else if (type == "bitmap") {
-    return new BitMapAllocator(size, block_size);
+    return new BitMapAllocator(cct, size, block_size);
   }
-  derr << "Allocator::" << __func__ << " unknown alloc type " << type << dendl;
-  return NULL;
+  lderr(cct) << "Allocator::" << __func__ << " unknown alloc type "
+            << type << dendl;
+  return nullptr;
 }
index cbcbc3693be9db2b4d2e9693f49aab670c002c43..53acd429f644e6a5e9c9b3754947c1028929baeb 100644 (file)
@@ -66,7 +66,8 @@ public:
   virtual uint64_t get_free() = 0;
 
   virtual void shutdown() = 0;
-  static Allocator *create(string type, int64_t size, int64_t block_size);
+  static Allocator *create(CephContext* cct, string type, int64_t size,
+                          int64_t block_size);
 };
 
 #endif
index 0a8b3379fa420ca44545640fe0e9dc6d14621abd..d7ed7de9c225187e5b34fdf2223b0541947d9f40 100644 (file)
@@ -25,7 +25,7 @@
 #include "common/debug.h"
 #include <math.h>
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "bitalloc:"
@@ -113,7 +113,6 @@ void BmapEntityListIter::decr_idx()
 /*
  * Bitmap Entry functions.
  */
-
 void BmapEntry::_init_bit_mask()
 {
 
@@ -125,12 +124,13 @@ void BmapEntry::_init_bit_mask()
 
   uint64_t bmask = ((bmap_t) 0x1 << (BmapEntry::size() - 1));
   for (int i = 0; i < BmapEntry::size(); i++) {
-    m_bit_to_mask[i] = bmask >> i; 
+    m_bit_to_mask[i] = bmask >> i;
   }
   BmapEntry::m_bit_mask_init = true;
 }
 
-BmapEntry::BmapEntry(bool full)
+BmapEntry::BmapEntry(CephContext* cct, bool full)
+  : cct(cct)
 {
 
   BmapEntry::_init_bit_mask();
@@ -394,7 +394,7 @@ void BitMapZone::init(int64_t zone_num, int64_t total_blocks, bool def)
   alloc_assert(total_blocks < std::numeric_limits<int32_t>::max());
   alloc_assert(!(total_blocks % BmapEntry::size()));
 
-  BmapEntryVector *bmaps = new BmapEntryVector(num_bmaps, BmapEntry(def));
+  BmapEntryVector *bmaps = new BmapEntryVector(num_bmaps, BmapEntry(cct, def));
   m_bmap_list = bmaps;
   incr_count();
 }
@@ -431,12 +431,16 @@ int64_t BitMapZone::get_reserved_blocks()
   return 0;
 }
 
-BitMapZone::BitMapZone(int64_t total_blocks, int64_t zone_num)
+BitMapZone::BitMapZone(CephContext* cct, int64_t total_blocks,
+                      int64_t zone_num)
+  : BitMapArea(cct)
 {
   init(zone_num, total_blocks, false);
 }
 
-BitMapZone::BitMapZone(int64_t total_blocks, int64_t zone_num, bool def)
+BitMapZone::BitMapZone(CephContext* cct, int64_t total_blocks,
+                      int64_t zone_num, bool def)
+  : BitMapArea(cct)
 {
   init(zone_num, total_blocks, def);
 }
@@ -670,14 +674,14 @@ void BitMapZone::dump_state(int& count)
 /*
  * BitMapArea Leaf and non-Leaf functions.
  */
-int64_t BitMapArea::get_zone_size()
+int64_t BitMapArea::get_zone_size(CephContext* cct)
 {
-  return g_conf->bluestore_bitmapallocator_blocks_per_zone;
+  return cct->_conf->bluestore_bitmapallocator_blocks_per_zone;
 }
 
-int64_t BitMapArea::get_span_size()
+int64_t BitMapArea::get_span_size(CephContext* cct)
 {
-  return g_conf->bluestore_bitmapallocator_span_size;
+  return cct->_conf->bluestore_bitmapallocator_span_size;
 }
 
 bmap_area_type_t BitMapArea::level_to_type(int level)
@@ -691,11 +695,11 @@ bmap_area_type_t BitMapArea::level_to_type(int level)
   }
 }
 
-int BitMapArea::get_level(int64_t total_blocks)
+int BitMapArea::get_level(CephContext* cct, int64_t total_blocks)
 {
   int level = 1;
-  int64_t zone_size_block = get_zone_size();
-  int64_t span_size = get_span_size();
+  int64_t zone_size_block = get_zone_size(cct);
+  int64_t span_size = get_span_size(cct);
   int64_t spans = zone_size_block * span_size;
   while (spans < total_blocks) {
     spans *= span_size;
@@ -704,17 +708,17 @@ int BitMapArea::get_level(int64_t total_blocks)
   return level;
 }
 
-int64_t BitMapArea::get_level_factor(int level)
+int64_t BitMapArea::get_level_factor(CephContext* cct, int level)
 {
   alloc_assert(level > 0);
 
-  int64_t zone_size = get_zone_size();
+  int64_t zone_size = get_zone_size(cct);
   if (level == 1) {
     return zone_size;
   }
 
   int64_t level_factor = zone_size;
-  int64_t span_size = get_span_size();
+  int64_t span_size = get_span_size(cct);
   while (--level) {
     level_factor *= span_size;
   }
@@ -735,7 +739,8 @@ bmap_area_type_t BitMapArea::get_type()
 /*
  * BitMapArea Leaf and Internal
  */
-BitMapAreaIN::BitMapAreaIN()
+BitMapAreaIN::BitMapAreaIN(CephContext* cct)
+  : BitMapArea(cct)
 {
   // nothing
 }
@@ -744,7 +749,7 @@ void BitMapAreaIN::init_common(int64_t total_blocks, int64_t area_idx, bool def)
 {
   m_area_index = area_idx;
   m_total_blocks = total_blocks;
-  m_level = BitMapArea::get_level(total_blocks);
+  m_level = BitMapArea::get_level(cct, total_blocks);
   m_type = BitMapArea::level_to_type(m_level);
   m_reserved_blocks = 0;
 
@@ -757,7 +762,7 @@ void BitMapAreaIN::init(int64_t total_blocks, int64_t area_idx, bool def)
   alloc_assert(!(total_blocks % BmapEntry::size()));
 
   init_common(total_blocks, area_idx, def);
-  int64_t level_factor = BitMapArea::get_level_factor(m_level);
+  int64_t level_factor = BitMapArea::get_level_factor(cct, m_level);
 
   num_child = (total_blocks + level_factor - 1) / level_factor;
   alloc_assert(num_child < std::numeric_limits<int16_t>::max());
@@ -768,30 +773,34 @@ void BitMapAreaIN::init(int64_t total_blocks, int64_t area_idx, bool def)
   int i = 0;
   for (i = 0; i < num_child - 1; i++) {
     if (m_level <= 2) {
-      children[i] = new BitMapAreaLeaf(m_child_size_blocks, i, def);
+      children[i] = new BitMapAreaLeaf(cct, m_child_size_blocks, i, def);
     } else {
-      children[i] = new BitMapAreaIN(m_child_size_blocks, i, def);
+      children[i] = new BitMapAreaIN(cct, m_child_size_blocks, i, def);
     }
     total_blocks -= m_child_size_blocks;
   }
 
-  int last_level = BitMapArea::get_level(total_blocks);
+  int last_level = BitMapArea::get_level(cct, total_blocks);
   if (last_level == 1) {
-    children[i] = new BitMapAreaLeaf(total_blocks, i, def);
+    children[i] = new BitMapAreaLeaf(cct, total_blocks, i, def);
   } else {
-    children[i] = new BitMapAreaIN(total_blocks, i, def);
+    children[i] = new BitMapAreaIN(cct, total_blocks, i, def);
   }
   BitMapAreaList *list = new BitMapAreaList(children, num_child);
   m_child_list = list;
   m_num_child = num_child;
 }
 
-BitMapAreaIN::BitMapAreaIN(int64_t total_blocks, int64_t area_idx)
+BitMapAreaIN::BitMapAreaIN(CephContext* cct,int64_t total_blocks,
+                          int64_t area_idx)
+  : BitMapArea(cct)
 {
   init(total_blocks, area_idx, false);
 }
 
-BitMapAreaIN::BitMapAreaIN(int64_t total_blocks, int64_t area_idx, bool def)
+BitMapAreaIN::BitMapAreaIN(CephContext* cct, int64_t total_blocks,
+                          int64_t area_idx, bool def)
+  : BitMapArea(cct)
 {
   init(total_blocks, area_idx, def);
 }
@@ -1052,25 +1061,29 @@ void BitMapAreaIN::dump_state(int& count)
 /*
  * BitMapArea Leaf
  */
-BitMapAreaLeaf::BitMapAreaLeaf(int64_t total_blocks, int64_t area_idx)
+BitMapAreaLeaf::BitMapAreaLeaf(CephContext* cct, int64_t total_blocks,
+                              int64_t area_idx)
+  : BitMapAreaIN(cct)
 {
   init(total_blocks, area_idx, false);
 }
 
-BitMapAreaLeaf::BitMapAreaLeaf(int64_t total_blocks, int64_t area_idx, bool def)
+BitMapAreaLeaf::BitMapAreaLeaf(CephContext* cct, int64_t total_blocks,
+                              int64_t area_idx, bool def)
+  : BitMapAreaIN(cct)
 {
   init(total_blocks, area_idx, def);
 }
 
 void BitMapAreaLeaf::init(int64_t total_blocks, int64_t area_idx,
-          bool def)
+                         bool def)
 {
   int64_t num_child = 0;
   alloc_assert(!(total_blocks % BmapEntry::size()));
 
   init_common(total_blocks, area_idx, def);
   alloc_assert(m_level == 1);
-  int zone_size_block = get_zone_size();
+  int zone_size_block = get_zone_size(cct);
   alloc_assert(zone_size_block > 0);
   num_child = (total_blocks + zone_size_block - 1) / zone_size_block;
   alloc_assert(num_child);
@@ -1079,7 +1092,7 @@ void BitMapAreaLeaf::init(int64_t total_blocks, int64_t area_idx,
   alloc_assert(m_level == 1);
   BitMapArea **children = new BitMapArea*[num_child];
   for (int i = 0; i < num_child; i++) {
-      children[i] = new BitMapZone(m_child_size_blocks, i, def);
+    children[i] = new BitMapZone(cct, m_child_size_blocks, i, def);
   }
 
   BitMapAreaList *list = new BitMapAreaList(children, num_child);
@@ -1197,19 +1210,25 @@ BitMapAreaList::BitMapAreaList(BitMapArea **list, int64_t len)
 /*
  * Main allocator functions.
  */
-BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode)
+BitAllocator::BitAllocator(CephContext* cct, int64_t total_blocks,
+                          int64_t zone_size_block, bmap_alloc_mode_t mode)
+  : BitMapAreaIN(cct)
 {
   init_check(total_blocks, zone_size_block, mode, false, false);
 }
 
-BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block,
-         bmap_alloc_mode_t mode, bool def)
+BitAllocator::BitAllocator(CephContext* cct, int64_t total_blocks,
+                          int64_t zone_size_block, bmap_alloc_mode_t mode,
+                          bool def)
+  : BitMapAreaIN(cct)
 {
   init_check(total_blocks, zone_size_block, mode, def, false);
 }
 
-BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block,
-         bmap_alloc_mode_t mode, bool def, bool stats_on)
+BitAllocator::BitAllocator(CephContext* cct, int64_t total_blocks,
+                          int64_t zone_size_block, bmap_alloc_mode_t mode,
+                          bool def, bool stats_on)
+  : BitMapAreaIN(cct)
 {
   init_check(total_blocks, zone_size_block, mode, def, stats_on);
 }
@@ -1350,7 +1369,7 @@ bool BitAllocator::check_input(int64_t num_blocks)
     return false;
   }
 
-  if (num_blocks > get_zone_size()) {
+  if (num_blocks > get_zone_size(cct)) {
     return false;
   }
   return true;
index 2be2c4e3997cf19d6b385a8d85148ec693760254..38150fbd40e2ca7301d30d876695b75df34aa7f2 100644 (file)
@@ -143,6 +143,7 @@ typedef unsigned long bmap_t;
 typedef mempool::bluestore_alloc::vector<bmap_t> bmap_mask_vec_t;
 
 class BmapEntry {
+  CephContext* cct;
 
 private:
   bmap_t m_bits;
@@ -160,11 +161,12 @@ public:
   static bmap_t align_mask(int x);
   static bmap_t bit_mask(int bit_num);
   bmap_t atomic_fetch();
-  BmapEntry(bool val);
-  BmapEntry() {
+  BmapEntry(CephContext* cct, bool val);
+  BmapEntry(CephContext* cct) : cct(cct) {
     m_bits = 0;
   }
   BmapEntry(const BmapEntry& bmap) {
+    cct = bmap.cct;
     bmap_t i = bmap.m_bits;
     m_bits = i;
   }
@@ -198,6 +200,8 @@ typedef enum bmap_area_type {
 } bmap_area_type_t;
 
 class BitMapArea {
+public:
+  CephContext* cct;
 
 protected:
   int16_t m_area_index;
@@ -205,11 +209,11 @@ protected:
 
 public:
   MEMPOOL_CLASS_HELPERS();
-  static int64_t get_zone_size();
-  static int64_t get_span_size();
+  static int64_t get_zone_size(CephContext* cct);
+  static int64_t get_span_size(CephContext* cct);
   bmap_area_type_t level_to_type(int level);
-  static int get_level(int64_t total_blocks);
-  static int64_t get_level_factor(int level);
+  static int get_level(CephContext* cct, int64_t total_blocks);
+  static int64_t get_level_factor(CephContext* cct, int level);
   virtual bool is_allocated(int64_t start_block, int64_t num_blocks) = 0;
   virtual bool is_exhausted() = 0;
   virtual bool child_check_n_lock(BitMapArea *child, int64_t required) {
@@ -259,6 +263,7 @@ public:
   int64_t get_level();
   bmap_area_type_t get_type();
   virtual void dump_state(int& count) = 0;
+  BitMapArea(CephContext* cct) : cct(cct) {}
   virtual ~BitMapArea() { }
 };
 
@@ -349,8 +354,8 @@ public:
   void free_blocks_int(int64_t start_block, int64_t num_blocks);
   void init(int64_t zone_num, int64_t total_blocks, bool def);
 
-  BitMapZone(int64_t total_blocks, int64_t zone_num);
-  BitMapZone(int64_t total_blocks, int64_t zone_num, bool def);
+  BitMapZone(CephContext* cct, int64_t total_blocks, int64_t zone_num);
+  BitMapZone(CephContext* cct, int64_t total_blocks, int64_t zone_num, bool def);
 
   ~BitMapZone();
   void shutdown();
@@ -401,11 +406,15 @@ protected:
   int64_t alloc_blocks_dis_int_work(bool wrap, int64_t num_blocks, int64_t min_alloc, int64_t hint,
         int64_t blk_off, ExtentList *block_list);  
 
+  int64_t alloc_blocks_int_work(bool wait, bool wrap,
+                         int64_t num_blocks, int64_t hint, int64_t *start_block);
+
 public:
   MEMPOOL_CLASS_HELPERS();
-  BitMapAreaIN();
-  BitMapAreaIN(int64_t zone_num, int64_t total_blocks);
-  BitMapAreaIN(int64_t zone_num, int64_t total_blocks, bool def);
+  BitMapAreaIN(CephContext* cct);
+  BitMapAreaIN(CephContext* cct, int64_t zone_num, int64_t total_blocks);
+  BitMapAreaIN(CephContext* cct, int64_t zone_num, int64_t total_blocks,
+              bool def);
 
   virtual ~BitMapAreaIN();
   void shutdown();
@@ -442,9 +451,10 @@ public:
   MEMPOOL_CLASS_HELPERS();
   static int64_t count;
   static void incr_count() { count++;}
-  BitMapAreaLeaf() { }
-  BitMapAreaLeaf(int64_t zone_num, int64_t total_blocks);
-  BitMapAreaLeaf(int64_t zone_num, int64_t total_blocks, bool def);
+  BitMapAreaLeaf(CephContext* cct) : BitMapAreaIN(cct) { }
+  BitMapAreaLeaf(CephContext* cct, int64_t zone_num, int64_t total_blocks);
+  BitMapAreaLeaf(CephContext* cct, int64_t zone_num, int64_t total_blocks,
+                bool def);
 
   bool child_check_n_lock(BitMapArea *child, int64_t required) {
     ceph_abort();
@@ -503,9 +513,11 @@ private:
 public:
   MEMPOOL_CLASS_HELPERS();
 
-  BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode);
-  BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode, bool def);
-  BitAllocator(int64_t total_blocks, int64_t zone_size_block,
+  BitAllocator(CephContext* cct, int64_t total_blocks,
+              int64_t zone_size_block, bmap_alloc_mode_t mode);
+  BitAllocator(CephContext* cct, int64_t total_blocks, int64_t zone_size_block,
+              bmap_alloc_mode_t mode, bool def);
+  BitAllocator(CephContext* cct, int64_t total_blocks, int64_t zone_size_block,
                bmap_alloc_mode_t mode, bool def, bool stats_on);
   ~BitAllocator();
   void shutdown();
index 497a53cba8f1103a0ff93472ffaa3ce8e4837b93..7a8331f8f61707bd2e52bc2cbf6199fc20262c8d 100644 (file)
 #include "bluestore_types.h"
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "bitmapalloc:"
 
 
-BitMapAllocator::BitMapAllocator(int64_t device_size, int64_t block_size)
+BitMapAllocator::BitMapAllocator(CephContext* cct, int64_t device_size,
+                                int64_t block_size)
+  : cct(cct)
 {
   assert(ISP2(block_size));
   if (!ISP2(block_size)) {
@@ -28,7 +30,7 @@ BitMapAllocator::BitMapAllocator(int64_t device_size, int64_t block_size)
     return;
   }
 
-  int64_t zone_size_blks = g_conf->bluestore_bitmapallocator_blocks_per_zone;
+  int64_t zone_size_blks = cct->_conf->bluestore_bitmapallocator_blocks_per_zone;
   assert(ISP2(zone_size_blks));
   if (!ISP2(zone_size_blks)) {
     derr << __func__ << " zone_size " << zone_size_blks
@@ -37,7 +39,7 @@ BitMapAllocator::BitMapAllocator(int64_t device_size, int64_t block_size)
     return;
   }
 
-  int64_t span_size = g_conf->bluestore_bitmapallocator_span_size;
+  int64_t span_size = cct->_conf->bluestore_bitmapallocator_span_size;
   assert(ISP2(span_size));
   if (!ISP2(span_size)) {
     derr << __func__ << " span_size " << span_size
@@ -47,8 +49,8 @@ BitMapAllocator::BitMapAllocator(int64_t device_size, int64_t block_size)
   }
 
   m_block_size = block_size;
-  m_bit_alloc = new BitAllocator(device_size / block_size,
-        zone_size_blks, CONCURRENT, true);
+  m_bit_alloc = new BitAllocator(cct, device_size / block_size,
+                                zone_size_blks, CONCURRENT, true);
   assert(m_bit_alloc);
   if (!m_bit_alloc) {
     derr << __func__ << " Unable to intialize Bit Allocator" << dendl;
index a721e23ca057797a0186dad5917ed2043685eea2..a10c7e4324a264306fb014aef6f5a635becac57d 100644 (file)
@@ -11,6 +11,7 @@
 #include "include/btree_interval_set.h"
 
 class BitMapAllocator : public Allocator {
+  CephContext* cct;
   std::mutex m_lock;
 
   int64_t m_block_size;
@@ -24,8 +25,7 @@ class BitMapAllocator : public Allocator {
                         int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len);
 
 public:
-  BitMapAllocator();
-  BitMapAllocator(int64_t device_size, int64_t block_size);
+  BitMapAllocator(CephContext* cct, int64_t device_size, int64_t block_size);
   ~BitMapAllocator();
 
   int reserve(uint64_t need);
index bba7a6fe207511bd8fc94d4f2879947664ee7b86..27e55156204e6967c97007e622dad73153eb80fa 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "freelist "
@@ -46,10 +46,12 @@ void BitmapFreelistManager::setup_merge_operator(KeyValueDB *db, string prefix)
   db->set_merge_operator(prefix, merge_op);
 }
 
-BitmapFreelistManager::BitmapFreelistManager(KeyValueDB *db,
+BitmapFreelistManager::BitmapFreelistManager(CephContext* cct,
+                                            KeyValueDB *db,
                                             string meta_prefix,
                                             string bitmap_prefix)
-  : meta_prefix(meta_prefix),
+  : FreelistManager(cct),
+    meta_prefix(meta_prefix),
     bitmap_prefix(bitmap_prefix),
     kvdb(db)
 {
@@ -57,10 +59,10 @@ BitmapFreelistManager::BitmapFreelistManager(KeyValueDB *db,
 
 int BitmapFreelistManager::create(uint64_t new_size, KeyValueDB::Transaction txn)
 {
-  bytes_per_block = g_conf->bdev_block_size;
+  bytes_per_block = cct->_conf->bdev_block_size;
   assert(ISP2(bytes_per_block));
   size = P2ALIGN(new_size, bytes_per_block);
-  blocks_per_key = g_conf->bluestore_freelist_blocks_per_key;
+  blocks_per_key = cct->_conf->bluestore_freelist_blocks_per_key;
 
   _init_misc();
 
@@ -456,7 +458,7 @@ void BitmapFreelistManager::allocate(
 {
   dout(10) << __func__ << " 0x" << std::hex << offset << "~" << length
           << std::dec << dendl;
-  if (g_conf->bluestore_debug_freelist)
+  if (cct->_conf->bluestore_debug_freelist)
     _verify_range(offset, length, 0);
   _xor(offset, length, txn);
 }
@@ -467,7 +469,7 @@ void BitmapFreelistManager::release(
 {
   dout(10) << __func__ << " 0x" << std::hex << offset << "~" << length
           << std::dec << dendl;
-  if (g_conf->bluestore_debug_freelist)
+  if (cct->_conf->bluestore_debug_freelist)
     _verify_range(offset, length, 1);
   _xor(offset, length, txn);
 }
index 3119ae1bd5f77dba476d0baca23dd0a8c04b8114..7f8d062d912d810a9871be5748276c87d3a12c20 100644 (file)
@@ -46,7 +46,7 @@ class BitmapFreelistManager : public FreelistManager {
     KeyValueDB::Transaction txn);
 
 public:
-  BitmapFreelistManager(KeyValueDB *db, string meta_prefix,
+  BitmapFreelistManager(CephContext* cct, KeyValueDB *db, string meta_prefix,
                        string bitmap_prefix);
 
   static void setup_merge_operator(KeyValueDB *db, string prefix);
index 91a5912d21f0f2f50a08f31cb1d16249f6a7ed1f..f43914fa2889ea76fa6b1c4e6a08aca4f4ccf89f 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bdev
 #undef dout_prefix
 #define dout_prefix *_dout << "bdev "
@@ -44,7 +44,8 @@ void IOContext::aio_wait()
   dout(20) << __func__ << " " << this << " done" << dendl;
 }
 
-BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cbpriv)
+BlockDevice *BlockDevice::create(CephContext* cct, const string& path,
+                                aio_callback_t cb, void *cbpriv)
 {
   string type = "kernel";
   char buf[PATH_MAX + 1];
@@ -58,11 +59,11 @@ BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cb
   dout(1) << __func__ << " path " << path << " type " << type << dendl;
 
   if (type == "kernel") {
-    return new KernelDevice(cb, cbpriv);
+    return new KernelDevice(cct, cb, cbpriv);
   }
 #if defined(HAVE_SPDK)
   if (type == "ust-nvme") {
-    return new NVMEDevice(cb, cbpriv);
+    return new NVMEDevice(cct, cb, cbpriv);
   }
 #endif
 
index ba5b7facd2065ff3b81cc717c89f70585e65f163..3b0f08c911250ddfe4cda0ec1bd9f1d95b651c95 100644 (file)
@@ -28,6 +28,7 @@
 
 /// track in-flight io
 struct IOContext {
+  CephContext* cct;
   void *priv;
 #ifdef HAVE_SPDK
   void *nvme_task_first = nullptr;
@@ -44,13 +45,13 @@ struct IOContext {
   std::atomic_int num_reading = {0};
   std::atomic_int num_waiting = {0};
 
-  explicit IOContext(void *p)
-    : priv(p)
+  explicit IOContext(CephContext* cct, void *p)
+    : cct(cct), priv(p)
     {}
 
   // no copying
-  IOContext(const IOContext& other);
-  IOContext &operator=(const IOContext& other);
+  IOContext(const IOContext& other) = delete;
+  IOContext &operator=(const IOContext& other) = delete;
 
   bool has_pending_aios() {
     return num_pending.load();
@@ -68,6 +69,9 @@ struct IOContext {
 
 
 class BlockDevice {
+public:
+  CephContext* cct;
+private:
   std::mutex ioc_reap_lock;
   vector<IOContext*> ioc_reap_queue;
   std::atomic_int ioc_reap_count = {0};
@@ -76,12 +80,12 @@ protected:
   bool rotational = true;
 
 public:
-  BlockDevice() = default;
+  BlockDevice(CephContext* cct) : cct(cct) {}
   virtual ~BlockDevice() = default;
   typedef void (*aio_callback_t)(void *handle, void *aio);
 
   static BlockDevice *create(
-      const string& path, aio_callback_t cb, void *cbpriv);
+    CephContext* cct, const string& path, aio_callback_t cb, void *cbpriv);
   virtual bool supported_bdev_label() { return true; }
   virtual bool is_rotational() { return rotational; }
 
index ac2cdddc74f1c9e12b752474b03b5bb18c732265..1262706b5f0913edad8ff0f3768994a129c4c3ea 100644 (file)
@@ -9,7 +9,7 @@
 #include "BlockDevice.h"
 #include "Allocator.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluefs
 #undef dout_prefix
 #define dout_prefix *_dout << "bluefs "
@@ -23,8 +23,9 @@ MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileReader, bluefs_file_reader, bluefs);
 MEMPOOL_DEFINE_OBJECT_FACTORY(BlueFS::FileLock, bluefs_file_lock, bluefs);
 
 
-BlueFS::BlueFS()
-  : bdev(MAX_BDEV),
+BlueFS::BlueFS(CephContext* cct)
+  : cct(cct),
+    bdev(MAX_BDEV),
     ioc(MAX_BDEV),
     block_all(MAX_BDEV),
     block_total(MAX_BDEV, 0)
@@ -50,7 +51,7 @@ BlueFS::~BlueFS()
 
 void BlueFS::_init_logger()
 {
-  PerfCountersBuilder b(g_ceph_context, "BlueFS",
+  PerfCountersBuilder b(cct, "BlueFS",
                         l_bluefs_first, l_bluefs_last);
   b.add_u64_counter(l_bluefs_gift_bytes, "gift_bytes",
                    "Bytes gifted from BlueStore");
@@ -83,12 +84,12 @@ void BlueFS::_init_logger()
   b.add_u64_counter(l_bluefs_bytes_written_sst, "bytes_written_sst",
                    "Bytes written to SSTs");
   logger = b.create_perf_counters();
-  g_ceph_context->get_perfcounters_collection()->add(logger);
+  cct->get_perfcounters_collection()->add(logger);
 }
 
 void BlueFS::_shutdown_logger()
 {
-  g_ceph_context->get_perfcounters_collection()->remove(logger);
+  cct->get_perfcounters_collection()->remove(logger);
   delete logger;
 }
 
@@ -117,7 +118,7 @@ int BlueFS::add_block_device(unsigned id, string path)
   dout(10) << __func__ << " bdev " << id << " path " << path << dendl;
   assert(id < bdev.size());
   assert(bdev[id] == NULL);
-  BlockDevice *b = BlockDevice::create(path, NULL, NULL);
+  BlockDevice *b = BlockDevice::create(cct, path, NULL, NULL);
   int r = b->open(path);
   if (r < 0) {
     delete b;
@@ -126,7 +127,7 @@ int BlueFS::add_block_device(unsigned id, string path)
   dout(1) << __func__ << " bdev " << id << " path " << path
          << " size " << pretty_si_t(b->get_size()) << "B" << dendl;
   bdev[id] = b;
-  ioc[id] = new IOContext(NULL);
+  ioc[id] = new IOContext(cct, NULL);
   return 0;
 }
 
@@ -180,9 +181,9 @@ int BlueFS::reclaim_blocks(unsigned id, uint64_t want,
   assert(r == 0); // caller shouldn't ask for more than they can get
   int count = 0;
   uint64_t alloc_len = 0;;
-  AllocExtentVector extents = AllocExtentVector(want / g_conf->bluefs_alloc_size);
+  AllocExtentVector extents = AllocExtentVector(want / cct->_conf->bluefs_alloc_size);
 
-  r = alloc[id]->allocate(want, g_conf->bluefs_alloc_size, 0,
+  r = alloc[id]->allocate(want, cct->_conf->bluefs_alloc_size, 0,
                           &extents, &count, &alloc_len);
 
   *length = alloc_len;
@@ -285,7 +286,7 @@ int BlueFS::mkfs(uuid_d osd_uuid)
   log_file->fnode.prefer_bdev = BDEV_WAL;
   int r = _allocate(
     log_file->fnode.prefer_bdev,
-    g_conf->bluefs_max_log_runway,
+    cct->_conf->bluefs_max_log_runway,
     &log_file->fnode.extents);
   assert(r == 0);
   log_writer = _create_writer(log_file);
@@ -333,9 +334,9 @@ void BlueFS::_init_alloc()
       continue;
     }
     assert(bdev[id]->get_size());
-    alloc[id] = Allocator::create(g_conf->bluefs_allocator,
-                                  bdev[id]->get_size(),
-                                  g_conf->bluefs_alloc_size);
+    alloc[id] = Allocator::create(cct, cct->_conf->bluefs_allocator,
+                                 bdev[id]->get_size(),
+                                 cct->_conf->bluefs_alloc_size);
     interval_set<uint64_t>& p = block_all[id];
     for (interval_set<uint64_t>::iterator q = p.begin(); q != p.end(); ++q) {
       alloc[id]->init_add_free(q.get_start(), q.get_len());
@@ -499,7 +500,7 @@ int BlueFS::_replay(bool noop)
   dout(10) << __func__ << " log_fnode " << super.log_fnode << dendl;
 
   FileReader *log_reader = new FileReader(
-    log_file, g_conf->bluefs_max_prefetch,
+    log_file, cct->_conf->bluefs_max_prefetch,
     false,  // !random
     true);  // ignore eof
   while (true) {
@@ -867,7 +868,7 @@ int BlueFS::_read_random(
              << std::hex << x_off << "~" << l << std::dec
              << " of " << *p << dendl;
     int r = bdev[p->bdev]->read_random(p->offset + x_off, l, out,
-                                      g_conf->bluefs_buffered_io);
+                                      cct->_conf->bluefs_buffered_io);
     assert(r == 0);
     off += l;
     len -= l;
@@ -927,7 +928,7 @@ int BlueFS::_read(
                << std::hex << x_off << "~" << l << std::dec
                << " of " << *p << dendl;
       int r = bdev[p->bdev]->read(p->offset + x_off, l, &buf->bl, ioc[p->bdev],
-                                 g_conf->bluefs_buffered_io);
+                                 cct->_conf->bluefs_buffered_io);
       assert(r == 0);
     }
     left = buf->get_buf_remaining(off);
@@ -1002,7 +1003,7 @@ uint64_t BlueFS::_estimate_log_size()
 void BlueFS::compact_log()
 {
   std::unique_lock<std::mutex> l(lock);
-  if (g_conf->bluefs_compact_log_sync) {
+  if (cct->_conf->bluefs_compact_log_sync) {
      _compact_log_sync();
   } else {
     _compact_log_async(l);
@@ -1020,8 +1021,8 @@ bool BlueFS::_should_compact_log()
           << (new_log ? " (async compaction in progress)" : "")
           << dendl;
   if (new_log ||
-      current < g_conf->bluefs_log_compact_min_size ||
-      ratio < g_conf->bluefs_log_compact_min_ratio) {
+      current < cct->_conf->bluefs_log_compact_min_size ||
+      ratio < cct->_conf->bluefs_log_compact_min_ratio) {
     return false;
   }
   return true;
@@ -1079,7 +1080,7 @@ void BlueFS::_compact_log_sync()
   ::encode(t, bl);
   _pad_bl(bl);
 
-  uint64_t need = bl.length() + g_conf->bluefs_max_log_runway;
+  uint64_t need = bl.length() + cct->_conf->bluefs_max_log_runway;
   dout(20) << __func__ << " need " << need << dendl;
 
   mempool::bluefs::vector<bluefs_extent_t> old_extents;
@@ -1145,12 +1146,12 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
 
   // 1. allocate new log space and jump to it.
   old_log_jump_to = log_file->fnode.get_allocated();
-  uint64_t need = old_log_jump_to + g_conf->bluefs_max_log_runway;
+  uint64_t need = old_log_jump_to + cct->_conf->bluefs_max_log_runway;
   dout(10) << __func__ << " old_log_jump_to 0x" << std::hex << old_log_jump_to
            << " need 0x" << need << std::dec << dendl;
   while (log_file->fnode.get_allocated() < need) {
     int r = _allocate(log_file->fnode.prefer_bdev,
-                     g_conf->bluefs_max_log_runway,
+                     cct->_conf->bluefs_max_log_runway,
                      &log_file->fnode.extents);
     assert(r == 0);
   }
@@ -1168,7 +1169,7 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
 
   // conservative estimate for final encoded size
   new_log_jump_to = ROUND_UP_TO(t.op_bl.length() + super.block_size * 2,
-                                g_conf->bluefs_alloc_size);
+                                cct->_conf->bluefs_alloc_size);
   t.op_jump(log_seq, new_log_jump_to);
 
   bufferlist bl;
@@ -1324,7 +1325,7 @@ int BlueFS::_flush_and_sync_log(std::unique_lock<std::mutex>& l,
   // allocate some more space (before we run out)?
   int64_t runway = log_writer->file->fnode.get_allocated() -
     log_writer->get_effective_write_pos();
-  if (runway < (int64_t)g_conf->bluefs_min_log_runway) {
+  if (runway < (int64_t)cct->_conf->bluefs_min_log_runway) {
     dout(10) << __func__ << " allocating more log runway (0x"
             << std::hex << runway << std::dec  << " remaining)" << dendl;
     while (new_log_writer) {
@@ -1332,7 +1333,7 @@ int BlueFS::_flush_and_sync_log(std::unique_lock<std::mutex>& l,
       log_cond.wait(l);
     }
     int r = _allocate(log_writer->file->fnode.prefer_bdev,
-                     g_conf->bluefs_max_log_runway,
+                     cct->_conf->bluefs_max_log_runway,
                      &log_writer->file->fnode.extents);
     assert(r == 0);
     log_t.op_file_update(log_writer->file->fnode);
@@ -1423,7 +1424,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
   if (h->file->fnode.ino == 1)
     buffered = false;
   else
-    buffered = g_conf->bluefs_buffered_io;
+    buffered = cct->_conf->bluefs_buffered_io;
 
   if (offset + length <= h->pos)
     return 0;
@@ -1454,7 +1455,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
            << dendl;
       return r;
     }
-    if (g_conf->bluefs_preextend_wal_files &&
+    if (cct->_conf->bluefs_preextend_wal_files &&
        h->writer_type == WRITER_WAL) {
       // NOTE: this *requires* that rocksdb also has log recycling
       // enabled and is therefore doing robust CRCs on the log
@@ -1637,9 +1638,9 @@ int BlueFS::_flush(FileWriter *h, bool force)
   uint64_t length = h->buffer.length();
   uint64_t offset = h->pos;
   if (!force &&
-      length < g_conf->bluefs_min_flush_size) {
+      length < cct->_conf->bluefs_min_flush_size) {
     dout(10) << __func__ << " " << h << " ignoring, length " << length
-            << " < min_flush_size " << g_conf->bluefs_min_flush_size
+            << " < min_flush_size " << cct->_conf->bluefs_min_flush_size
             << dendl;
     return 0;
   }
@@ -1736,7 +1737,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len,
   dout(10) << __func__ << " len 0x" << std::hex << len << std::dec
            << " from " << (int)id << dendl;
   assert(id < alloc.size());
-  uint64_t min_alloc_size = g_conf->bluefs_alloc_size;
+  uint64_t min_alloc_size = cct->_conf->bluefs_alloc_size;
 
   uint64_t left = ROUND_UP_TO(len, min_alloc_size);
   int r = -ENOSPC;
@@ -1836,7 +1837,7 @@ void BlueFS::sync_metadata()
   }
 
   if (_should_compact_log()) {
-    if (g_conf->bluefs_compact_log_sync) {
+    if (cct->_conf->bluefs_compact_log_sync) {
       _compact_log_sync();
     } else {
       _compact_log_async(l);
@@ -1946,7 +1947,7 @@ BlueFS::FileWriter *BlueFS::_create_writer(FileRef f)
   FileWriter *w = new FileWriter(f);
   for (unsigned i = 0; i < MAX_BDEV; ++i) {
     if (bdev[i]) {
-      w->iocv[i] = new IOContext(NULL);
+      w->iocv[i] = new IOContext(cct, NULL);
     } else {
       w->iocv[i] = NULL;
     }
@@ -1992,7 +1993,7 @@ int BlueFS::open_for_read(
   }
   File *file = q->second.get();
 
-  *h = new FileReader(file, random ? 4096 : g_conf->bluefs_max_prefetch,
+  *h = new FileReader(file, random ? 4096 : cct->_conf->bluefs_max_prefetch,
                      random, false);
   dout(10) << __func__ << " h " << *h << " on " << file->fnode << dendl;
   return 0;
index ed4c9edbc21e91ebda100556f0388bdc6d5e7520..f2bb86f2d3d1d5269b7cb12d8a19d4024177e174 100644 (file)
@@ -40,6 +40,7 @@ enum {
 
 class BlueFS {
 public:
+  CephContext* cct;
   static constexpr unsigned MAX_BDEV = 3;
   static constexpr unsigned BDEV_WAL = 0;
   static constexpr unsigned BDEV_DB = 1;
@@ -322,7 +323,7 @@ private:
   }
 
 public:
-  BlueFS();
+  BlueFS(CephContext* cct);
   ~BlueFS();
 
   // the super is always stored on bdev 0
index fb34487984245f7f6b1d8202cd71912f9d5c9b55..d37d725035ad1c62c629f43363fff2fd06430ae8 100644 (file)
@@ -133,7 +133,7 @@ class BlueRocksRandomAccessFile : public rocksdb::RandomAccessFile {
     if (pattern == RANDOM)
       h->buf.max_prefetch = 4096;
     else if (pattern == SEQUENTIAL)
-      h->buf.max_prefetch = g_conf->bluefs_max_prefetch;
+      h->buf.max_prefetch = fs->cct->_conf->bluefs_max_prefetch;
   }
 
   // Remove any kind of caching of data from the offset to offset+length
index 34d8980bbfbb05555e1dca3f9a42c15823570161..0481cfafc5c6500742e4808c0d3b8a2cf4d4fb35 100644 (file)
@@ -31,7 +31,7 @@
 #include "BlueRocksEnv.h"
 #include "auth/Crypto.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 
 // bluestore_meta_onode
@@ -278,7 +278,8 @@ static int get_key_shared_blob(const string& key, uint64_t *sbid)
 
 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();
 
@@ -506,14 +507,15 @@ ostream& operator<<(ostream& out, const BlueStore::Buffer& b)
 
 // Cache
 
-BlueStore::Cache *BlueStore::Cache::create(string type, PerfCounters *logger)
+BlueStore::Cache *BlueStore::Cache::create(CephContext* cct, string type,
+                                          PerfCounters *logger)
 {
   Cache *c = nullptr;
 
   if (type == "lru")
-    c = new LRUCache;
+    c = new LRUCache(cct);
   else if (type == "2q")
-    c = new TwoQCache;
+    c = new TwoQCache(cct);
   else
     assert(0 == "unrecognized cache type");
 
@@ -787,7 +789,7 @@ void BlueStore::TwoQCache::_trim(uint64_t onode_max, uint64_t buffer_max)
 
   // buffers
   if (buffer_bytes > buffer_max) {
-    uint64_t kin = buffer_max * g_conf->bluestore_2q_cache_kin_ratio;
+    uint64_t kin = buffer_max * cct->_conf->bluestore_2q_cache_kin_ratio;
     uint64_t khot = buffer_max - kin;
 
     // pre-calculate kout based on average buffer size too,
@@ -798,7 +800,7 @@ void BlueStore::TwoQCache::_trim(uint64_t onode_max, uint64_t buffer_max)
       uint64_t buffer_avg_size = buffer_bytes / buffer_num;
       assert(buffer_avg_size);
       uint64_t calculated_buffer_num = buffer_max / buffer_avg_size;
-      kout = calculated_buffer_num * g_conf->bluestore_2q_cache_kout_ratio;
+      kout = calculated_buffer_num * cct->_conf->bluestore_2q_cache_kout_ratio;
     }
 
     if (buffer_list_bytes[BUFFER_HOT] < khot) {
@@ -958,7 +960,7 @@ void BlueStore::TwoQCache::_audit(const char *when)
 void BlueStore::BufferSpace::_clear()
 {
   // note: we already hold cache->lock
-  dout(10) << __func__ << dendl;
+  ldout(cache->cct, 10) << __func__ << dendl;
   while (!buffer_map.empty()) {
     _rm_buffer(buffer_map.begin());
   }
@@ -967,7 +969,7 @@ void BlueStore::BufferSpace::_clear()
 int BlueStore::BufferSpace::_discard(uint64_t offset, uint64_t length)
 {
   // note: we already hold cache->lock
-  dout(20) << __func__ << std::hex << " 0x" << offset << "~" << length
+  ldout(cache->cct, 20) << __func__ << std::hex << " 0x" << offset << "~" << length
            << std::dec << dendl;
   int cache_private = 0;
   cache->_audit("discard start");
@@ -1106,7 +1108,7 @@ void BlueStore::BufferSpace::finish_write(uint64_t seq)
     }
 
     Buffer *b = &*i;
-    dout(20) << __func__ << " " << *b << dendl;
+    ldout(cache->cct, 20) << __func__ << " " << *b << dendl;
     assert(b->is_writing());
 
     if (b->flags & Buffer::FLAG_NOCACHE) {
@@ -1135,7 +1137,7 @@ void BlueStore::BufferSpace::split(size_t pos, BlueStore::BufferSpace &r)
       break;
 
     if (p->second->offset < pos) {
-      dout(30) << __func__ << " cut " << *p->second << dendl;
+      ldout(cache->cct, 30) << __func__ << " cut " << *p->second << dendl;
       size_t left = pos - p->second->offset;
       size_t right = p->second->length - left;
       if (p->second->data.length()) {
@@ -1153,7 +1155,7 @@ void BlueStore::BufferSpace::split(size_t pos, BlueStore::BufferSpace &r)
     }
 
     assert(p->second->end() > pos);
-    dout(30) << __func__ << " move " << *p->second << dendl;
+    ldout(cache->cct, 30) << __func__ << " move " << *p->second << dendl;
     if (p->second->data.length()) {
       r._add_buffer(new Buffer(&r, p->second->state, p->second->seq,
                                p->second->offset - pos, p->second->data),
@@ -1183,11 +1185,12 @@ BlueStore::OnodeRef BlueStore::OnodeSpace::add(const ghobject_t& oid, OnodeRef o
   std::lock_guard<std::recursive_mutex> l(cache->lock);
   auto p = onode_map.find(oid);
   if (p != onode_map.end()) {
-    dout(30) << __func__ << " " << oid << " " << o
-            << " raced, returning existing " << p->second << dendl;
+    ldout(cache->cct, 30) << __func__ << " " << oid << " " << o
+                         << " raced, returning existing " << p->second
+                         << dendl;
     return p->second;
   }
-  dout(30) << __func__ << " " << oid << " " << o << dendl;
+  ldout(cache->cct, 30) << __func__ << " " << oid << " " << o << dendl;
   onode_map[oid] = o;
   cache->_add_onode(o, 1);
   return o;
@@ -1196,14 +1199,15 @@ BlueStore::OnodeRef BlueStore::OnodeSpace::add(const ghobject_t& oid, OnodeRef o
 BlueStore::OnodeRef BlueStore::OnodeSpace::lookup(const ghobject_t& oid)
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
-  dout(30) << __func__ << dendl;
+  ldout(cache->cct, 30) << __func__ << dendl;
   ceph::unordered_map<ghobject_t,OnodeRef>::iterator p = onode_map.find(oid);
   if (p == onode_map.end()) {
-    dout(30) << __func__ << " " << oid << " miss" << dendl;
+    ldout(cache->cct, 30) << __func__ << " " << oid << " miss" << dendl;
     cache->logger->inc(l_bluestore_onode_misses);
     return OnodeRef();
   }
-  dout(30) << __func__ << " " << oid << " hit " << p->second << dendl;
+  ldout(cache->cct, 30) << __func__ << " " << oid << " hit " << p->second
+                       << dendl;
   cache->_touch_onode(p->second);
   cache->logger->inc(l_bluestore_onode_hits);
   return p->second;
@@ -1212,7 +1216,7 @@ BlueStore::OnodeRef BlueStore::OnodeSpace::lookup(const ghobject_t& oid)
 void BlueStore::OnodeSpace::clear()
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
-  dout(10) << __func__ << dendl;
+  ldout(cache->cct, 10) << __func__ << dendl;
   for (auto &p : onode_map) {
     cache->_rm_onode(p.second);
   }
@@ -1223,7 +1227,7 @@ void BlueStore::OnodeSpace::clear_pre_split(SharedBlobSet& sbset,
                                            uint32_t ps, int bits)
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
-  dout(10) << __func__ << dendl;
+  ldout(cache->cct, 10) << __func__ << dendl;
 
   auto p = onode_map.begin();
   while (p != onode_map.end()) {
@@ -1259,7 +1263,8 @@ void BlueStore::OnodeSpace::rename(OnodeRef& oldo,
                                     const string& new_okey)
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
-  dout(30) << __func__ << " " << old_oid << " -> " << new_oid << dendl;
+  ldout(cache->cct, 30) << __func__ << " " << old_oid << " -> " << new_oid
+                       << dendl;
   ceph::unordered_map<ghobject_t,OnodeRef>::iterator po, pn;
   po = onode_map.find(old_oid);
   pn = onode_map.find(new_oid);
@@ -1267,7 +1272,8 @@ void BlueStore::OnodeSpace::rename(OnodeRef& oldo,
 
   assert(po != onode_map.end());
   if (pn != onode_map.end()) {
-    dout(30) << __func__ << "  removing target " << pn->second << dendl;
+    ldout(cache->cct, 30) << __func__ << "  removing target " << pn->second
+                         << dendl;
     cache->_rm_onode(pn->second);
     onode_map.erase(pn);
   }
@@ -1288,7 +1294,7 @@ void BlueStore::OnodeSpace::rename(OnodeRef& oldo,
 bool BlueStore::OnodeSpace::map_any(std::function<bool(OnodeRef)> f)
 {
   std::lock_guard<std::recursive_mutex> l(cache->lock);
-  dout(20) << __func__ << dendl;
+  ldout(cache->cct, 20) << __func__ << dendl;
   for (auto& i : onode_map) {
     if (f(i.second)) {
       return true;
@@ -1333,14 +1339,16 @@ BlueStore::SharedBlob::~SharedBlob()
 void BlueStore::SharedBlob::put()
 {
   if (--nref == 0) {
-    dout(20) << __func__ << " " << this
-            << " removing self from set " << parent_set << dendl;
+    ldout(bc.cache->cct, 20) << __func__ << " " << this
+                              << " removing self from set " << parent_set
+                              << dendl;
     if (parent_set) {
       if (parent_set->remove(this)) {
        delete this;
       } else {
-       dout(20) << __func__ << " " << this
-                << " lost race to remove myself from set" << dendl;
+       ldout(bc.cache->cct, 20)
+         << __func__ << " " << this << " lost race to remove myself from set"
+         << dendl;
       }
     } else {
       delete this;
@@ -1604,9 +1612,9 @@ ostream& operator<<(ostream& out, const BlueStore::Extent& e)
 #undef dout_prefix
 #define dout_prefix *_dout << "bluestore.extentmap(" << this << ") "
 
-BlueStore::ExtentMap::ExtentMap(Onode *o)
-  : onode(o),
-    inline_bl(g_conf->bluestore_extent_map_inline_shard_prealloc_size) {
+BlueStore::ExtentMap::ExtentMap(CephContext* cct, Onode *o)
+  : cct(cct), onode(o),
+    inline_bl(cct->_conf->bluestore_extent_map_inline_shard_prealloc_size) {
 }
 
 bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
@@ -1620,9 +1628,8 @@ bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
       bool never_happen = encode_some(0, OBJECT_MAX_SIZE, inline_bl, &n);
       assert(!never_happen);
       size_t len = inline_bl.length();
-      dout(20) << __func__ << " inline shard "
-              << len << " bytes from " << n << " extents" << dendl;
-      if (!force && len > g_conf->bluestore_extent_map_shard_max_size) {
+      dout(20) << __func__ << " inline shard " << len << " bytes from " << n<< " extents" << dendl;
+      if (!force && len > cct->_conf->bluestore_extent_map_shard_max_size) {
        return true;
       }
     }
@@ -1667,16 +1674,17 @@ bool BlueStore::ExtentMap::update(KeyValueDB::Transaction t,
          return true;
        }
         size_t len = bl.length();
+
        dout(20) << __func__ << " shard 0x" << std::hex
                 << p->offset << std::dec << " is " << len
                 << " bytes (was " << p->shard_info->bytes << ") from " << nn
                 << " extents" << dendl;
 
         //indicate need for reshard if force mode selected, len > shard_max size OR
-        //non-last shard size is below the min threshold. The last check is to avoid potential 
+        //non-last shard size is below the min threshold. The last check is to avoid potential
         //unneeded reshardings since this might happen permanently.
         if (!force &&
-             (len > g_conf->bluestore_extent_map_shard_max_size ||
+             (len > cct->_conf->bluestore_extent_map_shard_max_size ||
                (n != shards.end() && len < g_conf->bluestore_extent_map_shard_min_size))) {
           return true;
         }
@@ -1728,11 +1736,12 @@ void BlueStore::ExtentMap::reshard(uint64_t min_alloc_size)
       bytes += s.bytes;
     }
   }
-  unsigned target = g_conf->bluestore_extent_map_shard_target_size;
-  unsigned slop = target * g_conf->bluestore_extent_map_shard_target_size_slop;
+  unsigned target = cct->_conf->bluestore_extent_map_shard_target_size;
+  unsigned slop = target *
+    cct->_conf->bluestore_extent_map_shard_target_size_slop;
   unsigned extent_avg = bytes / extent_map.size();
-  dout(20) << __func__ << " extent_avg " << extent_avg
-          << " target " << target << " slop " << slop << dendl;
+  dout(20) << __func__ << " extent_avg " << extent_avg << " target " << target
+          << " slop " << slop << dendl;
 
   // reshard
   unsigned estimate = 0;
@@ -1756,8 +1765,8 @@ void BlueStore::ExtentMap::reshard(uint64_t min_alloc_size)
       offset = e.logical_offset;
       new_shard_info.emplace_back(bluestore_onode_t::shard_info());
       new_shard_info.back().offset = offset;
-      dout(20) << __func__ << "  new shard 0x" << std::hex << offset << std::dec
-              << dendl;
+      dout(20) << __func__ << "  new shard 0x" << std::hex << offset
+              << std::dec << dendl;
       estimate = 0;
     }
     estimate += extent_avg;
@@ -1818,9 +1827,8 @@ void BlueStore::ExtentMap::reshard(uint64_t min_alloc_size)
              if (b->get_blob().can_split_at(blob_offset) &&
                  blob_offset % min_alloc_size == 0) {
                dout(20) << __func__ << "    splitting blob, bstart 0x"
-                        << std::hex << bstart
-                        << " blob_offset 0x" << blob_offset
-                        << std::dec << " " << *b << dendl;
+                        << std::hex << bstart << " blob_offset 0x"
+                        << blob_offset << std::dec << " " << *b << dendl;
                b = split_blob(b, blob_offset, sh.offset);
                // switch b to the new right-hand side, in case it
                // *also* has to get split.
@@ -1983,7 +1991,7 @@ void BlueStore::ExtentMap::decode_some(bufferlist& bl)
        le->assign_blob(blobs[blobid - 1]);
        assert(le->blob);
       } else {
-       Blob *b = new Blob();
+       Blob *b = new Blob(cct);
         uint64_t sbid = 0;
        b->decode(p, struct_v, &sbid, false);
        blobs[n] = b;
@@ -2036,7 +2044,7 @@ void BlueStore::ExtentMap::decode_spanning_blobs(
   unsigned n;
   denc_varint(n, p);
   while (n--) {
-    BlobRef b(new Blob());
+    BlobRef b(new Blob(c->store->cct));
     denc_varint(b->id, p);
     spanning_blob_map[b->id] = b;
     uint64_t sbid = 0;
@@ -2125,7 +2133,7 @@ void BlueStore::ExtentMap::dirty_range(
     auto p = &shards[start];
     if (!p->loaded) {
       dout(20) << __func__ << " shard 0x" << std::hex << p->offset << std::dec
-               << " is not loaded, can't mark dirty" << dendl;
+              << " is not loaded, can't mark dirty" << dendl;
       assert(0 == "can't mark unloaded shard dirty");
     }
     if (!p->dirty) {
@@ -2310,8 +2318,8 @@ BlueStore::BlobRef BlueStore::ExtentMap::split_blob(
 {
   uint32_t end_pos = pos + lb->get_blob().get_logical_length() - blob_offset;
   dout(20) << __func__ << " 0x" << std::hex << pos << " end 0x" << end_pos
-          << " blob_offset 0x" << blob_offset << std::dec
-          << " " << *lb << dendl;
+          << " blob_offset 0x" << blob_offset << std::dec << " " << *lb
+          << dendl;
   BlobRef rb = onode->c->new_blob();
   lb->split(blob_offset, rb.get());
 
@@ -2350,10 +2358,10 @@ BlueStore::BlobRef BlueStore::ExtentMap::split_blob(
 void BlueStore::Onode::flush()
 {
   std::unique_lock<std::mutex> l(flush_lock);
-  dout(20) << __func__ << " " << flush_txns << dendl;
+  ldout(c->store->cct, 20) << __func__ << " " << flush_txns << dendl;
   while (!flush_txns.empty())
     flush_cond.wait(l);
-  dout(20) << __func__ << " done" << dendl;
+  ldout(c->store->cct, 20) << __func__ << " done" << dendl;
 }
 
 // =======================================================
@@ -2384,13 +2392,14 @@ void BlueStore::Collection::open_shared_blob(uint64_t sbid, BlobRef b)
 
   b->shared_blob = shared_blob_set.lookup(sbid);
   if (b->shared_blob) {
-    dout(10) << __func__ << " sbid 0x" << std::hex << sbid << std::dec
-            << " had " << *b->shared_blob << dendl;
+    ldout(store->cct, 10) << __func__ << " sbid 0x" << std::hex << sbid
+                         << std::dec << " had " << *b->shared_blob << dendl;
   } else {
     b->shared_blob = new SharedBlob(sbid, cache);
     shared_blob_set.add(b->shared_blob.get());
-    dout(10) << __func__ << " sbid 0x" << std::hex << sbid << std::dec
-            << " opened " << *b->shared_blob << dendl;
+    ldout(store->cct, 10) << __func__ << " sbid 0x" << std::hex << sbid
+                         << std::dec << " opened " << *b->shared_blob
+                         << dendl;
   }
 }
 
@@ -2402,21 +2411,22 @@ void BlueStore::Collection::load_shared_blob(SharedBlobRef sb)
   get_shared_blob_key(sb->sbid, &key);
   int r = store->db->get(PREFIX_SHARED_BLOB, key, &v);
   if (r < 0) {
-    derr << __func__ << " sbid 0x" << std::hex << sb->sbid << std::dec
-        << " not found at key " << pretty_binary_string(key) << dendl;
+      lderr(store->cct) << __func__ << " sbid 0x" << std::hex << sb->sbid
+                       << std::dec << " not found at key "
+                       << pretty_binary_string(key) << dendl;
     assert(0 == "uh oh, missing shared_blob");
   }
 
   bufferlist::iterator p = v.begin();
   ::decode(sb->shared_blob, p);
-  dout(10) << __func__ << " sbid 0x" << std::hex << sb->sbid << std::dec
-          << " loaded shared_blob " << *sb << dendl;
+  ldout(store->cct, 10) << __func__ << " sbid 0x" << std::hex << sb->sbid
+                       << std::dec << " loaded shared_blob " << *sb << dendl;
   sb->loaded = true;
 }
 
 void BlueStore::Collection::make_blob_shared(uint64_t sbid, BlobRef b)
 {
-  dout(10) << __func__ << " " << *b << dendl;
+  ldout(store->cct, 10) << __func__ << " " << *b << dendl;
   bluestore_blob_t& blob = b->dirty_blob();
 
   // update blob
@@ -2432,7 +2442,7 @@ void BlueStore::Collection::make_blob_shared(uint64_t sbid, BlobRef b)
       b->shared_blob->shared_blob.ref_map.get(p.offset, p.length);
     }
   }
-  dout(20) << __func__ << " now " << *b << dendl;
+  ldout(store->cct, 20) << __func__ << " now " << *b << dendl;
 }
 
 BlueStore::OnodeRef BlueStore::Collection::get_onode(
@@ -2444,8 +2454,8 @@ BlueStore::OnodeRef BlueStore::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();
     }
   }
@@ -2455,18 +2465,18 @@ BlueStore::OnodeRef BlueStore::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);
-    if (!g_conf->bluestore_debug_misc &&
+    if (!store->cct->_conf->bluestore_debug_misc &&
        !create)
       return OnodeRef();
 
@@ -2501,7 +2511,8 @@ void BlueStore::Collection::trim_cache()
   size_t seq;
   store->get_mempool_stats(&seq, &total_bytes, &total_onodes);
   if (seq == cache->last_trim_seq) {
-    dout(30) << __func__ << " no new mempool stats; nothing to do" << dendl;
+    ldout(store->cct, 30) << __func__ << " no new mempool stats; nothing to do"
+                         << dendl;
     return;
   }
   cache->last_trim_seq = seq;
@@ -2512,13 +2523,14 @@ void BlueStore::Collection::trim_cache()
   }
   float bytes_per_onode = (float)total_bytes / (float)total_onodes;
   size_t num_shards = store->cache_shards.size();
-  uint64_t shard_target = g_conf->bluestore_cache_size / num_shards;
-  dout(30) << __func__
-          << " total meta bytes " << total_bytes
-          << ", total onodes " << total_onodes
-          << ", bytes_per_onode " << bytes_per_onode
+  uint64_t shard_target = store->cct->_conf->bluestore_cache_size / num_shards;
+  ldout(store->cct, 30) << __func__
+                       << " total meta bytes " << total_bytes
+                       << ", total onodes " << total_onodes
+                       << ", bytes_per_onode " << bytes_per_onode
           << dendl;
-  cache->trim(shard_target, g_conf->bluestore_cache_meta_ratio, bytes_per_onode);
+  cache->trim(shard_target, store->cct->_conf->bluestore_cache_meta_ratio,
+             bytes_per_onode);
 
   store->_update_cache_logger();
 }
@@ -2534,7 +2546,7 @@ void *BlueStore::MempoolThread::entry()
     store->mempool_onodes = mempool::bluestore_meta_onode::allocated_items();
     ++store->mempool_seq;
     utime_t wait;
-    wait += g_conf->bluestore_cache_trim_interval;
+    wait += store->cct->_conf->bluestore_cache_trim_interval;
     cond.WaitInterval(lock, wait);
   }
   stop = false;
@@ -2592,7 +2604,7 @@ BlueStore::BlueStore(CephContext *cct, const string& path)
     mempool_thread(this)
 {
   _init_logger();
-  g_ceph_context->_conf->add_observer(this);
+  cct->_conf->add_observer(this);
   set_cache_shards(1);
 
   if (cct->_conf->bluestore_shard_finishers) {
@@ -2614,7 +2626,7 @@ BlueStore::~BlueStore()
   }
   finishers.clear();
 
-  g_ceph_context->_conf->remove_observer(this);
+  cct->_conf->remove_observer(this);
   _shutdown_logger();
   assert(!mounted);
   assert(db == NULL);
@@ -2656,15 +2668,15 @@ void BlueStore::handle_conf_change(const struct md_config_t *conf,
 
 void BlueStore::_set_compression()
 {
-  comp_min_blob_size = g_conf->bluestore_compression_min_blob_size;
-  comp_max_blob_size = g_conf->bluestore_compression_max_blob_size;
+  comp_min_blob_size = cct->_conf->bluestore_compression_min_blob_size;
+  comp_max_blob_size = cct->_conf->bluestore_compression_max_blob_size;
 
-  auto m = Compressor::get_comp_mode_type(g_conf->bluestore_compression_mode);
+  auto m = Compressor::get_comp_mode_type(cct->_conf->bluestore_compression_mode);
   if (m) {
     comp_mode = *m;
   } else {
     derr << __func__ << " unrecognized value '"
-         << g_conf->bluestore_compression_mode
+         << cct->_conf->bluestore_compression_mode
          << "' for bluestore_compression_mode, reverting to 'none'"
          << dendl;
     comp_mode = Compressor::COMP_NONE;
@@ -2672,7 +2684,7 @@ void BlueStore::_set_compression()
 
   compressor = nullptr;
 
-  auto& alg_name = g_conf->bluestore_compression_algorithm;
+  auto& alg_name = cct->_conf->bluestore_compression_algorithm;
   if (!alg_name.empty()) {
     compressor = Compressor::create(cct, alg_name);
     if (!compressor) {
@@ -2689,7 +2701,7 @@ void BlueStore::_set_compression()
 void BlueStore::_set_csum()
 {
   csum_type = Checksummer::CSUM_NONE;
-  int t = Checksummer::get_csum_string_type(g_conf->bluestore_csum_type);
+  int t = Checksummer::get_csum_string_type(cct->_conf->bluestore_csum_type);
   if (t > Checksummer::CSUM_NONE)
     csum_type = t;
 
@@ -2700,7 +2712,7 @@ void BlueStore::_set_csum()
 
 void BlueStore::_init_logger()
 {
-  PerfCountersBuilder b(g_ceph_context, "BlueStore",
+  PerfCountersBuilder b(cct, "BlueStore",
                         l_bluestore_first, l_bluestore_last);
   b.add_time_avg(l_bluestore_state_prepare_lat, "state_prepare_lat",
     "Average prepare state latency");
@@ -2813,7 +2825,7 @@ void BlueStore::_init_logger()
   b.add_u64(l_bluestore_extent_compress, "bluestore_extent_compress",
             "Sum for extents that have been removed due to compression");
   logger = b.create_perf_counters();
-  g_ceph_context->get_perfcounters_collection()->add(logger);
+  cct->get_perfcounters_collection()->add(logger);
 }
 
 int BlueStore::_reload_logger()
@@ -2833,14 +2845,15 @@ int BlueStore::_reload_logger()
 
 void BlueStore::_shutdown_logger()
 {
-  g_ceph_context->get_perfcounters_collection()->remove(logger);
+  cct->get_perfcounters_collection()->remove(logger);
   delete logger;
 }
 
-int BlueStore::get_block_device_fsid(const string& path, uuid_d *fsid)
+int BlueStore::get_block_device_fsid(CephContext* cct, const string& path,
+                                    uuid_d *fsid)
 {
   bluestore_bdev_label_t label;
-  int r = _read_bdev_label(path, &label);
+  int r = _read_bdev_label(cct, path, &label);
   if (r < 0)
     return r;
   *fsid = label.osd_uuid;
@@ -2894,7 +2907,8 @@ int BlueStore::_write_bdev_label(string path, bluestore_bdev_label_t label)
   return r;
 }
 
-int BlueStore::_read_bdev_label(string path, bluestore_bdev_label_t *label)
+int BlueStore::_read_bdev_label(CephContext* cct, string path,
+                               bluestore_bdev_label_t *label)
 {
   dout(10) << __func__ << dendl;
   int fd = ::open(path.c_str(), O_RDONLY);
@@ -2950,7 +2964,7 @@ int BlueStore::_check_or_set_bdev_label(
     if (r < 0)
       return r;
   } else {
-    int r = _read_bdev_label(path, &label);
+    int r = _read_bdev_label(cct, path, &label);
     if (r < 0)
       return r;
     if (label.osd_uuid != fsid) {
@@ -2967,20 +2981,20 @@ void BlueStore::_set_alloc_sizes(void)
   /*
    * Set device block size according to its media
    */
-  if (g_conf->bluestore_min_alloc_size) {
-    min_alloc_size = g_conf->bluestore_min_alloc_size;
+  if (cct->_conf->bluestore_min_alloc_size) {
+    min_alloc_size = cct->_conf->bluestore_min_alloc_size;
   } else {
     assert(bdev);
     if (bdev->is_rotational()) {
-      min_alloc_size = g_conf->bluestore_min_alloc_size_hdd;
+      min_alloc_size = cct->_conf->bluestore_min_alloc_size_hdd;
     } else {
-      min_alloc_size = g_conf->bluestore_min_alloc_size_ssd;
+      min_alloc_size = cct->_conf->bluestore_min_alloc_size_ssd;
     }
   }
   min_alloc_size_order = ctz(min_alloc_size);
   assert(min_alloc_size == 1u << min_alloc_size_order);
 
-  max_alloc_size = g_conf->bluestore_max_alloc_size;
+  max_alloc_size = cct->_conf->bluestore_max_alloc_size;
 
   dout(10) << __func__ << " min_alloc_size 0x" << std::hex << min_alloc_size
           << std::dec << " order " << min_alloc_size_order
@@ -2993,7 +3007,7 @@ int BlueStore::_open_bdev(bool create)
   bluestore_bdev_label_t label;
   assert(bdev == NULL);
   string p = path + "/block";
-  bdev = BlockDevice::create(p, aio_cb, static_cast<void*>(this));
+  bdev = BlockDevice::create(cct, p, aio_cb, static_cast<void*>(this));
   int r = bdev->open(p);
   if (r < 0)
     goto fail;
@@ -3032,7 +3046,7 @@ void BlueStore::_close_bdev()
 int BlueStore::_open_fm(bool create)
 {
   assert(fm == NULL);
-  fm = FreelistManager::create(freelist_type, db, PREFIX_ALLOC);
+  fm = FreelistManager::create(cct, freelist_type, db, PREFIX_ALLOC);
 
   if (create) {
     // initialize freespace
@@ -3046,7 +3060,7 @@ int BlueStore::_open_fm(bool create)
     fm->create(bdev->get_size(), t);
 
     uint64_t reserved = 0;
-    if (g_conf->bluestore_bluefs) {
+    if (cct->_conf->bluestore_bluefs) {
       assert(bluefs_extents.num_intervals() == 1);
       interval_set<uint64_t>::iterator p = bluefs_extents.begin();
       reserved = p.get_start() + p.get_len();
@@ -3065,14 +3079,14 @@ int BlueStore::_open_fm(bool create)
     // instead rely on bluefs_extents.
     fm->allocate(0, BLUEFS_START, t);
 
-    if (g_conf->bluestore_debug_prefill > 0) {
+    if (cct->_conf->bluestore_debug_prefill > 0) {
       uint64_t end = bdev->get_size() - reserved;
       dout(1) << __func__ << " pre-fragmenting freespace, using "
-             << g_conf->bluestore_debug_prefill << " with max free extent "
-             << g_conf->bluestore_debug_prefragment_max << dendl;
+             << cct->_conf->bluestore_debug_prefill << " with max free extent "
+             << cct->_conf->bluestore_debug_prefragment_max << dendl;
       uint64_t start = P2ROUNDUP(reserved, min_alloc_size);
-      uint64_t max_b = g_conf->bluestore_debug_prefragment_max / min_alloc_size;
-      float r = g_conf->bluestore_debug_prefill;
+      uint64_t max_b = cct->_conf->bluestore_debug_prefragment_max / min_alloc_size;
+      float r = cct->_conf->bluestore_debug_prefill;
       r /= 1.0 - r;
       bool stop = false;
 
@@ -3132,7 +3146,7 @@ int BlueStore::_open_alloc()
 {
   assert(alloc == NULL);
   assert(bdev->get_size());
-  alloc = Allocator::create(g_conf->bluestore_allocator,
+  alloc = Allocator::create(cct, cct->_conf->bluestore_allocator,
                             bdev->get_size(),
                             min_min_alloc_size);
   uint64_t num = 0, bytes = 0;
@@ -3280,7 +3294,7 @@ int BlueStore::_open_db(bool create)
 
   string kv_backend;
   if (create) {
-    kv_backend = g_conf->bluestore_kvbackend;
+    kv_backend = cct->_conf->bluestore_kvbackend;
   } else {
     r = read_meta("kv_backend", &kv_backend);
     if (r < 0) {
@@ -3292,7 +3306,7 @@ int BlueStore::_open_db(bool create)
 
   bool do_bluefs;
   if (create) {
-    do_bluefs = g_conf->bluestore_bluefs;
+    do_bluefs = cct->_conf->bluestore_bluefs;
   } else {
     string s;
     r = read_meta("bluefs", &s);
@@ -3319,7 +3333,7 @@ int BlueStore::_open_db(bool create)
       derr << " backend must be rocksdb to use bluefs" << dendl;
       return -EINVAL;
     }
-    bluefs = new BlueFS;
+    bluefs = new BlueFS(cct);
 
     string bfn;
     struct stat st;
@@ -3368,12 +3382,12 @@ int BlueStore::_open_db(bool create)
       // note: we might waste a 4k block here if block.db is used, but it's
       // simpler.
       uint64_t initial =
-       bdev->get_size() * (g_conf->bluestore_bluefs_min_ratio +
-                           g_conf->bluestore_bluefs_gift_ratio);
-      initial = MAX(initial, g_conf->bluestore_bluefs_min);
+       bdev->get_size() * (cct->_conf->bluestore_bluefs_min_ratio +
+                           cct->_conf->bluestore_bluefs_gift_ratio);
+      initial = MAX(initial, cct->_conf->bluestore_bluefs_min);
       // align to bluefs's alloc_size
-      initial = P2ROUNDUP(initial, g_conf->bluefs_alloc_size);
-      initial += g_conf->bluefs_alloc_size - BLUEFS_START;
+      initial = P2ROUNDUP(initial, cct->_conf->bluefs_alloc_size);
+      initial += cct->_conf->bluefs_alloc_size - BLUEFS_START;
       bluefs->add_block_extent(bluefs_shared_bdev, BLUEFS_START, initial);
       bluefs_extents.insert(BLUEFS_START, initial);
     }
@@ -3405,9 +3419,9 @@ int BlueStore::_open_db(bool create)
          bluefs->get_block_device_size(BlueFS::BDEV_WAL) -
           BDEV_LABEL_BLOCK_SIZE);
       }
-      g_conf->set_val("rocksdb_separate_wal_dir", "true");
+      cct->_conf->set_val("rocksdb_separate_wal_dir", "true");
     } else {
-      g_conf->set_val("rocksdb_separate_wal_dir", "false");
+      cct->_conf->set_val("rocksdb_separate_wal_dir", "false");
     }
 
     if (create) {
@@ -3418,7 +3432,7 @@ int BlueStore::_open_db(bool create)
       derr << __func__ << " failed bluefs mount: " << cpp_strerror(r) << dendl;
       goto free_bluefs;
     }
-    if (g_conf->bluestore_bluefs_env_mirror) {
+    if (cct->_conf->bluestore_bluefs_env_mirror) {
       rocksdb::Env *a = new BlueRocksEnv(bluefs);
       unique_ptr<rocksdb::Directory> dir;
       rocksdb::Env *b = rocksdb::Env::Default();
@@ -3447,16 +3461,16 @@ int BlueStore::_open_db(bool create)
                << (uint64_t)(db_size * 95 / 100) << " "
                << fn + ".slow" << ","
                << (uint64_t)(slow_size * 95 / 100);
-      g_conf->set_val("rocksdb_db_paths", db_paths.str(), false, false);
+      cct->_conf->set_val("rocksdb_db_paths", db_paths.str(), false, false);
       dout(10) << __func__ << " set rocksdb_db_paths to "
-              << g_conf->rocksdb_db_paths << dendl;
+              << cct->_conf->rocksdb_db_paths << dendl;
     }
 
     if (create) {
       env->CreateDir(fn);
-      if (g_conf->rocksdb_separate_wal_dir)
+      if (cct->_conf->rocksdb_separate_wal_dir)
        env->CreateDir(fn + ".wal");
-      if (g_conf->rocksdb_db_paths.length())
+      if (cct->_conf->rocksdb_db_paths.length())
        env->CreateDir(fn + ".slow");
     }
   } else if (create) {
@@ -3470,7 +3484,7 @@ int BlueStore::_open_db(bool create)
     }
 
     // wal_dir, too!
-    if (g_conf->rocksdb_separate_wal_dir) {
+    if (cct->_conf->rocksdb_separate_wal_dir) {
       string walfn = path + "/db.wal";
       r = ::mkdir(walfn.c_str(), 0755);
       if (r < 0)
@@ -3484,7 +3498,7 @@ int BlueStore::_open_db(bool create)
     }
   }
 
-  db = KeyValueDB::create(g_ceph_context,
+  db = KeyValueDB::create(cct,
                          kv_backend,
                          fn,
                          static_cast<void*>(env));
@@ -3506,7 +3520,7 @@ int BlueStore::_open_db(bool create)
   db->set_merge_operator(PREFIX_STAT, merge_op);
 
   if (kv_backend == "rocksdb")
-    options = g_conf->bluestore_rocksdb_options;
+    options = cct->_conf->bluestore_rocksdb_options;
   db->init(options);
   if (create)
     r = db->create_and_open(err);
@@ -3621,25 +3635,25 @@ int BlueStore::_balance_bluefs_freespace(vector<bluestore_pextent_t> *extents)
 
   uint64_t gift = 0;
   uint64_t reclaim = 0;
-  if (bluefs_ratio < g_conf->bluestore_bluefs_min_ratio) {
-    gift = g_conf->bluestore_bluefs_gift_ratio * total_free;
+  if (bluefs_ratio < cct->_conf->bluestore_bluefs_min_ratio) {
+    gift = cct->_conf->bluestore_bluefs_gift_ratio * total_free;
     dout(10) << __func__ << " bluefs_ratio " << bluefs_ratio
-            << " < min_ratio " << g_conf->bluestore_bluefs_min_ratio
+            << " < min_ratio " << cct->_conf->bluestore_bluefs_min_ratio
             << ", should gift " << pretty_si_t(gift) << dendl;
-  } else if (bluefs_ratio > g_conf->bluestore_bluefs_max_ratio) {
-    reclaim = g_conf->bluestore_bluefs_reclaim_ratio * total_free;
-    if (bluefs_total - reclaim < g_conf->bluestore_bluefs_min)
-      reclaim = bluefs_total - g_conf->bluestore_bluefs_min;
+  } else if (bluefs_ratio > cct->_conf->bluestore_bluefs_max_ratio) {
+    reclaim = cct->_conf->bluestore_bluefs_reclaim_ratio * total_free;
+    if (bluefs_total - reclaim < cct->_conf->bluestore_bluefs_min)
+      reclaim = bluefs_total - cct->_conf->bluestore_bluefs_min;
     dout(10) << __func__ << " bluefs_ratio " << bluefs_ratio
-            << " > max_ratio " << g_conf->bluestore_bluefs_max_ratio
+            << " > max_ratio " << cct->_conf->bluestore_bluefs_max_ratio
             << ", should reclaim " << pretty_si_t(reclaim) << dendl;
   }
-  if (bluefs_total < g_conf->bluestore_bluefs_min &&
-    g_conf->bluestore_bluefs_min <
-      (uint64_t)(g_conf->bluestore_bluefs_max_ratio * total_free)) {
-    uint64_t g = g_conf->bluestore_bluefs_min - bluefs_total;
+  if (bluefs_total < cct->_conf->bluestore_bluefs_min &&
+    cct->_conf->bluestore_bluefs_min <
+      (uint64_t)(cct->_conf->bluestore_bluefs_max_ratio * total_free)) {
+    uint64_t g = cct->_conf->bluestore_bluefs_min - bluefs_total;
     dout(10) << __func__ << " bluefs_total " << bluefs_total
-            << " < min " << g_conf->bluestore_bluefs_min
+            << " < min " << cct->_conf->bluestore_bluefs_min
             << ", should gift " << pretty_si_t(g) << dendl;
     if (g > gift)
       gift = g;
@@ -3662,7 +3676,7 @@ int BlueStore::_balance_bluefs_freespace(vector<bluestore_pextent_t> *extents)
     int count = 0;
     uint64_t alloc_len = 0;
     AllocExtentVector exts = AllocExtentVector(gift / min_alloc_size);
-    r = alloc->allocate(gift, g_conf->bluefs_alloc_size, 0, 0, &exts, &count, &alloc_len);
+    r = alloc->allocate(gift, cct->_conf->bluefs_alloc_size, 0, 0, &exts, &count, &alloc_len);
 
     if (r < 0 || alloc_len < gift) {
       derr << __func__ << " allocate failed on 0x" << std::hex << gift
@@ -3812,7 +3826,7 @@ int BlueStore::_setup_block_symlink_or_file(
          return r;
        }
 
-       if (g_conf->bluestore_block_preallocate_file) {
+       if (cct->_conf->bluestore_block_preallocate_file) {
 #ifdef HAVE_POSIX_FALLOCATE
          r = ::posix_fallocate(fd, 0, size);
          if (r) {
@@ -3865,8 +3879,8 @@ int BlueStore::mkfs()
     r = read_meta("mkfs_done", &done);
     if (r == 0) {
       dout(1) << __func__ << " already created" << dendl;
-      if (g_conf->bluestore_fsck_on_mkfs) {
-        r = fsck(g_conf->bluestore_fsck_on_mkfs_deep);
+      if (cct->_conf->bluestore_fsck_on_mkfs) {
+        r = fsck(cct->_conf->bluestore_fsck_on_mkfs_deep);
         if (r < 0) {
           derr << __func__ << " fsck found fatal error: " << cpp_strerror(r)
                << dendl;
@@ -3896,7 +3910,7 @@ int BlueStore::mkfs()
     }
   }
 
-  freelist_type = g_conf->bluestore_freelist_type;
+  freelist_type = cct->_conf->bluestore_freelist_type;
 
   r = _open_path();
   if (r < 0)
@@ -3929,20 +3943,20 @@ int BlueStore::mkfs()
     fsid = old_fsid;
   }
 
-  r = _setup_block_symlink_or_file("block", g_conf->bluestore_block_path,
-                                  g_conf->bluestore_block_size,
-                                  g_conf->bluestore_block_create);
+  r = _setup_block_symlink_or_file("block", cct->_conf->bluestore_block_path,
+                                  cct->_conf->bluestore_block_size,
+                                  cct->_conf->bluestore_block_create);
   if (r < 0)
     goto out_close_fsid;
-  if (g_conf->bluestore_bluefs) {
-    r = _setup_block_symlink_or_file("block.wal", g_conf->bluestore_block_wal_path,
-       g_conf->bluestore_block_wal_size,
-       g_conf->bluestore_block_wal_create);
+  if (cct->_conf->bluestore_bluefs) {
+    r = _setup_block_symlink_or_file("block.wal", cct->_conf->bluestore_block_wal_path,
+       cct->_conf->bluestore_block_wal_size,
+       cct->_conf->bluestore_block_wal_create);
     if (r < 0)
       goto out_close_fsid;
-    r = _setup_block_symlink_or_file("block.db", g_conf->bluestore_block_db_path,
-       g_conf->bluestore_block_db_size,
-       g_conf->bluestore_block_db_create);
+    r = _setup_block_symlink_or_file("block.db", cct->_conf->bluestore_block_db_path,
+       cct->_conf->bluestore_block_db_size,
+       cct->_conf->bluestore_block_db_create);
     if (r < 0)
       goto out_close_fsid;
   }
@@ -3965,10 +3979,10 @@ int BlueStore::mkfs()
   if (r < 0)
     goto out_close_fm;
 
-  r = write_meta("kv_backend", g_conf->bluestore_kvbackend);
+  r = write_meta("kv_backend", cct->_conf->bluestore_kvbackend);
   if (r < 0)
     goto out_close_alloc;
-  r = write_meta("bluefs", stringify((int)g_conf->bluestore_bluefs));
+  r = write_meta("bluefs", stringify((int)cct->_conf->bluestore_bluefs));
   if (r < 0)
     goto out_close_alloc;
 
@@ -4000,8 +4014,8 @@ int BlueStore::mkfs()
   _close_path();
 
   if (r == 0 &&
-      g_conf->bluestore_fsck_on_mkfs) {
-    int rc = fsck(g_conf->bluestore_fsck_on_mkfs_deep);
+      cct->_conf->bluestore_fsck_on_mkfs) {
+    int rc = fsck(cct->_conf->bluestore_fsck_on_mkfs_deep);
     if (rc < 0)
       return rc;
     if (rc > 0) {
@@ -4019,7 +4033,8 @@ void BlueStore::set_cache_shards(unsigned num)
   assert(num >= old);
   cache_shards.resize(num);
   for (unsigned i = old; i < num; ++i) {
-    cache_shards[i] = Cache::create(g_conf->bluestore_cache_type, logger);
+    cache_shards[i] = Cache::create(cct, cct->_conf->bluestore_cache_type,
+                                   logger);
   }
 }
 
@@ -4042,8 +4057,8 @@ int BlueStore::mount()
     }
   }
 
-  if (g_conf->bluestore_fsck_on_mount) {
-    int rc = fsck(g_conf->bluestore_fsck_on_mount_deep);
+  if (cct->_conf->bluestore_fsck_on_mount) {
+    int rc = fsck(cct->_conf->bluestore_fsck_on_mount_deep);
     if (rc < 0)
       return rc;
     if (rc > 0) {
@@ -4177,8 +4192,8 @@ int BlueStore::umount()
   _close_fsid();
   _close_path();
 
-  if (g_conf->bluestore_fsck_on_umount) {
-    int rc = fsck(g_conf->bluestore_fsck_on_umount_deep);
+  if (cct->_conf->bluestore_fsck_on_umount) {
+    int rc = fsck(cct->_conf->bluestore_fsck_on_umount_deep);
     if (rc < 0)
       return rc;
     if (rc > 0) {
@@ -5066,7 +5081,7 @@ int BlueStore::_do_read(
   if (op_flags & CEPH_OSD_OP_FLAG_FADVISE_WILLNEED) {
     dout(20) << __func__ << " will do buffered read" << dendl;
     buffered = true;
-  } else if (g_conf->bluestore_default_buffered_read &&
+  } else if (cct->_conf->bluestore_default_buffered_read &&
             (op_flags & (CEPH_OSD_OP_FLAG_FADVISE_DONTNEED |
                          CEPH_OSD_OP_FLAG_FADVISE_NOCACHE)) == 0) {
     dout(20) << __func__ << " defaulting to buffered read" << dendl;
@@ -5149,7 +5164,7 @@ int BlueStore::_do_read(
             << " need 0x" << b2r_it->second << std::dec << dendl;
     if (bptr->get_blob().has_flag(bluestore_blob_t::FLAG_COMPRESSED)) {
       bufferlist compressed_bl, raw_bl;
-      IOContext ioc(NULL);   // FIXME?
+      IOContext ioc(cct, NULL);   // FIXME?
       r = bptr->get_blob().map(
        0, bptr->get_blob().get_ondisk_length(),
        [&](uint64_t offset, uint64_t length) {
@@ -5198,7 +5213,7 @@ int BlueStore::_do_read(
                 << dendl;
 
        // read it
-       IOContext ioc(NULL);  // FIXME?
+       IOContext ioc(cct, NULL);  // FIXME?
        bufferlist bl;
        r = bptr->get_blob().map(r_off, r_len,
                             [&](uint64_t offset, uint64_t length) {
@@ -5625,7 +5640,7 @@ int BlueStore::_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);
@@ -5640,7 +5655,7 @@ int BlueStore::_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;
@@ -6233,7 +6248,7 @@ void BlueStore::get_db_statistics(Formatter *f)
 
 BlueStore::TransContext *BlueStore::_txc_create(OpSequencer *osr)
 {
-  TransContext *txc = new TransContext(osr);
+  TransContext *txc = new TransContext(cct, osr);
   txc->t = db->get_transaction();
   osr->queue_new(txc);
   dout(20) << __func__ << " osr " << osr << " = " << txc
@@ -6291,7 +6306,7 @@ void BlueStore::_txc_state_proc(TransContext *txc)
         sb->bc.finish_write(txc->seq);
       }
       txc->shared_blobs_written.clear();
-      if (g_conf->bluestore_sync_submit_transaction &&
+      if (cct->_conf->bluestore_sync_submit_transaction &&
          fm->supports_parallel_transactions()) {
        if (txc->last_nid >= nid_max ||
            txc->last_blobid >= blobid_max) {
@@ -6308,8 +6323,8 @@ void BlueStore::_txc_state_proc(TransContext *txc)
        } else if (txc->osr->txc_with_unstable_io) {
          dout(20) << __func__ << " prior txc(s) with unstable ios "
                   << txc->osr->txc_with_unstable_io.load() << dendl;
-       } else if (g_conf->bluestore_debug_randomize_serial_transaction &&
-                  rand() % g_conf->bluestore_debug_randomize_serial_transaction
+       } else if (cct->_conf->bluestore_debug_randomize_serial_transaction &&
+                  rand() % cct->_conf->bluestore_debug_randomize_serial_transaction
                   == 0) {
          dout(20) << __func__ << " DEBUG randomly forcing submit via kv thread"
                   << dendl;
@@ -6667,7 +6682,7 @@ void BlueStore::_txc_finalize_kv(TransContext *txc, KeyValueDB::Transaction t)
 void BlueStore::_txc_release_alloc(TransContext *txc)
 {
   // update allocator with full released set
-  if (!g_conf->bluestore_debug_no_reuse_blocks) {
+  if (!cct->_conf->bluestore_debug_no_reuse_blocks) {
     for (interval_set<uint64_t>::iterator p = txc->released.begin();
         p != txc->released.end();
         ++p) {
@@ -6719,19 +6734,19 @@ void BlueStore::_kv_sync_thread()
       // it.  in either case, we increase the max in the earlier txn
       // we submit.
       uint64_t new_nid_max = 0, new_blobid_max = 0;
-      if (nid_last + g_conf->bluestore_nid_prealloc/2 > nid_max) {
+      if (nid_last + cct->_conf->bluestore_nid_prealloc/2 > nid_max) {
        KeyValueDB::Transaction t =
          kv_submitting.empty() ? synct : kv_submitting.front()->t;
-       new_nid_max = nid_last + g_conf->bluestore_nid_prealloc;
+       new_nid_max = nid_last + cct->_conf->bluestore_nid_prealloc;
        bufferlist bl;
        ::encode(new_nid_max, bl);
        t->set(PREFIX_SUPER, "nid_max", bl);
        dout(10) << __func__ << " new_nid_max " << new_nid_max << dendl;
       }
-      if (blobid_last + g_conf->bluestore_blobid_prealloc/2 > blobid_max) {
+      if (blobid_last + cct->_conf->bluestore_blobid_prealloc/2 > blobid_max) {
        KeyValueDB::Transaction t =
          kv_submitting.empty() ? synct : kv_submitting.front()->t;
-       new_blobid_max = blobid_last + g_conf->bluestore_blobid_prealloc;
+       new_blobid_max = blobid_last + cct->_conf->bluestore_blobid_prealloc;
        bufferlist bl;
        ::encode(new_blobid_max, bl);
        t->set(PREFIX_SUPER, "blobid_max", bl);
@@ -6852,12 +6867,12 @@ int BlueStore::_wal_apply(TransContext *txc)
   txc->log_state_latency(logger, l_bluestore_state_wal_queued_lat);
   txc->state = TransContext::STATE_WAL_APPLYING;
 
-  if (g_conf->bluestore_inject_wal_apply_delay) {
+  if (cct->_conf->bluestore_inject_wal_apply_delay) {
     dout(20) << __func__ << " bluestore_inject_wal_apply_delay "
-            << g_conf->bluestore_inject_wal_apply_delay
+            << cct->_conf->bluestore_inject_wal_apply_delay
             << dendl;
     utime_t t;
-    t.set_from_double(g_conf->bluestore_inject_wal_apply_delay);
+    t.set_from_double(cct->_conf->bluestore_inject_wal_apply_delay);
     t.sleep();
     dout(20) << __func__ << " finished sleep" << dendl;
   }
@@ -6965,7 +6980,7 @@ int BlueStore::queue_transactions(
   ObjectStore::Transaction::collect_contexts(
     tls, &onreadable, &ondisk, &onreadable_sync);
 
-  if (g_conf->objectstore_blackhole) {
+  if (cct->_conf->objectstore_blackhole) {
     dout(0) << __func__ << " objectstore_blackhole = TRUE, dropping transaction"
            << dendl;
     delete ondisk;
@@ -7445,7 +7460,7 @@ int BlueStore::_touch(TransContext *txc,
 
 void BlueStore::_dump_onode(OnodeRef o, int log_level)
 {
-  if (!g_conf->subsys.should_gather(ceph_subsys_bluestore, log_level))
+  if (!cct->_conf->subsys.should_gather(ceph_subsys_bluestore, log_level))
     return;
   dout(log_level) << __func__ << " " << o << " " << o->oid
                  << " nid " << o->onode.nid
@@ -7848,7 +7863,7 @@ int BlueStore::_do_alloc_write(
 
   auto crr = select_option(
     "compression_required_ratio",
-    g_conf->bluestore_compression_required_ratio,
+    cct->_conf->bluestore_compression_required_ratio,
     [&]() {
       double val;
       if(coll->pool_opts.get(pool_opts_t::COMPRESSION_REQUIRED_RATIO, &val)) {
@@ -8144,7 +8159,7 @@ int BlueStore::_do_write(
   if (fadvise_flags & CEPH_OSD_OP_FLAG_FADVISE_WILLNEED) {
     dout(20) << __func__ << " will do buffered write" << dendl;
     wctx.buffered = true;
-  } else if (g_conf->bluestore_default_buffered_write &&
+  } else if (cct->_conf->bluestore_default_buffered_write &&
             (fadvise_flags & (CEPH_OSD_OP_FLAG_FADVISE_DONTNEED |
                               CEPH_OSD_OP_FLAG_FADVISE_NOCACHE)) == 0) {
     dout(20) << __func__ << " defaulting to buffered write" << dendl;
@@ -8218,8 +8233,8 @@ int BlueStore::_do_write(
     }
   }
   if (wctx.target_blob_size == 0 ||
-      wctx.target_blob_size > g_conf->bluestore_max_blob_size) {
-    wctx.target_blob_size = g_conf->bluestore_max_blob_size;
+      wctx.target_blob_size > cct->_conf->bluestore_max_blob_size) {
+    wctx.target_blob_size = cct->_conf->bluestore_max_blob_size;
   }
   // set the min blob size floor at 2x the min_alloc_size, or else we
   // won't be able to allocate a smaller extent for the compressed
@@ -8701,7 +8716,7 @@ int BlueStore::_clone(TransContext *txc,
   r = _do_truncate(txc, c, newo, 0);
   if (r < 0)
     goto out;
-  if (g_conf->bluestore_clone_cow) {
+  if (cct->_conf->bluestore_clone_cow) {
     _do_clone_range(txc, c, oldo, newo, 0, oldo->onode.size, 0);
   } else {
     bufferlist bl;
@@ -8806,7 +8821,7 @@ int BlueStore::_do_clone_range(
       } else if (!e.blob->shared_blob->loaded) {
        c->load_shared_blob(e.blob->shared_blob);
       }
-      cb = new Blob;
+      cb = new Blob(cct);
       e.blob->last_encoded_id = n;
       id_to_blob[n] = cb;
       e.blob->dup(*cb);
@@ -8884,7 +8899,7 @@ int BlueStore::_clone_range(TransContext *txc,
   _assign_nid(txc, newo);
 
   if (length > 0) {
-    if (g_conf->bluestore_clone_cow) {
+    if (cct->_conf->bluestore_clone_cow) {
       _do_zero(txc, c, newo, dstoff, length);
       _do_clone_range(txc, c, oldo, newo, srcoff, length, dstoff);
     } else {
@@ -8933,7 +8948,7 @@ int BlueStore::_rename(TransContext *txc,
 
   // rewrite shards
   oldo->extent_map.fault_range(db, 0, oldo->onode.size);
-  get_object_key(new_oid, &new_okey);
+  get_object_key(cct, new_oid, &new_okey);
   for (auto &s : oldo->extent_map.shards) {
     txc->t->rmkey(PREFIX_OBJ, s.key);
     get_extent_shard_key(new_okey, s.offset, &s.key);
index 4cc50aecfd31a2764590e61f136bf6777355188c..b57034b35e61600c79c0f1f81355d3b7ebbfc2ba 100644 (file)
@@ -110,7 +110,6 @@ class BlueStore : public ObjectStore,
   // -----------------------------------------------------
   // types
 public:
-
   // config observer
   virtual const char** get_tracked_conf_keys() const override;
   virtual void handle_conf_change(const struct md_config_t *conf,
@@ -420,6 +419,7 @@ public:
   /// in-memory blob metadata and associated cached buffers (if any)
   struct Blob {
     MEMPOOL_CLASS_HELPERS();
+    CephContext* cct;
 
     std::atomic_int nref = {0};     ///< reference count
     int16_t id = -1;                ///< id, for spanning blobs only, >= 0
@@ -435,7 +435,7 @@ public:
     bluestore_extent_ref_map_t ref_map;
 
   public:
-    Blob() {}
+    Blob(CephContext* cct) : cct(cct) {}
     ~Blob() {
     }
 
@@ -639,6 +639,7 @@ public:
 
   /// a sharded extent map, mapping offsets to lextents to blobs
   struct ExtentMap {
+    CephContext* cct;
     Onode *onode;
     extent_map_t extent_map;        ///< map of Extents to Blobs
     blob_map_t spanning_blob_map;   ///< blobs that span shards
@@ -660,7 +661,7 @@ public:
       void operator()(Extent *e) { delete e; }
     };
 
-    ExtentMap(Onode *o);
+    ExtentMap(CephContext* cct, Onode *o);
     ~ExtentMap() {
       extent_map.clear_and_dispose(DeleteDisposer());
     }
@@ -814,7 +815,7 @@ public:
        oid(o),
        key(k),
        exists(false),
-       extent_map(this) {
+       extent_map(c->store->cct, this) {
     }
 
     void flush();
@@ -831,6 +832,7 @@ public:
 
   /// a cache (shard) of onodes and buffers
   struct Cache {
+    CephContext* cct;
     PerfCounters *logger;
     std::recursive_mutex lock;          ///< protect lru and other structures
 
@@ -839,8 +841,9 @@ public:
 
     size_t last_trim_seq = 0;
 
-    static Cache *create(string type, PerfCounters *logger);
+    static Cache *create(CephContext* cct, string type, PerfCounters *logger);
 
+    Cache(CephContext* cct) : cct(cct) {}
     virtual ~Cache() {}
 
     virtual void _add_onode(OnodeRef& o, int level) = 0;
@@ -908,6 +911,7 @@ public:
     uint64_t buffer_size = 0;
 
   public:
+    LRUCache(CephContext* cct) : Cache(cct) {}
     uint64_t _get_num_onodes() override {
       return onode_lru.size();
     }
@@ -1008,6 +1012,7 @@ public:
     uint64_t buffer_list_bytes[BUFFER_TYPE_MAX] = {0}; ///< bytes per type
 
   public:
+    TwoQCache(CephContext* cct) : Cache(cct) {}
     uint64_t _get_num_onodes() override {
       return onode_lru.size();
     }
@@ -1126,7 +1131,7 @@ public:
     void make_blob_shared(uint64_t sbid, BlobRef b);
 
     BlobRef new_blob() {
-      BlobRef b = new Blob;
+      BlobRef b = new Blob(store->cct);
       b->shared_blob = new SharedBlob(cache);
       return b;
     }
@@ -1304,7 +1309,7 @@ public:
     uint64_t last_nid = 0;     ///< if non-zero, highest new nid we allocated
     uint64_t last_blobid = 0;  ///< if non-zero, highest new blobid we allocated
 
-    explicit TransContext(OpSequencer *o)
+    explicit TransContext(CephContext* cct, OpSequencer *o)
       : state(STATE_PREPARE),
        osr(o),
        ops(0),
@@ -1313,7 +1318,7 @@ public:
        onreadable(NULL),
        onreadable_sync(NULL),
        wal_txn(NULL),
-       ioc(this),
+       ioc(cct, this),
        start(ceph_clock_now()) {
         last_stamp = start;
     }
@@ -1647,7 +1652,8 @@ private:
                                   bool create);
 
   int _write_bdev_label(string path, bluestore_bdev_label_t label);
-  static int _read_bdev_label(string path, bluestore_bdev_label_t *label);
+  static int _read_bdev_label(CephContext* cct, string path,
+                             bluestore_bdev_label_t *label);
   int _check_or_set_bdev_label(string path, uint64_t size, string desc,
                               bool create);
 
@@ -1751,7 +1757,8 @@ public:
   bool wants_journal() override { return false; };
   bool allows_journal() override { return false; };
 
-  static int get_block_device_fsid(const string& path, uuid_d *fsid);
+  static int get_block_device_fsid(CephContext* cct, const string& path,
+                                  uuid_d *fsid);
 
   bool test_mount_in_use() override;
 
@@ -1976,21 +1983,21 @@ public:
   }
 private:
   bool _debug_data_eio(const ghobject_t& o) {
-    if (!g_conf->bluestore_debug_inject_read_err) {
+    if (!cct->_conf->bluestore_debug_inject_read_err) {
       return false;
     }
     RWLock::RLocker l(debug_read_error_lock);
     return debug_data_error_objects.count(o);
   }
   bool _debug_mdata_eio(const ghobject_t& o) {
-    if (!g_conf->bluestore_debug_inject_read_err) {
+    if (!cct->_conf->bluestore_debug_inject_read_err) {
       return false;
     }
     RWLock::RLocker l(debug_read_error_lock);
     return debug_mdata_error_objects.count(o);
   }
   void _debug_obj_on_delete(const ghobject_t& o) {
-    if (g_conf->bluestore_debug_inject_read_err) {
+    if (cct->_conf->bluestore_debug_inject_read_err) {
       RWLock::WLocker l(debug_read_error_lock);
       debug_data_error_objects.erase(o);
       debug_mdata_error_objects.erase(o);
index 361a9df6758421df675d7d2bb45dbd26e12e3bae..85174e1834f3e6de13d43ef85ac569ae493a1da9 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "freelist "
@@ -208,7 +208,7 @@ void ExtentFreelistManager::allocate(
       p->second = newlen;
     }
   }
-  if (g_conf->bluestore_debug_freelist)
+  if (cct->_conf->bluestore_debug_freelist)
     _audit();
 }
 
@@ -279,6 +279,6 @@ void ExtentFreelistManager::release(
 
   kv_free[offset] = length;
 
-  if (g_conf->bluestore_debug_freelist)
+  if (cct->_conf->bluestore_debug_freelist)
     _audit();
 }
index 839a251817ece46f671034bf1d71da55b12acc2e..3567a8edd8bb315adf7b89bcd9e78ff5edd465fd 100644 (file)
@@ -29,7 +29,9 @@ class ExtentFreelistManager : public FreelistManager {
   void _dump();
 
 public:
-  ExtentFreelistManager(KeyValueDB *kvdb, std::string prefix) :
+  ExtentFreelistManager(CephContext* cct, KeyValueDB *kvdb,
+                       std::string prefix) :
+    FreelistManager(cct),
     kvdb(kvdb),
     prefix(prefix),
     total_free(0) {
index e51be106978a8d36f2f7bd1365850ca4eb4a1b94..ad803e85872bd72a42e1972b5ad7f580356a75f7 100644 (file)
@@ -6,6 +6,7 @@
 #include "BitmapFreelistManager.h"
 
 FreelistManager *FreelistManager::create(
+  CephContext* cct,
   string type,
   KeyValueDB *kvdb,
   string prefix)
@@ -16,9 +17,9 @@ FreelistManager *FreelistManager::create(
   // freelist type until after we open the db.
   assert(prefix == "B");
   if (type == "extent")
-    return new ExtentFreelistManager(kvdb, "B");
+    return new ExtentFreelistManager(cct, kvdb, "B");
   if (type == "bitmap")
-    return new BitmapFreelistManager(kvdb, "B", "b");
+    return new BitmapFreelistManager(cct, kvdb, "B", "b");
   return NULL;
 }
 
index 97062fc991714a30a12bc8afc4113af8a27efe33..1d0bb5c2a5cc7217c78fbe508d343d5d11f53487 100644 (file)
 
 class FreelistManager {
 public:
-  FreelistManager() {}
+  CephContext* cct;
+  FreelistManager(CephContext* cct) : cct(cct) {}
   virtual ~FreelistManager() {}
 
   static FreelistManager *create(
+    CephContext* cct,
     string type,
     KeyValueDB *db,
     string prefix);
index 2fb8dd260295a8847718381e70332302ca04b22d..dd238b7140c0b25e4a30b962372d819304480531 100644 (file)
 #include "common/blkdev.h"
 #include "common/align.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bdev
 #undef dout_prefix
 #define dout_prefix *_dout << "bdev(" << path << ") "
 
-KernelDevice::KernelDevice(aio_callback_t cb, void *cbpriv)
-  : fd_direct(-1),
+KernelDevice::KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv)
+  : BlockDevice(cct),
+    fd_direct(-1),
     fd_buffered(-1),
     size(0), block_size(0),
     fs(NULL), aio(false), dio(false),
     debug_lock("KernelDevice::debug_lock"),
     flush_lock("KernelDevice::flush_lock"),
-    aio_queue(g_conf->bdev_aio_max_queue_depth),
+    aio_queue(cct->_conf->bdev_aio_max_queue_depth),
     aio_callback(cb),
     aio_callback_priv(cbpriv),
     aio_stop(false),
@@ -82,7 +83,7 @@ int KernelDevice::open(string p)
     goto out_direct;
   }
   dio = true;
-  aio = g_conf->bdev_aio;
+  aio = cct->_conf->bdev_aio;
   if (!aio) {
     assert(0 == "non-aio not supported");
   }
@@ -129,7 +130,7 @@ int KernelDevice::open(string p)
   // blksize doesn't strictly matter except that some file systems may
   // require a read/modify/write if we write something smaller than
   // it.
-  block_size = g_conf->bdev_block_size;
+  block_size = cct->_conf->bdev_block_size;
   if (block_size != (unsigned)st.st_blksize) {
     dout(1) << __func__ << " backing device/file reports st_blksize "
            << st.st_blksize << ", using bdev_block_size "
@@ -192,14 +193,14 @@ int KernelDevice::flush()
     return 0;
   }
   dout(10) << __func__ << " start" << dendl;
-  if (g_conf->bdev_inject_crash) {
+  if (cct->_conf->bdev_inject_crash) {
     ++injecting_crash;
     // sleep for a moment to give other threads a chance to submit or
     // wait on io that races with a flush.
     derr << __func__ << " injecting crash. first we sleep..." << dendl;
-    sleep(g_conf->bdev_inject_crash_flush_delay);
+    sleep(cct->_conf->bdev_inject_crash_flush_delay);
     derr << __func__ << " and now we die" << dendl;
-    g_ceph_context->_log->flush();
+    cct->_log->flush();
     _exit(1);
   }
   utime_t start = ceph_clock_now();
@@ -248,7 +249,7 @@ void KernelDevice::_aio_thread()
     dout(40) << __func__ << " polling" << dendl;
     int max = 16;
     FS::aio_t *aio[max];
-    int r = aio_queue.get_next_completed(g_conf->bdev_aio_poll_ms,
+    int r = aio_queue.get_next_completed(cct->_conf->bdev_aio_poll_ms,
                                         aio, max);
     if (r < 0) {
       derr << __func__ << " got " << cpp_strerror(r) << dendl;
@@ -280,7 +281,7 @@ void KernelDevice::_aio_thread()
        }
       }
     }
-    if (g_conf->bdev_debug_aio) {
+    if (cct->_conf->bdev_debug_aio) {
       utime_t now = ceph_clock_now();
       std::lock_guard<std::mutex> l(debug_queue_lock);
       if (debug_oldest) {
@@ -288,11 +289,11 @@ void KernelDevice::_aio_thread()
          debug_stall_since = now;
        } else {
          utime_t cutoff = now;
-         cutoff -= g_conf->bdev_debug_aio_suicide_timeout;
+         cutoff -= cct->_conf->bdev_debug_aio_suicide_timeout;
          if (debug_stall_since < cutoff) {
            derr << __func__ << " stalled aio " << debug_oldest
                 << " since " << debug_stall_since << ", timeout is "
-                << g_conf->bdev_debug_aio_suicide_timeout
+                << cct->_conf->bdev_debug_aio_suicide_timeout
                 << "s, suicide" << dendl;
            assert(0 == "stalled aio... buggy kernel or bad device?");
          }
@@ -300,13 +301,13 @@ void KernelDevice::_aio_thread()
       }
     }
     reap_ioc();
-    if (g_conf->bdev_inject_crash) {
+    if (cct->_conf->bdev_inject_crash) {
       ++inject_crash_count;
-      if (inject_crash_count * g_conf->bdev_aio_poll_ms / 1000 >
-         g_conf->bdev_inject_crash + g_conf->bdev_inject_crash_flush_delay) {
+      if (inject_crash_count * cct->_conf->bdev_aio_poll_ms / 1000 >
+         cct->_conf->bdev_inject_crash + cct->_conf->bdev_inject_crash_flush_delay) {
        derr << __func__ << " bdev_inject_crash trigger from aio thread"
             << dendl;
-       g_ceph_context->_log->flush();
+       cct->_log->flush();
        _exit(1);
       }
     }
@@ -322,7 +323,7 @@ void KernelDevice::_aio_log_start(
 {
   dout(20) << __func__ << " 0x" << std::hex << offset << "~" << length
           << std::dec << dendl;
-  if (g_conf->bdev_debug_inflight_ios) {
+  if (cct->_conf->bdev_debug_inflight_ios) {
     Mutex::Locker l(debug_lock);
     if (debug_inflight.intersects(offset, length)) {
       derr << __func__ << " inflight overlap of 0x"
@@ -365,7 +366,7 @@ void KernelDevice::_aio_log_finish(
 {
   dout(20) << __func__ << " " << aio << " 0x"
           << std::hex << offset << "~" << length << std::dec << dendl;
-  if (g_conf->bdev_debug_inflight_ios) {
+  if (cct->_conf->bdev_debug_inflight_ios) {
     Mutex::Locker l(debug_lock);
     debug_inflight.erase(offset, length);
   }
@@ -413,7 +414,7 @@ void KernelDevice::aio_submit(IOContext *ioc)
     // do not dereference txc (or it's contents) after we submit (if
     // done == true and we don't loop)
     int retries = 0;
-    if (g_conf->bdev_debug_aio) {
+    if (cct->_conf->bdev_debug_aio) {
       std::lock_guard<std::mutex> l(debug_queue_lock);
       debug_aio_link(*cur);
     }
@@ -458,8 +459,8 @@ int KernelDevice::aio_write(
     ioc->pending_aios.push_back(FS::aio_t(ioc, fd_direct));
     ++ioc->num_pending;
     FS::aio_t& aio = ioc->pending_aios.back();
-    if (g_conf->bdev_inject_crash &&
-       rand() % g_conf->bdev_inject_crash == 0) {
+    if (cct->_conf->bdev_inject_crash &&
+       rand() % cct->_conf->bdev_inject_crash == 0) {
       derr << __func__ << " bdev_inject_crash: dropping io 0x" << std::hex
           << off << "~" << len << std::dec
           << dendl;
@@ -483,8 +484,8 @@ int KernelDevice::aio_write(
   {
     dout(5) << __func__ << " 0x" << std::hex << off << "~" << len
            << std::dec << " buffered" << dendl;
-    if (g_conf->bdev_inject_crash &&
-       rand() % g_conf->bdev_inject_crash == 0) {
+    if (cct->_conf->bdev_inject_crash &&
+       rand() % cct->_conf->bdev_inject_crash == 0) {
       derr << __func__ << " bdev_inject_crash: dropping io 0x" << std::hex
           << off << "~" << len << std::dec << dendl;
       ++injecting_crash;
index 54e315f7f257840441eb9d0ec1cbee6e56d850d3..a76abf9d9be982abc0ee6b1c570e0b32549bce1b 100644 (file)
@@ -73,7 +73,7 @@ class KernelDevice : public BlockDevice {
   void debug_aio_unlink(FS::aio_t& aio);
 
 public:
-  KernelDevice(aio_callback_t cb, void *cbpriv);
+  KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv);
 
   void aio_submit(IOContext *ioc) override;
 
index 8f983bfbec85393047d74909fbea72b95e9ea47e..ec636de9547ae930e08a81bd3cd4549370169bc2 100644 (file)
@@ -110,7 +110,7 @@ struct Task {
   Task(NVMEDevice *dev, IOCommand c, uint64_t off, uint64_t l, int64_t rc = 0)
     : device(dev), command(c), offset(off), len(l),
       return_code(rc),
-      start(ceph::coarse_real_clock::now(g_ceph_context)) {}
+      start(ceph::coarse_real_clock::now(cct)) {}
   ~Task() {
     assert(!io_request.nseg);
   }
@@ -205,7 +205,7 @@ class SharedDriverData {
     size = spdk_nvme_ns_get_sector_size(ns) * spdk_nvme_ns_get_num_sectors(ns);
     zero_command_support = spdk_nvme_ns_get_flags(ns) & SPDK_NVME_NS_WRITE_ZEROES_SUPPORTED;
 
-    PerfCountersBuilder b(g_ceph_context, string("NVMEDevice-AIOThread-"+stringify(this)),
+    PerfCountersBuilder b(cct, string("NVMEDevice-AIOThread-"+stringify(this)),
                           l_bluestore_nvmedevice_first, l_bluestore_nvmedevice_last);
     b.add_time_avg(l_bluestore_nvmedevice_aio_write_lat, "aio_write_lat", "Average write completing latency");
     b.add_time_avg(l_bluestore_nvmedevice_read_lat, "read_lat", "Average read completing latency");
@@ -217,11 +217,11 @@ class SharedDriverData {
     b.add_time_avg(l_bluestore_nvmedevice_flush_queue_lat, "flush_queue_lat", "Average queue flush request latency");
     b.add_u64_counter(l_bluestore_nvmedevice_buffer_alloc_failed, "buffer_alloc_failed", "Alloc data buffer failed count");
     logger = b.create_perf_counters();
-    g_ceph_context->get_perfcounters_collection()->add(logger);
+    cct->get_perfcounters_collection()->add(logger);
     _aio_start();
   }
   ~SharedDriverData() {
-    g_ceph_context->get_perfcounters_collection()->remove(logger);
+    cct->get_perfcounters_collection()->remove(logger);
     delete logger;
   }
 
@@ -389,7 +389,8 @@ void SharedDriverData::_aio_thread()
   int r = 0;
   const int max = 4;
   uint64_t lba_off, lba_count;
-  ceph::coarse_real_clock::time_point cur, start = ceph::coarse_real_clock::now(g_ceph_context);
+  ceph::coarse_real_clock::time_point cur, start
+    = ceph::coarse_real_clock::now();
   while (true) {
     bool inflight = queue_op_seq.load() - completed_op_seq.load();
  again:
@@ -423,7 +424,7 @@ void SharedDriverData::_aio_thread()
             derr << __func__ << " failed to do write command" << dendl;
             ceph_abort();
           }
-          cur = ceph::coarse_real_clock::now(g_ceph_context);
+          cur = ceph::coarse_real_clock::now();
           auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(cur - start);
           logger->tinc(l_bluestore_nvmedevice_aio_write_queue_lat, dur);
           break;
@@ -447,7 +448,7 @@ void SharedDriverData::_aio_thread()
             std::unique_lock<std::mutex> l(t->ctx->lock);
             t->ctx->cond.notify_all();
           } else {
-            cur = ceph::coarse_real_clock::now(g_ceph_context);
+            cur = ceph::coarse_real_clock::now(cct);
             auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(cur - start);
             logger->tinc(l_bluestore_nvmedevice_read_queue_lat, dur);
           }
@@ -463,7 +464,7 @@ void SharedDriverData::_aio_thread()
             std::unique_lock<std::mutex> l(t->ctx->lock);
             t->ctx->cond.notify_all();
           } else {
-            cur = ceph::coarse_real_clock::now(g_ceph_context);
+            cur = ceph::coarse_real_clock::now();
             auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(cur - start);
             logger->tinc(l_bluestore_nvmedevice_flush_queue_lat, dur);
           }
@@ -495,13 +496,13 @@ void SharedDriverData::_aio_thread()
 
         Mutex::Locker l(queue_lock);
         if (queue_empty.load()) {
-          cur = ceph::coarse_real_clock::now(g_ceph_context);
+         cur = ceph::coarse_real_clock::now(cct);
           auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(cur - start);
           logger->tinc(l_bluestore_nvmedevice_polling_lat, dur);
           if (aio_stop)
             break;
           queue_cond.Wait(queue_lock);
-          start = ceph::coarse_real_clock::now(g_ceph_context);
+          start = ceph::coarse_real_clock::now();
         }
       }
     }
@@ -587,7 +588,7 @@ static bool probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev)
 
   if (spdk_pci_device_has_non_uio_driver(pci_dev)) {
     /*NVMe kernel driver case*/
-    if (g_conf->bdev_nvme_unbind_from_kernel) {
+    if (cct->_conf->bdev_nvme_unbind_from_kernel) {
       r =  spdk_pci_device_switch_to_uio_driver(pci_dev);
       if (r < 0) {
         derr << __func__ << " device " << name
@@ -678,7 +679,7 @@ int NVMEManager::try_get(const string &sn_tag, SharedDriverData **driver)
         }
 
         pci_system_init();
-        spdk_nvme_retry_count = g_conf->bdev_nvme_retry_count;
+        spdk_nvme_retry_count = cct->_conf->bdev_nvme_retry_count;
         if (spdk_nvme_retry_count < 0)
           spdk_nvme_retry_count = SPDK_NVME_DEFAULT_RETRY_COUNT;
 
@@ -724,7 +725,7 @@ void io_complete(void *t, const struct spdk_nvme_cpl *completion)
   SharedDriverData *driver = task->device->get_driver();
   ++driver->completed_op_seq;
   auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(
-      ceph::coarse_real_clock::now(g_ceph_context) - task->start);
+      ceph::coarse_real_clock::now() - task->start);
   if (task->command == IOCommand::WRITE_COMMAND) {
     driver->logger->tinc(l_bluestore_nvmedevice_aio_write_lat, dur);
     assert(!spdk_nvme_cpl_is_error(completion));
@@ -774,8 +775,9 @@ void io_complete(void *t, const struct spdk_nvme_cpl *completion)
 #undef dout_prefix
 #define dout_prefix *_dout << "bdev(" << name << ") "
 
-NVMEDevice::NVMEDevice(aio_callback_t cb, void *cbpriv)
-    : driver(NULL),
+NVMEDevice::NVMEDevice(CephContext* cct, aio_callback_t cb, void *cbpriv)
+  :   BlockDevice(cct),
+      driver(nullptr),
       size(0),
       block_size(0),
       aio_stop(false),
@@ -856,10 +858,10 @@ void NVMEDevice::close()
 int NVMEDevice::flush()
 {
   dout(10) << __func__ << " start" << dendl;
-  auto start = ceph::coarse_real_clock::now(g_ceph_context);
+  auto start = ceph::coarse_real_clock::now();
   driver->flush_wait();
   auto dur = std::chrono::duration_cast<std::chrono::nanoseconds>(
-      ceph::coarse_real_clock::now(g_ceph_context) - start);
+      ceph::coarse_real_clock::now() - start);
   driver->logger->tinc(l_bluestore_nvmedevice_flush_lat, dur);
   return 0;
 }
index 75b751ae533d9c0cd462567da5803c2ad1d86956..244e81ade368be11e4ecb9bcb7fb7d3d68f2946c 100644 (file)
@@ -207,7 +207,7 @@ class NVMEDevice : public BlockDevice {
   aio_callback_t aio_callback;
   void *aio_callback_priv;
 
-  NVMEDevice(aio_callback_t cb, void *cbpriv);
+  NVMEDevice(CephContext* cct, aio_callback_t cb, void *cbpriv);
 
   bool supported_bdev_label() override { return false; }
 
index 090f1fce8110e8281212b458641a9c8416508db2..043697149b9a76545b6b113494261cff5d5ddb50 100644 (file)
@@ -5,13 +5,13 @@
 #include "bluestore_types.h"
 #include "common/debug.h"
 
-#define dout_context g_ceph_context
+#define dout_context cct
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "stupidalloc "
 
-StupidAllocator::StupidAllocator()
-  : num_free(0),
+StupidAllocator::StupidAllocator(CephContext* cct)
+  : cct(cct), num_free(0),
     num_reserved(0),
     free(10),
     last_alloc(0)
@@ -24,7 +24,7 @@ StupidAllocator::~StupidAllocator()
 
 unsigned StupidAllocator::_choose_bin(uint64_t orig_len)
 {
-  uint64_t len = orig_len / g_conf->bdev_block_size;
+  uint64_t len = orig_len / cct->_conf->bdev_block_size;
   int bin = std::min((int)cbits(len), (int)free.size() - 1);
   dout(30) << __func__ << " len 0x" << std::hex << orig_len << std::dec
           << " -> " << bin << dendl;
@@ -159,9 +159,9 @@ int StupidAllocator::allocate_int(
     skew = alloc_unit - skew;
   *offset = p.get_start() + skew;
   *length = MIN(MAX(alloc_unit, want_size), p.get_len() - skew);
-  if (g_conf->bluestore_debug_small_allocations) {
+  if (cct->_conf->bluestore_debug_small_allocations) {
     uint64_t max =
-      alloc_unit * (rand() % g_conf->bluestore_debug_small_allocations);
+      alloc_unit * (rand() % cct->_conf->bluestore_debug_small_allocations);
     if (max && *length > max) {
       dout(10) << __func__ << " shortening allocation of 0x" << std::hex
               << *length << " -> 0x"
index 004b6d604574fe7ea161ee18cab768270b95e57f..b3b2950005b309e9b69043bcaa623cafee49b8fd 100644 (file)
@@ -11,6 +11,7 @@
 #include "os/bluestore/bluestore_types.h"
 
 class StupidAllocator : public Allocator {
+  CephContext* cct;
   std::mutex lock;
 
   int64_t num_free;     ///< total bytes in freelist
@@ -24,7 +25,7 @@ class StupidAllocator : public Allocator {
   void _insert_free(uint64_t offset, uint64_t len);
 
 public:
-  StupidAllocator();
+  StupidAllocator(CephContext* cct);
   ~StupidAllocator();
 
   int reserve(uint64_t need);
index 150b16826be89c86e3ba05f68618f1caa7413c39..dc7812367b5e872e76a2c6e091fd5a704bb664fe 100644 (file)
@@ -27,13 +27,13 @@ int main(int argc, char **argv)
 
   auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
                         CODE_ENVIRONMENT_UTILITY, 0);
-  common_init_finish(g_ceph_context);
-  g_ceph_context->_conf->set_val(
+  common_init_finish(cct.get());
+  cct->_conf->set_val(
     "enable_experimental_unrecoverable_data_corrupting_features",
     "*");
-  g_ceph_context->_conf->apply_changes(NULL);
+  cct->_conf->apply_changes(NULL);
 
-  BlueFS fs;
+  BlueFS fs(&(*cct));
 
   if (args.size() != 4) {
     usage(argv);
index 3e60408377b8f64dfbf7c6444d07fec2f195521e..8386caf362613e82d0b6edd873ff7d431e033a67 100644 (file)
@@ -512,7 +512,7 @@ class ObjectCacher {
   void mark_dirty(BufferHead *bh) {
     bh_set_state(bh, BufferHead::STATE_DIRTY);
     bh_lru_dirty.lru_touch(bh);
-    //bh->set_dirty_stamp(ceph_clock_now(g_ceph_context));
+    //bh->set_dirty_stamp(ceph_clock_now());
   }
 
   void bh_add(Object *ob, BufferHead *bh);
index 0b75f9c4f46d972b5d0d56a069a30125cc917122..df9363a3e1d2d471cd51ffda5ca8565c5600acf8 100644 (file)
@@ -24,7 +24,8 @@ public:
     AllocTest(): alloc(0) { }
     void init_alloc(int64_t size, uint64_t min_alloc_size) {
       std::cout << "Creating alloc type " << string(GetParam()) << " \n";
-      alloc.reset(Allocator::create(string(GetParam()), size, min_alloc_size));
+      alloc.reset(Allocator::create(g_ceph_context, string(GetParam()), size,
+                                   min_alloc_size));
     }
 
     void init_close() {
@@ -224,7 +225,7 @@ TEST_P(AllocTest, test_alloc_hint_bmap)
   if (GetParam() == std::string("stupid")) {
     return;
   }
-  int64_t blocks = BitMapArea::get_level_factor(2) * 4;
+  int64_t blocks = BitMapArea::get_level_factor(g_ceph_context, 2) * 4;
   int count = 0;
   int64_t allocated = 0;
   int64_t zone_size = 1024;
index 09460a153b6f0987c5b2ba8b621b2e6af4345f25..f68f44e0edc5a127ee52e7d47a032db8aa0e028e 100644 (file)
@@ -118,7 +118,9 @@ TEST(BitAllocator, test_bmap_iter)
   BitMapArea *area = NULL;
   BitMapArea **children = new BitMapArea*[num_items];
   for (i = 0; i < num_items; i++) {
-      children[i] = new BitMapAreaLeaf(BitMapArea::get_span_size(), i, false);
+    children[i] = new BitMapAreaLeaf(
+      g_ceph_context,
+      BitMapArea::get_span_size(g_ceph_context), i, false);
   }
 
   off = 0;
@@ -170,7 +172,7 @@ TEST(BitAllocator, test_bmap_entry)
   int64_t allocated = 0;
   int size = BmapEntry::size();
 
-  BmapEntry *bmap = new BmapEntry(true);
+  BmapEntry *bmap = new BmapEntry(g_ceph_context, true);
 
   // Clear bits one by one and check they are cleared
   for (i = 0; i < size; i++) {
@@ -239,7 +241,7 @@ TEST(BitAllocator, test_bmap_entry)
 
   {
 
-    bmap = new BmapEntry(false);
+    bmap = new BmapEntry(g_ceph_context, false);
     start = -1;
     scanned = 0;
     allocated = 0;
@@ -259,7 +261,7 @@ TEST(BitAllocator, test_bmap_entry)
     delete bmap;
   }
 
-  bmap = new BmapEntry(false);
+  bmap = new BmapEntry(g_ceph_context, false);
   bmap->set_bits(4, BmapEntry::size() - 4);
   bmap_test_assert(bmap->is_allocated(4, BmapEntry::size() - 4));
   bmap_test_assert(!bmap->is_allocated(0, 4));
@@ -274,7 +276,7 @@ TEST(BitAllocator, test_zone_alloc)
   int total_blocks = 1024;
   int64_t allocated = 0;
 
-  BitMapZone *zone = new BitMapZone(total_blocks, 0);
+  BitMapZone *zone = new BitMapZone(g_ceph_context, total_blocks, 0);
 
   // Allocate all blocks and see that it is allocating in order.
   bool lock = zone->lock_excl_try();
@@ -296,7 +298,7 @@ TEST(BitAllocator, test_zone_alloc)
 
     ExtentList *block_list = new ExtentList(&extents, blk_size);
 
-    zone = new BitMapZone(total_blocks, 0);
+    zone = new BitMapZone(g_ceph_context, total_blocks, 0);
     lock = zone->lock_excl_try();
     bmap_test_assert(lock);
     for (int i = 0; i < zone->size(); i += 4) {
@@ -322,7 +324,7 @@ TEST(BitAllocator, test_zone_alloc)
     for (int i = 1; i <= total_blocks - BmapEntry::size(); i = i << 1) {
       for (int64_t j = 0; j <= BmapEntry::size(); j = 1 << j) {
         ExtentList *block_list = new ExtentList(&extents, blk_size);
-        zone = new BitMapZone(total_blocks, 0);
+       zone = new BitMapZone(g_ceph_context, total_blocks, 0);
         lock = zone->lock_excl_try();
         bmap_test_assert(lock);
 
@@ -339,7 +341,7 @@ TEST(BitAllocator, test_zone_alloc)
     //allocation in loop
     {
       ExtentList *block_list = new ExtentList(&extents, blk_size);
-      zone = new BitMapZone(total_blocks, 0);
+      zone = new BitMapZone(g_ceph_context, total_blocks, 0);
       lock = zone->lock_excl_try();
 
       for (int iter = 1; iter < 5; iter++) {
@@ -371,7 +373,7 @@ TEST(BitAllocator, test_zone_alloc)
     {
 
         ExtentList *block_list = new ExtentList(&extents, blk_size);
-        zone = new BitMapZone(total_blocks, 0);
+       zone = new BitMapZone(g_ceph_context, total_blocks, 0);
         lock = zone->lock_excl_try();
         bmap_test_assert(lock);
 
@@ -424,8 +426,8 @@ TEST(BitAllocator, test_bmap_alloc)
     int64_t total_blocks = zone_size * 4;
     int64_t allocated = 0;
 
-    BitAllocator *alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
-   
+    BitAllocator *alloc = new BitAllocator(g_ceph_context, total_blocks,
+                                          zone_size, CONCURRENT);
     int64_t alloc_size = 2;
     for (int64_t iter = 0; iter < max_iter; iter++) {
       for (int64_t j = 0; alloc_size <= total_blocks; j++) {
@@ -523,7 +525,8 @@ TEST(BitAllocator, test_bmap_alloc2)
 {
   int64_t total_blocks = 1024 * 4;
   int64_t zone_size = 1024;
-  BitAllocator *alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
+  BitAllocator *alloc = new BitAllocator(g_ceph_context, total_blocks,
+                                        zone_size, CONCURRENT);
 
   alloc_extents_max_block(alloc, 1, 16);
   alloc_extents_max_block(alloc, 4, 16);
@@ -577,7 +580,8 @@ TEST(BitAllocator, test_bmap_alloc_concurrent)
 
   bmap_test_assert(total_blocks <= MAX_BLOCKS);
 
-  BitAllocator *alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
+  BitAllocator *alloc = new BitAllocator(g_ceph_context, total_blocks,
+                                        zone_size, CONCURRENT);
 
   for (int k = 0; k < 2; k++) {
     cont = k;
index 01763fec35c68b5fd798481c59ec4c016f33856f..f9875ea4f87c2760a00ba83b60648b7ebf5144b5 100644 (file)
@@ -47,7 +47,7 @@ TEST(BlueFS, mkfs) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
   uuid_d fsid;
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   fs.add_block_device(BlueFS::BDEV_DB, fn);
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   fs.mkfs(fsid);
@@ -57,7 +57,7 @@ TEST(BlueFS, mkfs) {
 TEST(BlueFS, mkfs_mount) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -72,7 +72,7 @@ TEST(BlueFS, mkfs_mount) {
 TEST(BlueFS, write_read) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -104,7 +104,7 @@ TEST(BlueFS, write_read) {
 TEST(BlueFS, small_appends) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -255,7 +255,7 @@ TEST(BlueFS, test_flush_1) {
     "65536");
   g_ceph_context->_conf->apply_changes(NULL);
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -290,7 +290,7 @@ TEST(BlueFS, test_flush_2) {
     "65536");
   g_ceph_context->_conf->apply_changes(NULL);
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -318,7 +318,7 @@ TEST(BlueFS, test_flush_3) {
     "65536");
   g_ceph_context->_conf->apply_changes(NULL);
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -352,7 +352,7 @@ TEST(BlueFS, test_simple_compaction_sync) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -405,7 +405,7 @@ TEST(BlueFS, test_simple_compaction_async) {
   uint64_t size = 1048576 * 128;
   string fn = get_temp_bdev(size);
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -461,7 +461,7 @@ TEST(BlueFS, test_compaction_sync) {
     "bluefs_compact_log_sync",
     "true");
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -499,7 +499,7 @@ TEST(BlueFS, test_compaction_async) {
     "bluefs_compact_log_sync",
     "false");
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
@@ -537,7 +537,7 @@ TEST(BlueFS, test_replay) {
     "bluefs_compact_log_sync",
     "false");
 
-  BlueFS fs;
+  BlueFS fs(g_ceph_context);
   ASSERT_EQ(0, fs.add_block_device(BlueFS::BDEV_DB, fn));
   fs.add_block_extent(BlueFS::BDEV_DB, 1048576, size - 1048576);
   uuid_d fsid;
index 4c63bef32c72591728451ca19ebc2126acb47c18..6da44a74bf50ddb26213a72a716c461c3c34c7af 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
 #include "include/types.h"
@@ -317,7 +317,7 @@ TEST(bluestore_blob_t, csum_bench)
 TEST(Blob, put_ref)
 {
   {
-    BlueStore::Blob b;
+    BlueStore::Blob b(g_ceph_context);
     b.shared_blob = new BlueStore::SharedBlob(nullptr);
     b.shared_blob->get();  // hack to avoid dtor from running
     b.dirty_blob().extents.push_back(bluestore_pextent_t(0x40715000, 0x2000));
@@ -336,14 +336,14 @@ TEST(Blob, put_ref)
     r.clear();
     b.put_ref(0xae00, 0x4200, 0x1000, &r);
     cout << " r " << r << std::endl;
-    cout << b << std::endl;  
+    cout << b << std::endl;
   }
 
   unsigned mas = 4096;
   unsigned mrs = 8192;
 
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -363,7 +363,7 @@ TEST(Blob, put_ref)
     ASSERT_EQ(mas*2, b.extents[0].length);
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -384,7 +384,7 @@ TEST(Blob, put_ref)
     ASSERT_EQ(mas*2, b.extents[0].length);
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -419,7 +419,7 @@ TEST(Blob, put_ref)
     ASSERT_EQ(3u, b.extents.size());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -457,7 +457,7 @@ TEST(Blob, put_ref)
     ASSERT_TRUE(b.extents[4].is_valid());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -486,7 +486,7 @@ TEST(Blob, put_ref)
     ASSERT_TRUE(b.extents[2].is_valid());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -521,7 +521,7 @@ TEST(Blob, put_ref)
     ASSERT_TRUE(b.extents[2].is_valid());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -571,7 +571,7 @@ TEST(Blob, put_ref)
     ASSERT_FALSE(b.extents[0].is_valid());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -621,7 +621,7 @@ TEST(Blob, put_ref)
     ASSERT_FALSE(b.extents[0].is_valid());
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -659,7 +659,7 @@ TEST(Blob, put_ref)
   }
   // verify csum chunk size if factored in properly
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -676,7 +676,7 @@ TEST(Blob, put_ref)
     ASSERT_EQ(mas*4, b.extents[0].length);
   }
   {
-    BlueStore::Blob B;
+    BlueStore::Blob B(g_ceph_context);
     B.shared_blob = new BlueStore::SharedBlob(nullptr);
     B.shared_blob->get();  // hack to avoid dtor from running
     bluestore_blob_t& b = B.dirty_blob();
@@ -759,9 +759,10 @@ TEST(bluestore_blob_t, prune_tail)
 
 TEST(Blob, split)
 {
-  BlueStore::Cache *cache = BlueStore::Cache::create("lru", NULL);
+  BlueStore::Cache *cache = BlueStore::Cache::create(
+    g_ceph_context, "lru", NULL);
   {
-    BlueStore::Blob L, R;
+    BlueStore::Blob L(g_ceph_context), R(g_ceph_context);
     L.shared_blob = new BlueStore::SharedBlob(cache);
     L.shared_blob->get();  // hack to avoid dtor from running
     R.shared_blob = new BlueStore::SharedBlob(cache);
@@ -781,7 +782,7 @@ TEST(Blob, split)
     ASSERT_EQ(0x1000u, R.get_blob().extents.front().length);
   }
   {
-    BlueStore::Blob L, R;
+    BlueStore::Blob L(g_ceph_context), R(g_ceph_context);
     L.shared_blob = new BlueStore::SharedBlob(cache);
     L.shared_blob->get();  // hack to avoid dtor from running
     R.shared_blob = new BlueStore::SharedBlob(cache);
@@ -805,9 +806,9 @@ TEST(Blob, split)
 
 TEST(ExtentMap, find_lextent)
 {
-  BlueStore::LRUCache cache;
-  BlueStore::ExtentMap em(nullptr);
-  BlueStore::BlobRef br(new BlueStore::Blob);
+  BlueStore::LRUCache cache(g_ceph_context);
+  BlueStore::ExtentMap em(g_ceph_context, nullptr);
+  BlueStore::BlobRef br(new BlueStore::Blob(g_ceph_context));
   br->shared_blob = new BlueStore::SharedBlob(&cache);
 
   ASSERT_EQ(em.extent_map.end(), em.find_lextent(0));
@@ -851,9 +852,9 @@ TEST(ExtentMap, find_lextent)
 
 TEST(ExtentMap, seek_lextent)
 {
-  BlueStore::LRUCache cache;
-  BlueStore::ExtentMap em(nullptr);
-  BlueStore::BlobRef br(new BlueStore::Blob);
+  BlueStore::LRUCache cache(g_ceph_context);
+  BlueStore::ExtentMap em(g_ceph_context, nullptr);
+  BlueStore::BlobRef br(new BlueStore::Blob(g_ceph_context));
   br->shared_blob = new BlueStore::SharedBlob(&cache);
 
   ASSERT_EQ(em.extent_map.end(), em.seek_lextent(0));
@@ -897,9 +898,9 @@ TEST(ExtentMap, seek_lextent)
 
 TEST(ExtentMap, has_any_lextents)
 {
-  BlueStore::LRUCache cache;
-  BlueStore::ExtentMap em(nullptr);
-  BlueStore::BlobRef b(new BlueStore::Blob);
+  BlueStore::LRUCache cache(g_ceph_context);
+  BlueStore::ExtentMap em(g_ceph_context, nullptr);
+  BlueStore::BlobRef b(new BlueStore::Blob(g_ceph_context));
   b->shared_blob = new BlueStore::SharedBlob(&cache);
 
   ASSERT_FALSE(em.has_any_lextents(0, 0));
@@ -941,11 +942,11 @@ TEST(ExtentMap, has_any_lextents)
 
 TEST(ExtentMap, compress_extent_map)
 {
-  BlueStore::LRUCache cache;
-  BlueStore::ExtentMap em(nullptr);
-  BlueStore::BlobRef b1(new BlueStore::Blob);
-  BlueStore::BlobRef b2(new BlueStore::Blob);
-  BlueStore::BlobRef b3(new BlueStore::Blob);
+  BlueStore::LRUCache cache(g_ceph_context);
+  BlueStore::ExtentMap em(g_ceph_context, nullptr);
+  BlueStore::BlobRef b1(new BlueStore::Blob(g_ceph_context));
+  BlueStore::BlobRef b2(new BlueStore::Blob(g_ceph_context));
+  BlueStore::BlobRef b3(new BlueStore::Blob(g_ceph_context));
   b1->shared_blob = new BlueStore::SharedBlob(&cache);
   b2->shared_blob = new BlueStore::SharedBlob(&cache);
   b3->shared_blob = new BlueStore::SharedBlob(&cache);