]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix the demotion in StupidAllocator::init_rm_free 20430/head
authorKefu Chai <kchai@redhat.com>
Wed, 14 Feb 2018 04:17:06 +0000 (12:17 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 14 Feb 2018 04:22:56 +0000 (12:22 +0800)
* we should update the _size field when demotion kicks in, otherwise the
  interval_set::m and interval_set::_size won't be consistent.
* also rename post_process to claim, as it "steals" the leftover(s) of
chopped segment.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/include/interval_set.h
src/os/bluestore/StupidAllocator.cc

index 26e7a9d78393cf2bd5e42de5d369168866b8b80b..4fcd60eb06588b97bcb72b67a46c1196c1f06c2b 100644 (file)
@@ -521,7 +521,7 @@ class interval_set {
   }
 
   void erase(T start, T len, 
-    std::function<bool(T, T)> post_process = {}) {
+    std::function<bool(T, T)> claim = {}) {
     typename Map::iterator p = find_inc_m(start);
 
     _size -= len;
@@ -533,13 +533,22 @@ class interval_set {
     T before = start - p->first;
     assert(p->second >= before+len);
     T after = p->second - before - len;
-    if (before && (post_process ? post_process(p->first, before) : true)) {
-      p->second = before;        // shorten bit before
+    if (before) {
+      if (claim && claim(p->first, before)) {
+       _size -= before;
+       m.erase(p);
+      } else {
+       p->second = before;        // shorten bit before
+      }
     } else {
       m.erase(p);
     }
-    if (after && (post_process ? post_process(start + len, after) : true)) {
-      m[start + len] = after;
+    if (after) {
+      if (claim && claim(start + len, after)) {
+       _size -= after;
+      } else {
+       m[start + len] = after;
+      }
     }
   }
 
index 706b00ea004f0690f8e01a7ecea6ad8fb50964ea..9aba90bb03ec83c2313ca434547cce62b5ad17e4 100644 (file)
@@ -323,9 +323,9 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length)
               ldout(cct, 30) << __func__ << " demoting1 0x" << std::hex << off << "~" << len
                              << std::dec << " to bin " << newbin << dendl;
               _insert_free(off, len);
-              return false;
+              return true;
             }
-            return true;
+            return false;
           });
         ++it;
       }