[thin_check] cleanup: use metadata_counter

This commit is contained in:
Ming-Hung Tsai 2016-04-02 23:24:24 +08:00
parent c8aabf2948
commit f20e2a0f40

View File

@ -31,6 +31,7 @@
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
#include "thin-provisioning/device_tree.h" #include "thin-provisioning/device_tree.h"
#include "thin-provisioning/mapping_tree.h" #include "thin-provisioning/mapping_tree.h"
#include "thin-provisioning/metadata_counter.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "thin-provisioning/commands.h" #include "thin-provisioning/commands.h"
@ -169,58 +170,13 @@ namespace {
bool clear_needs_check_flag_on_success; bool clear_needs_check_flag_on_success;
}; };
void count_trees(transaction_manager::ptr tm,
superblock_detail::superblock &sb,
block_counter &bc) {
// Count the device tree
{
noop_value_counter<device_tree_detail::device_details> vc;
device_tree dtree(*tm, sb.device_details_root_,
device_tree_detail::device_details_traits::ref_counter());
count_btree_blocks(dtree, bc, vc);
}
// Count the mapping tree
{
noop_value_counter<mapping_tree_detail::block_time> vc;
mapping_tree mtree(*tm, sb.data_mapping_root_,
mapping_tree_detail::block_traits::ref_counter(tm->get_sm()));
count_btree_blocks(mtree, bc, vc);
}
}
error_state check_space_map_counts(flags const &fs, nested_output &out, error_state check_space_map_counts(flags const &fs, nested_output &out,
superblock_detail::superblock &sb, superblock_detail::superblock &sb,
block_manager<>::ptr bm, block_manager<>::ptr bm,
transaction_manager::ptr tm) { transaction_manager::ptr tm) {
block_counter bc; block_counter bc;
// Count the superblock count_metadata(tm, sb, bc);
bc.inc(superblock_detail::SUPERBLOCK_LOCATION);
count_trees(tm, sb, bc);
// Count the metadata snap, if present
if (sb.metadata_snap_ != superblock_detail::SUPERBLOCK_LOCATION) {
bc.inc(sb.metadata_snap_);
superblock_detail::superblock snap = read_superblock(bm, sb.metadata_snap_);
count_trees(tm, snap, bc);
}
// Count the metadata space map
{
persistent_space_map::ptr metadata_sm =
open_metadata_sm(*tm, static_cast<void *>(&sb.metadata_space_map_root_));
metadata_sm->count_metadata(bc);
}
// Count the data space map
{
persistent_space_map::ptr data_sm =
open_disk_sm(*tm, static_cast<void *>(&sb.data_space_map_root_));
data_sm->count_metadata(bc);
}
// Finally we need to check the metadata space map agrees // Finally we need to check the metadata space map agrees
// with the counts we've just calculated. // with the counts we've just calculated.