From: Ramesh Chander Date: Mon, 13 Jun 2016 12:06:39 +0000 (-0700) Subject: os/bluestore: fix few calculations in bit alloc X-Git-Tag: v11.0.0~202^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6a2f04df5f66e231208dc3b5151ae048e950f371;p=ceph.git os/bluestore: fix few calculations in bit alloc Signed-off-by: Ramesh Chander --- diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index d0c368e321e5..2a2f7a1cab91 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 077ff875af5d..bb591f20bef3 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)