]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlueFS: add reclaim_blocks interface
authorSage Weil <sage@redhat.com>
Mon, 11 Jan 2016 19:40:50 +0000 (14:40 -0500)
committerSage Weil <sage@redhat.com>
Mon, 11 Jan 2016 19:42:47 +0000 (14:42 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index e2d41ba937d3bf930ecdaad482d8268f8a346f2d..d1d58c20e4be119668f33e8f604cc2dd4dda549a 100644 (file)
@@ -81,6 +81,30 @@ void BlueFS::add_block_extent(unsigned id, uint64_t offset, uint64_t length)
   dout(10) << __func__ << " done" << dendl;
 }
 
+int BlueFS::reclaim_blocks(unsigned id, uint64_t want,
+                          uint64_t *offset, uint32_t *length)
+{
+  dout(1) << __func__ << " bdev " << id << " want " << want << dendl;
+  assert(id < alloc.size());
+  int r = alloc[id]->reserve(want);
+  assert(r == 0); // caller shouldn't ask for more than they can get
+
+  r = alloc[id]->allocate(want, g_conf->bluefs_alloc_size, 0,
+                           offset, length);
+  assert(r >= 0);
+  if (*length < want)
+    alloc[id]->unreserve(want - *length);
+
+  block_all[id].erase(*offset, *length);
+  log_t.op_alloc_rm(id, *offset, *length);
+  r = _flush_log();
+  assert(r == 0);
+
+  dout(1) << __func__ << " bdev " << id << " want " << want
+         << " got " << *offset << "~" << *length << dendl;
+  return 0;
+}
+
 uint64_t BlueFS::get_total(unsigned id)
 {
   Mutex::Locker l(lock);
index 0a489b8f1c6109022e9f814b6198841fae279f95..be1f88dea88a2633b5bf0ea1a8dd35be6a6dc8d4 100644 (file)
@@ -303,6 +303,10 @@ public:
   /// gift more block space
   void add_block_extent(unsigned bdev, uint64_t offset, uint64_t len);
 
+  /// reclaim block space
+  int reclaim_blocks(unsigned bdev, uint64_t want,
+                    uint64_t *offset, uint32_t *length);
+
   void flush(FileWriter *h) {
     Mutex::Locker l(lock);
     _flush(h, false);