]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix few calculations in bit alloc
authorRamesh Chander <Ramesh.Chander@sandisk.com>
Mon, 13 Jun 2016 12:06:39 +0000 (05:06 -0700)
committerRamesh Chander <Ramesh.Chander@sandisk.com>
Tue, 14 Jun 2016 03:33:09 +0000 (20:33 -0700)
Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
src/os/bluestore/BitAllocator.cc
src/os/bluestore/BitMapAllocator.cc

index d0c368e321e5aaaedc3147f8d95ce0e70394c896..2a2f7a1cab910eb039d76cacb6f6dbab41ccc218 100644 (file)
@@ -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);
 }
index 077ff875af5d8bb80d10cd1a97f86b0afb8f6058..bb591f20bef33011c4f2879f6995b87ba22f10af 100644 (file)
@@ -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)