From f20e2a0f401c1e30c65ff29e76c2af97eb01daf9 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 2 Apr 2016 23:24:24 +0800 Subject: [PATCH] [thin_check] cleanup: use metadata_counter --- thin-provisioning/thin_check.cc | 48 ++------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/thin-provisioning/thin_check.cc b/thin-provisioning/thin_check.cc index 2451db2..f2c57cb 100644 --- a/thin-provisioning/thin_check.cc +++ b/thin-provisioning/thin_check.cc @@ -31,6 +31,7 @@ #include "persistent-data/file_utils.h" #include "thin-provisioning/device_tree.h" #include "thin-provisioning/mapping_tree.h" +#include "thin-provisioning/metadata_counter.h" #include "thin-provisioning/superblock.h" #include "thin-provisioning/commands.h" @@ -169,58 +170,13 @@ namespace { 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 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 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, superblock_detail::superblock &sb, block_manager<>::ptr bm, transaction_manager::ptr tm) { block_counter bc; - // Count the superblock - 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(&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(&sb.data_space_map_root_)); - data_sm->count_metadata(bc); - } + count_metadata(tm, sb, bc); // Finally we need to check the metadata space map agrees // with the counts we've just calculated.