From 539af4f27e773cb21d187b75086c7c9498dd7749 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 25 Jun 2018 17:42:41 +0300 Subject: [PATCH] os/bluestore: fix overlappedd allocation returned by bitmap allocator Fixes: https://tracker.ceph.com/issues/24598 Signed-off-by: Igor Fedotov --- src/os/bluestore/fastbmap_allocator_impl.cc | 2 +- src/test/objectstore/Allocator_test.cc | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/os/bluestore/fastbmap_allocator_impl.cc b/src/os/bluestore/fastbmap_allocator_impl.cc index 9fdaab2fb3b..424f8051871 100755 --- a/src/os/bluestore/fastbmap_allocator_impl.cc +++ b/src/os/bluestore/fastbmap_allocator_impl.cc @@ -85,8 +85,8 @@ interval_t AllocatorLevel01Loose::_get_longest_from_l0(uint64_t pos0, res_candidate.length, min_granules); if (res.length < res_candidate.length) { res = res_candidate; - res_candidate = interval_t(); } + res_candidate = interval_t(); pos += d; end_loop = pos >= pos1; continue; diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index 3b6bc358856..959932af9e5 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -285,6 +285,37 @@ TEST_P(AllocTest, test_alloc_fragmentation) // digits after decimal point due to this. EXPECT_EQ(0, uint64_t(alloc->get_fragmentation(alloc_unit) * 100)); } + +TEST_P(AllocTest, test_alloc_bug_24598) +{ + if (string(GetParam()) != "bitmap") + return; + + uint64_t capacity = 0x2625a0000ull; + uint64_t alloc_unit = 0x4000; + uint64_t want_size = 0x200000; + PExtentVector allocated, tmp; + + init_alloc(capacity, alloc_unit); + + alloc->init_add_free(0x4800000, 0x100000); + alloc->init_add_free(0x4a00000, 0x100000); + + alloc->init_rm_free(0x4800000, 0x100000); + alloc->init_rm_free(0x4a00000, 0x100000); + + alloc->init_add_free(0x3f00000, 0x500000); + alloc->init_add_free(0x4500000, 0x100000); + alloc->init_add_free(0x4700000, 0x100000); + alloc->init_add_free(0x4900000, 0x100000); + alloc->init_add_free(0x4b00000, 0x200000); + + EXPECT_EQ(want_size, alloc->allocate(want_size, 0x100000, 0, 0, &tmp)); + EXPECT_EQ(tmp[0].offset, 0x4b00000); + EXPECT_EQ(tmp[0].length, 0x200000); + EXPECT_EQ(tmp.size(), 1); +} + INSTANTIATE_TEST_CASE_P( Allocator, AllocTest, -- 2.39.5