From: Igor Fedotov Date: Thu, 29 Apr 2021 18:16:44 +0000 (+0300) Subject: os/bluestore: tolerate zero length for allocators' init_[add/rm]_free() X-Git-Tag: v15.2.14~61^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=dd59b241288e66bddea28132b8bfb239b160e1a1;p=ceph.git os/bluestore: tolerate zero length for allocators' init_[add/rm]_free() Signed-off-by: Igor Fedotov (cherry picked from commit 6548e5d991810e89fc1ac14eb4fcf1a37a2b129f) --- diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index 0ac70baa80c3a..42b6ea028752f 100644 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -405,6 +405,8 @@ void AvlAllocator::dump(std::function 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 diff --git a/src/os/bluestore/HybridAllocator.cc b/src/os/bluestore/HybridAllocator.cc index 6caf5c6dd8924..3a2da67379b59 100644 --- a/src/os/bluestore/HybridAllocator.cc +++ b/src/os/bluestore/HybridAllocator.cc @@ -155,6 +155,8 @@ void HybridAllocator::dump(std::function 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 diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 2660657d9e934..ca6121ac38c58 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -307,6 +307,8 @@ void StupidAllocator::dump(std::function 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; diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index f6f0c38bec20a..71b74d5abe39c 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -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;