2016-02-27 12:53:06 +05:30
|
|
|
#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;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
namespace {
|
2020-08-11 20:12:32 +05:30
|
|
|
bool count_trees(transaction_manager::ptr tm,
|
2016-06-19 22:10:10 +05:30
|
|
|
superblock_detail::superblock const &sb,
|
2016-06-19 19:35:58 +05:30
|
|
|
block_counter &bc) {
|
2016-02-27 12:53:06 +05:30
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
// 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);
|
|
|
|
}
|
2016-02-27 12:53:06 +05:30
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
// 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(space_map::ptr()));
|
|
|
|
count_btree_blocks(mtree, bc, vc);
|
|
|
|
}
|
2020-08-11 20:12:32 +05:30
|
|
|
|
|
|
|
return true;
|
2016-02-27 12:53:06 +05:30
|
|
|
}
|
|
|
|
|
2020-08-11 20:12:32 +05:30
|
|
|
bool count_space_maps(transaction_manager::ptr tm,
|
2016-06-19 22:10:10 +05:30
|
|
|
superblock_detail::superblock const &sb,
|
2016-06-19 19:35:58 +05:30
|
|
|
block_counter &bc) {
|
2020-08-11 20:12:32 +05:30
|
|
|
bool ret = true;
|
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
// Count the metadata space map (no-throw)
|
|
|
|
try {
|
|
|
|
persistent_space_map::ptr metadata_sm =
|
2016-06-19 22:10:10 +05:30
|
|
|
open_metadata_sm(*tm, static_cast<void const *>(&sb.metadata_space_map_root_));
|
2016-06-19 19:35:58 +05:30
|
|
|
metadata_sm->count_metadata(bc);
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
cerr << e.what() << endl;
|
2020-08-11 20:12:32 +05:30
|
|
|
ret = false;
|
2016-06-19 19:35:58 +05:30
|
|
|
}
|
2016-02-27 12:53:06 +05:30
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
// Count the data space map (no-throw)
|
2020-08-11 20:12:32 +05:30
|
|
|
try {
|
2016-06-19 19:35:58 +05:30
|
|
|
persistent_space_map::ptr data_sm =
|
2016-06-19 22:10:10 +05:30
|
|
|
open_disk_sm(*tm, static_cast<void const *>(&sb.data_space_map_root_));
|
2016-06-19 19:35:58 +05:30
|
|
|
data_sm->count_metadata(bc);
|
2020-08-11 20:12:32 +05:30
|
|
|
} catch (std::exception &e) {
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
ret = false;
|
2016-06-19 19:35:58 +05:30
|
|
|
}
|
2020-08-11 20:12:32 +05:30
|
|
|
|
|
|
|
return ret;
|
2016-02-27 12:53:06 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 19:35:58 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2020-08-11 20:12:32 +05:30
|
|
|
bool thin_provisioning::count_metadata(transaction_manager::ptr tm,
|
2016-06-19 22:10:10 +05:30
|
|
|
superblock_detail::superblock const &sb,
|
2016-02-27 12:53:06 +05:30
|
|
|
block_counter &bc,
|
|
|
|
bool skip_metadata_snap) {
|
2020-08-11 20:12:32 +05:30
|
|
|
bool ret = true;
|
|
|
|
|
2016-02-27 12:53:06 +05:30
|
|
|
// Count the superblock
|
|
|
|
bc.inc(superblock_detail::SUPERBLOCK_LOCATION);
|
2020-08-11 20:12:32 +05:30
|
|
|
ret &= count_trees(tm, sb, bc);
|
2016-02-27 12:53:06 +05:30
|
|
|
|
|
|
|
// 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_);
|
2020-08-11 20:12:32 +05:30
|
|
|
ret &= count_trees(tm, snap, bc);
|
2016-02-27 12:53:06 +05:30
|
|
|
}
|
|
|
|
|
2020-08-11 20:12:32 +05:30
|
|
|
ret &= count_space_maps(tm, sb, bc);
|
|
|
|
|
|
|
|
return ret;
|
2016-02-27 12:53:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|