From 6a2f04df5f66e231208dc3b5151ae048e950f371 Mon Sep 17 00:00:00 2001 From: Ramesh Chander Date: Mon, 13 Jun 2016 05:06:39 -0700 Subject: [PATCH] os/bluestore: fix few calculations in bit alloc Signed-off-by: Ramesh Chander --- src/os/bluestore/BitAllocator.cc | 8 +++----- src/os/bluestore/BitMapAllocator.cc | 13 +++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index d0c368e321e..2a2f7a1cab9 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -842,7 +842,7 @@ bool BitMapAreaIN::is_allocated(int64_t start_block, int64_t num_blocks) area = (BitMapArea *) m_child_list->get_nth_item( start_block / m_child_size_blocks); - area_block_offset = start_block % area->size(); + area_block_offset = start_block % m_child_size_blocks; falling_in_area = MIN(m_child_size_blocks - area_block_offset, num_blocks); if (!area->is_allocated(area_block_offset, falling_in_area)) { @@ -1214,15 +1214,13 @@ BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_a } BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block, - bmap_alloc_mode_t mode, bool def): - BitMapAreaIN(total_blocks, zone_size_block, def) + bmap_alloc_mode_t mode, bool def) { init_check(total_blocks, zone_size_block, mode, def, false); } BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block, - bmap_alloc_mode_t mode, bool def, bool stats_on): - BitMapAreaIN(total_blocks, zone_size_block, def) + bmap_alloc_mode_t mode, bool def, bool stats_on) { init_check(total_blocks, zone_size_block, mode, def, stats_on); } diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index 077ff875af5..bb591f20bef 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -158,9 +158,18 @@ void BitMapAllocator::init_add_free(uint64_t offset, uint64_t length) { dout(10) << __func__ <<" instance "<< (uint64_t) this << " offset " << offset << " length " << length << dendl; + uint64_t size = m_bit_alloc->size() * m_block_size; - insert_free(ROUND_UP_TO(offset, m_block_size), - (length / m_block_size) * m_block_size); + uint64_t offset_adj = ROUND_UP_TO(offset, m_block_size); + uint64_t length_adj = ((length - (offset_adj - offset)) / + m_block_size) * m_block_size; + + if ((offset_adj + length_adj) > size) { + assert(((offset_adj + length_adj) - m_block_size) < size); + length_adj = size - offset_adj; + } + + insert_free(offset_adj, length_adj); } void BitMapAllocator::init_rm_free(uint64_t offset, uint64_t length) -- 2.47.3