[thin_check] wire up mapping tree checker

This commit is contained in:
Joe Thornber 2013-05-22 14:55:28 +01:00
parent b456f16aa0
commit 6fe92d4a63
3 changed files with 50 additions and 4 deletions

View File

@ -136,6 +136,7 @@ THIN_CHECK_SOURCE=\
persistent-data/transaction_manager.cc \ persistent-data/transaction_manager.cc \
thin-provisioning/file_utils.cc \ thin-provisioning/file_utils.cc \
thin-provisioning/device_tree.cc \ thin-provisioning/device_tree.cc \
thin-provisioning/mapping_tree.cc \
thin-provisioning/metadata.cc \ thin-provisioning/metadata.cc \
thin-provisioning/metadata_checker.cc \ thin-provisioning/metadata_checker.cc \
thin-provisioning/superblock.cc thin-provisioning/superblock.cc

View File

@ -49,8 +49,12 @@ Feature: thin_check
When I run thin_check with --super-block-only When I run thin_check with --super-block-only
Then it should pass Then it should pass
@announce
Scenario: --super-block-only check fails with corrupt superblock Scenario: --super-block-only check fails with corrupt superblock
Given a corrupt superblock Given a corrupt superblock
When I run thin_check with --super-block-only When I run thin_check with --super-block-only
Then it should fail Then it should fail with:
"""
examining superblock
superblock is corrupt
bad checksum in superblock
"""

View File

@ -198,12 +198,44 @@ namespace {
//-------------------------------- //--------------------------------
class mapping_reporter : public mapping_tree_detail::damage_visitor {
public:
mapping_reporter(nested_output &out)
: out_(out) {
}
virtual void visit(mapping_tree_detail::missing_devices const &d) {
out_ << "missing all mappings for devices: " << d.keys_ << end_message();
{
auto _ = out_.push();
out_ << d.desc_ << end_message();
}
err_ = combine_errors(err_, FATAL);
}
virtual void visit(mapping_tree_detail::missing_mappings const &d) {
out_ << "thin device " << d.thin_dev_ << " is missing mappings " << d.keys_ << end_message();
{
auto _ = out_.push();
out_ << d.desc_ << end_message();
}
err_ = combine_errors(err_, FATAL);
}
private:
nested_output &out_;
error_state err_;
};
//--------------------------------
error_state metadata_check(string const &path) { error_state metadata_check(string const &path) {
block_manager<>::ptr bm = open_bm(path); block_manager<>::ptr bm = open_bm(path);
nested_output out(cerr, 2); nested_output out(cerr, 2);
superblock_reporter sb_rep(out); superblock_reporter sb_rep(out);
devices_reporter dev_rep(out); devices_reporter dev_rep(out);
mapping_reporter mapping_rep(out);
out << "examining superblock" << end_message(); out << "examining superblock" << end_message();
{ {
@ -214,16 +246,25 @@ namespace {
if (sb_rep.get_error() == FATAL) if (sb_rep.get_error() == FATAL)
return FATAL; return FATAL;
superblock_detail::superblock sb = read_superblock(bm);
transaction_manager::ptr tm = open_tm(bm);
out << "examining devices tree" << end_message(); out << "examining devices tree" << end_message();
{ {
auto _ = out.push(); auto _ = out.push();
superblock_detail::superblock sb = read_superblock(bm);
transaction_manager::ptr tm = open_tm(bm);
device_tree dtree(tm, sb.device_details_root_, device_tree dtree(tm, sb.device_details_root_,
device_tree_detail::device_details_traits::ref_counter()); device_tree_detail::device_details_traits::ref_counter());
check_device_tree(dtree, dev_rep); check_device_tree(dtree, dev_rep);
} }
out << "examining mapping tree" << end_message();
{
auto _ = out.push();
mapping_tree mtree(tm, sb.data_mapping_root_,
mapping_tree_detail::block_traits::ref_counter(tm->get_sm()));
check_mapping_tree(mtree, mapping_rep);
}
return combine_errors(sb_rep.get_error(), return combine_errors(sb_rep.get_error(),
dev_rep.get_error()); dev_rep.get_error());
} }