From 762dd42971a9ced62ea5617f7cd6b0e0fd2ef74c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 28 Oct 2017 16:20:43 -0500 Subject: [PATCH] os/bluestore: use interval_set<...,btree_map<...>> This avoid the code duplication, yay! Signed-off-by: Sage Weil --- src/os/bluestore/StupidAllocator.cc | 6 +++--- src/os/bluestore/StupidAllocator.h | 11 +++++++---- src/test/common/test_interval_set.cc | 8 ++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 0c28fa1730afe..41962bca6c1a7 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -72,7 +72,7 @@ void StupidAllocator::unreserve(uint64_t unused) /// return the effective length of the extent if we align to alloc_unit uint64_t StupidAllocator::_aligned_len( - btree_interval_set::iterator p, + StupidAllocator::interval_set_t::iterator p, uint64_t alloc_unit) { uint64_t skew = p.get_start() % alloc_unit; @@ -292,10 +292,10 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length) std::lock_guard l(lock); ldout(cct, 10) << __func__ << " 0x" << std::hex << offset << "~" << length << std::dec << dendl; - btree_interval_set rm; + interval_set_t rm; rm.insert(offset, length); for (unsigned i = 0; i < free.size() && !rm.empty(); ++i) { - btree_interval_set overlap; + interval_set_t overlap; overlap.intersection_of(rm, free[i]); if (!overlap.empty()) { ldout(cct, 20) << __func__ << " bin " << i << " rm 0x" << std::hex << overlap diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index c8e6b28120f39..ccf0f0ec14b60 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -7,7 +7,8 @@ #include #include "Allocator.h" -#include "include/btree_interval_set.h" +#include "include/btree_map.h" +#include "include/interval_set.h" #include "os/bluestore/bluestore_types.h" #include "include/mempool.h" @@ -19,8 +20,10 @@ class StupidAllocator : public Allocator { int64_t num_reserved; ///< reserved bytes typedef mempool::bluestore_alloc::pool_allocator< - pair> allocator; - std::vector> free; ///< leading-edge copy + pair> allocator_t; + typedef btree::btree_map,allocator_t> interval_set_map_t; + typedef interval_set interval_set_t; + std::vector free; ///< leading-edge copy uint64_t last_alloc; @@ -28,7 +31,7 @@ class StupidAllocator : public Allocator { void _insert_free(uint64_t offset, uint64_t len); uint64_t _aligned_len( - btree_interval_set::iterator p, + interval_set_t::iterator p, uint64_t alloc_unit); public: diff --git a/src/test/common/test_interval_set.cc b/src/test/common/test_interval_set.cc index ca723125610df..7a85588bbbc66 100644 --- a/src/test/common/test_interval_set.cc +++ b/src/test/common/test_interval_set.cc @@ -16,7 +16,7 @@ #include #include "include/interval_set.h" -#include "include/btree_interval_set.h" +#include "include/btree_map.h" using namespace ceph; @@ -29,7 +29,11 @@ class IntervalSetTest : public ::testing::Test { typedef T ISet; }; -typedef ::testing::Types< interval_set , btree_interval_set > IntervalSetTypes; +typedef ::testing::Types< + interval_set, + interval_set> + > IntervalSetTypes; TYPED_TEST_CASE(IntervalSetTest, IntervalSetTypes); -- 2.39.5