From 80783e77292c4540cb005b855a735fe05c82bbbe Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Sat, 27 Feb 2016 15:23:06 +0800 Subject: [PATCH] Add metadata_counter.{h,cc} --- Makefile.in | 1 + thin-provisioning/metadata_counter.cc | 73 +++++++++++++++++++++++++++ thin-provisioning/metadata_counter.h | 24 +++++++++ 3 files changed, 98 insertions(+) create mode 100644 thin-provisioning/metadata_counter.cc create mode 100644 thin-provisioning/metadata_counter.h diff --git a/Makefile.in b/Makefile.in index 30b0c1a..b515463 100644 --- a/Makefile.in +++ b/Makefile.in @@ -81,6 +81,7 @@ SOURCE=\ thin-provisioning/mapping_tree.cc \ thin-provisioning/metadata.cc \ thin-provisioning/metadata_checker.cc \ + thin-provisioning/metadata_counter.cc \ thin-provisioning/metadata_dumper.cc \ thin-provisioning/restore_emitter.cc \ thin-provisioning/rmap_visitor.cc \ diff --git a/thin-provisioning/metadata_counter.cc b/thin-provisioning/metadata_counter.cc new file mode 100644 index 0000000..bf3f809 --- /dev/null +++ b/thin-provisioning/metadata_counter.cc @@ -0,0 +1,73 @@ +#include "thin-provisioning/metadata_counter.h" +#include "persistent-data/space-maps/core.h" +#include "persistent-data/space-maps/disk_structures.h" + +using namespace persistent_data; +using namespace thin_provisioning; + +//---------------------------------------------------------------- + +void thin_provisioning::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(space_map::ptr())); + count_btree_blocks(mtree, bc, vc); + } +} + +void thin_provisioning::count_space_maps(transaction_manager::ptr tm, + superblock_detail::superblock &sb, + block_counter &bc) { + // Count the metadata space map (no-throw) + try { + persistent_space_map::ptr metadata_sm = + open_metadata_sm(*tm, static_cast(&sb.metadata_space_map_root_)); + metadata_sm->count_metadata(bc); + } catch (std::exception &e) { + cerr << e.what() << endl; + } + + // Count the data space map (no-throw) + try { + persistent_space_map::ptr data_sm = + open_disk_sm(*tm, static_cast(&sb.data_space_map_root_)); + data_sm->count_metadata(bc); + } catch (std::exception &e) { + cerr << e.what() << endl; + } +} + +void thin_provisioning::count_metadata(transaction_manager::ptr tm, + superblock_detail::superblock &sb, + block_counter &bc, + bool skip_metadata_snap) { + // Count the superblock + bc.inc(superblock_detail::SUPERBLOCK_LOCATION); + count_trees(tm, sb, bc); + + // Count the metadata snap, if present + if (!skip_metadata_snap && sb.metadata_snap_ != superblock_detail::SUPERBLOCK_LOCATION) { + bc.inc(sb.metadata_snap_); + + superblock_detail::superblock snap = read_superblock(tm->get_bm(), sb.metadata_snap_); + count_trees(tm, snap, bc); + } + + count_trees(tm, sb, bc); + count_space_maps(tm, sb, bc); +} + +//---------------------------------------------------------------- diff --git a/thin-provisioning/metadata_counter.h b/thin-provisioning/metadata_counter.h new file mode 100644 index 0000000..861d72f --- /dev/null +++ b/thin-provisioning/metadata_counter.h @@ -0,0 +1,24 @@ +#ifndef METADATA_COUNTER_H +#define METADATA_COUNTER_H + +#include "thin-provisioning/metadata.h" +#include "persistent-data/data-structures/btree_counter.h" + +//---------------------------------------------------------------- + +namespace thin_provisioning { + void count_trees(transaction_manager::ptr tm, + superblock_detail::superblock &sb, + block_counter &bc); + void count_space_maps(transaction_manager::ptr tm, + superblock_detail::superblock &sb, + block_counter &bc); + void count_metadata(transaction_manager::ptr tm, + superblock_detail::superblock &sb, + block_counter &bc, + bool skip_metadata_snap = false); +} + +//---------------------------------------------------------------- + +#endif