unittest_bit_alloc race fix

Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Ramesh Chander 2017-01-02 00:01:55 -08:00 committed by Sage Weil
parent 2b2ab914b2
commit 506a06a71e
2 changed files with 8 additions and 1 deletions

View File

@ -827,6 +827,12 @@ int64_t BitMapAreaIN::get_used_blocks()
return m_used_blocks;
}
int64_t BitMapAreaIN::get_used_blocks_adj()
{
std::lock_guard<std::mutex> l(m_blocks_lock);
return m_used_blocks - m_reserved_blocks;
}
bool BitMapAreaIN::reserve_blocks(int64_t num)
{
bool res = false;

View File

@ -416,6 +416,7 @@ public:
virtual void unreserve(int64_t num_blocks, int64_t allocated);
virtual int64_t get_reserved_blocks();
virtual int64_t get_used_blocks();
virtual int64_t get_used_blocks_adj();
virtual int64_t size() {
return m_total_blocks;
}
@ -530,7 +531,7 @@ public:
return m_total_blocks - m_extra_blocks;
}
int64_t get_used_blocks() {
return BitMapAreaIN::get_used_blocks() - (m_extra_blocks + m_reserved_blocks);
return (BitMapAreaIN::get_used_blocks_adj() - m_extra_blocks);
}
BitAllocatorStats *get_stats() {