]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: tolerate zero length for allocators' init_[add/rm]_free() 41612/head
authorIgor Fedotov <ifedotov@suse.com>
Thu, 29 Apr 2021 18:16:44 +0000 (21:16 +0300)
committerCory Snyder <csnyder@iland.com>
Tue, 1 Jun 2021 09:57:58 +0000 (05:57 -0400)
Signed-off-by: Igor Fedotov <ifedotov@suse.com>
(cherry picked from commit 6548e5d991810e89fc1ac14eb4fcf1a37a2b129f)

src/os/bluestore/AvlAllocator.cc
src/os/bluestore/HybridAllocator.cc
src/os/bluestore/StupidAllocator.cc
src/test/objectstore/Allocator_test.cc

index 0ac70baa80c3acd6cd87c03bfb59d06158730842..42b6ea028752f71a6c772c38bd83b24b5c6c157b 100644 (file)
@@ -405,6 +405,8 @@ void AvlAllocator::dump(std::function<void(uint64_t offset, uint64_t length)> no
 
 void AvlAllocator::init_add_free(uint64_t offset, uint64_t length)
 {
+  if (!length)
+    return;
   std::lock_guard l(lock);
   ldout(cct, 10) << __func__ << std::hex
                  << " offset 0x" << offset
@@ -415,6 +417,8 @@ void AvlAllocator::init_add_free(uint64_t offset, uint64_t length)
 
 void AvlAllocator::init_rm_free(uint64_t offset, uint64_t length)
 {
+  if (!length)
+    return;
   std::lock_guard l(lock);
   ldout(cct, 10) << __func__ << std::hex
                  << " offset 0x" << offset
index 6caf5c6dd8924be68db1301ddb180e84d9a35299..3a2da67379b592eda2b8312b741102ff8bf149c7 100644 (file)
@@ -155,6 +155,8 @@ void HybridAllocator::dump(std::function<void(uint64_t offset, uint64_t length)>
 
 void HybridAllocator::init_rm_free(uint64_t offset, uint64_t length)
 {
+  if (!length)
+    return;
   std::lock_guard l(lock);
   ldout(cct, 10) << __func__ << std::hex
                  << " offset 0x" << offset
index 2660657d9e93480baa07dfb1d48118e47d72648f..ca6121ac38c584e95564a80a768e49ff6747eaa6 100644 (file)
@@ -307,6 +307,8 @@ void StupidAllocator::dump(std::function<void(uint64_t offset, uint64_t length)>
 
 void StupidAllocator::init_add_free(uint64_t offset, uint64_t length)
 {
+  if (!length)
+    return;
   std::lock_guard l(lock);
   ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
                 << std::dec << dendl;
@@ -316,6 +318,8 @@ void StupidAllocator::init_add_free(uint64_t offset, uint64_t length)
 
 void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length)
 {
+  if (!length)
+    return;
   std::lock_guard l(lock);
   ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length
                 << std::dec << dendl;
index f6f0c38bec20abc5e9e00bbb3a3bb8328e45891b..71b74d5abe39ce182dc21187ffcce513da69d0bf 100644 (file)
@@ -47,6 +47,23 @@ TEST_P(AllocTest, test_alloc_init)
   ASSERT_EQ(alloc->get_free(), (uint64_t) 0);
 }
 
+TEST_P(AllocTest, test_init_add_free)
+{
+  int64_t block_size = 1024;
+  int64_t capacity = 4 * 1024 * block_size;
+
+  {
+    init_alloc(capacity, block_size);
+
+    auto free = alloc->get_free();
+    alloc->init_add_free(block_size, 0);
+    ASSERT_EQ(free, alloc->get_free());
+
+    alloc->init_rm_free(block_size, 0);
+    ASSERT_EQ(free, alloc->get_free());
+  }
+}
+
 TEST_P(AllocTest, test_alloc_min_alloc)
 {
   int64_t block_size = 1024;