improve reference count tracking

This commit is contained in:
Joe Thornber 2011-08-25 15:51:40 +01:00
parent 52f03b7542
commit fce7e99d9a
2 changed files with 14 additions and 12 deletions

View File

@ -76,20 +76,24 @@ namespace persistent_data {
void visit_internal(unsigned level, bool is_root, void visit_internal(unsigned level, bool is_root,
btree_detail::node_ref<uint64_traits, BlockSize> const &n) { btree_detail::node_ref<uint64_traits, BlockSize> const &n) {
counter_.inc(n.get_location());
check_duplicate_block(n.get_location()); check_duplicate_block(n.get_location());
check_block_nr(n); check_block_nr(n);
check_max_entries(n); check_max_entries(n);
check_nr_entries(n, is_root); check_nr_entries(n, is_root);
for (unsigned i = 0; i < n.get_nr_entries(); i++)
counter_.inc(n.value_at(i));
} }
void visit_internal_leaf(unsigned level, bool is_root, void visit_internal_leaf(unsigned level, bool is_root,
btree_detail::node_ref<uint64_traits, BlockSize> const &n) { btree_detail::node_ref<uint64_traits, BlockSize> const &n) {
counter_.inc(n.get_location());
check_duplicate_block(n.get_location()); check_duplicate_block(n.get_location());
check_block_nr(n); check_block_nr(n);
check_max_entries(n); check_max_entries(n);
check_nr_entries(n, is_root); check_nr_entries(n, is_root);
for (unsigned i = 0; i < n.get_nr_entries(); i++)
counter_.inc(n.value_at(i));
} }
void visit_leaf(unsigned level, bool is_root, void visit_leaf(unsigned level, bool is_root,

View File

@ -328,22 +328,20 @@ metadata::device_exists(thin_dev_t dev) const
} }
namespace { namespace {
// FIXME: this doesn't check for non-zero counts in the sm that are
// actually zero.
optional<error_set::ptr> optional<error_set::ptr>
check_ref_counts(string const &desc, block_counter const &actual, check_ref_counts(string const &desc, block_counter const &counts,
space_map::ptr sm) { space_map::ptr sm) {
error_set::ptr errors(new error_set(desc)); error_set::ptr errors(new error_set(desc));
bool bad = false; bool bad = false;
block_counter::count_map const &counts = actual.get_counts(); for (block_address b = 0; b < sm->get_nr_blocks(); b++) {
block_counter::count_map::const_iterator it, end = counts.end(); uint32_t actual = sm->get_count(b);
for (it = counts.begin(); it != end; ++it) { uint32_t expected = counts.get_count(b);
uint32_t ref_count = sm->get_count(it->first);
if (ref_count != it->second) { if (actual != expected) {
ostringstream out; ostringstream out;
out << it->first << ": was " << ref_count out << b << ": was " << actual
<< ", expected " << it->second; << ", expected " << expected;
errors->add_child(out.str()); errors->add_child(out.str());
bad = true; bad = true;
} }