]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: separate Allocator from freelist storage
authorSage Weil <sage@redhat.com>
Thu, 10 Dec 2015 21:05:56 +0000 (16:05 -0500)
committerSage Weil <sage@redhat.com>
Fri, 1 Jan 2016 18:06:52 +0000 (13:06 -0500)
FreelistManager perists our freelist.  Allocator is a policy that
allocates it.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/Allocator.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/StupidAllocator.cc
src/os/bluestore/StupidAllocator.h

index 9d4b71726d70b543dc877e6721e8beaa80f4eec8..5c120a2f6a9f3ab9cd0b4275a644a86119601101 100644 (file)
@@ -36,7 +36,8 @@ public:
 
   virtual void dump(std::ostream& out) = 0;
 
-  virtual int init(FreelistManager *fm) = 0;
+  virtual void init_add_free(uint64_t offset, uint64_t length) = 0;
+
   virtual void shutdown() = 0;
 
   static Allocator *create(string type);
index 674571723c36ae36cf8ae1ddc2674e3ab6789073..451ffaf65f40677cdbd330b42cd7490e5fc3361e 100644 (file)
@@ -786,16 +786,18 @@ int BlueStore::_open_alloc()
     fm = NULL;
     return r;
   }
+
   alloc = Allocator::create("stupid");
-  r =  alloc->init(fm);
-  if (r < 0) {
-    delete alloc;
-    alloc = NULL;
-    fm->shutdown();
-    delete fm;
-    fm = NULL;
-    return r;
-  }
+  uint64_t num = 0, bytes = 0;
+  const map<uint64_t,uint64_t>& fl = fm->get_freelist();
+  for (auto p : fl) {
+    alloc->init_add_free(p.first, p.second);
+    ++num;
+    bytes += p.second;
+  }
+  dout(10) << __func__ << " loaded " << pretty_si_t(bytes)
+          << " in " << num << " extents"
+          << dendl;
   return r;
 }
 
index 95688d536f599cb05c84033446921899f694d2c1..2727f8c8a440ba90984fc517aa0d14ab887c803a 100644 (file)
@@ -4,15 +4,13 @@
 #include "StupidAllocator.h"
 #include "bluestore_types.h"
 #include "BlueStore.h"
-#include "FreelistManager.h"
 
 #define dout_subsys ceph_subsys_bluestore
 #undef dout_prefix
 #define dout_prefix *_dout << "stupidalloc "
 
 StupidAllocator::StupidAllocator()
-  : fm(NULL),
-    lock("StupicAllocator::lock"),
+  : lock("StupicAllocator::lock"),
     num_free(0),
     num_uncommitted(0),
     num_committing(0),
@@ -192,28 +190,13 @@ void StupidAllocator::dump(ostream& out)
        ++p) {
     dout(30) << __func__ << "  " << p.get_start() << "~" << p.get_len() << dendl;
   }
-  fm->dump();
 }
 
-int StupidAllocator::init(FreelistManager *f)
+void StupidAllocator::init_add_free(uint64_t offset, uint64_t length)
 {
-  dout(1) << __func__ << dendl;
-  fm = f;
-
-  // load state from freelist
-  unsigned num = 0;
-  const map<uint64_t,uint64_t>& fl = fm->get_freelist();
-  for (map<uint64_t,uint64_t>::const_iterator p = fl.begin(); p != fl.end(); ++p) {
-    dout(30) << "  " << p->first << "~" << p->second << dendl;
-    _insert_free(p->first, p->second);
-    ++num;
-    num_free += p->second;
-  }
-
-  dout(10) << __func__ << " loaded " << pretty_si_t(num_free)
-          << " in " << num << " extents"
-          << dendl;
-  return 0;
+  dout(10) << __func__ << " " << offset << "~" << length << dendl;
+  _insert_free(offset, length);
+  num_free += length;
 }
 
 void StupidAllocator::shutdown()
index ca20c0a83f108398cf51fa9ed364bfb5a0446bc2..ffaec2aebef3d173cf76da93900943140ef9fc36 100644 (file)
@@ -8,10 +8,7 @@
 #include "include/interval_set.h"
 #include "common/Mutex.h"
 
-class FreelistManager;
-
 class StupidAllocator : public Allocator {
-  FreelistManager *fm;
   Mutex lock;
 
   uint64_t num_free;     ///< total bytes in freelist
@@ -46,7 +43,7 @@ public:
 
   void dump(ostream& out);
 
-  int init(FreelistManager *f);
+  void init_add_free(uint64_t offset, uint64_t length);
   void shutdown();
 };