diff --git a/src/blockstore_impl.h b/src/blockstore_impl.h index ba79e16a..e20e956c 100644 --- a/src/blockstore_impl.h +++ b/src/blockstore_impl.h @@ -277,6 +277,7 @@ class blockstore_impl_t int unsynced_big_write_count = 0, unstable_unsynced = 0; int unsynced_queued_ops = 0; allocator *data_alloc = NULL; + uint64_t used_blocks = 0; uint8_t *zero_object; void *metadata_buffer = NULL; @@ -430,7 +431,7 @@ public: inline uint32_t get_block_size() { return dsk.data_block_size; } inline uint64_t get_block_count() { return dsk.block_count; } - inline uint64_t get_free_block_count() { return data_alloc->get_free_count(); } + inline uint64_t get_free_block_count() { return dsk.block_count - used_blocks; } inline uint32_t get_bitmap_granularity() { return dsk.disk_alignment; } inline uint64_t get_journal_size() { return dsk.journal_len; } }; diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index c958edb3..f0464d9a 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -376,6 +376,7 @@ bool blockstore_init_meta::handle_meta_block(uint8_t *buf, uint64_t entries_per_ else { bs->inode_space_stats[entry->oid.inode] += bs->dsk.data_block_size; + bs->used_blocks++; } entries_loaded++; #ifdef BLOCKSTORE_DEBUG @@ -1181,6 +1182,7 @@ void blockstore_init_journal::erase_dirty_object(blockstore_dirty_db_t::iterator sp -= bs->dsk.data_block_size; else bs->inode_space_stats.erase(oid.inode); + bs->used_blocks--; } bs->erase_dirty(dirty_it, dirty_end, clean_loc); // Remove it from the flusher's queue, too diff --git a/src/blockstore_stable.cpp b/src/blockstore_stable.cpp index aa857f9a..10648ad9 100644 --- a/src/blockstore_stable.cpp +++ b/src/blockstore_stable.cpp @@ -445,6 +445,7 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty) if (!exists) { inode_space_stats[dirty_it->first.oid.inode] += dsk.data_block_size; + used_blocks++; } big_to_flush++; } @@ -455,6 +456,7 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty) sp -= dsk.data_block_size; else inode_space_stats.erase(dirty_it->first.oid.inode); + used_blocks--; big_to_flush++; } }