[thin_check] --override-mapping-root

This commit is contained in:
Joe Thornber 2017-10-04 11:43:13 +01:00
parent dcb0fe1148
commit 24931b3bda
2 changed files with 24 additions and 2 deletions

View File

@ -33,6 +33,12 @@ OPTIONS
is needed to fix any issues. After thin_repair succeeded, you may run is needed to fix any issues. After thin_repair succeeded, you may run
thin_check again. thin_check again.
--override-mapping-root <block> Specify a mapping root to use.
Don't use this. This overrides what's specified in the superblock. Only
use this if you really understand the metadata format and are trying to
recover damaged metadata.
EXAMPLE EXAMPLE
Analyses thin provisioning metadata on logical volume /dev/vg/metadata: Analyses thin provisioning metadata on logical volume /dev/vg/metadata:

View File

@ -20,6 +20,9 @@
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include "version.h" #include "version.h"
#include "base/application.h" #include "base/application.h"
@ -168,6 +171,7 @@ namespace {
bool ignore_non_fatal_errors; bool ignore_non_fatal_errors;
bool quiet; bool quiet;
boost::optional<block_address> override_mapping_root;
bool clear_needs_check_flag_on_success; bool clear_needs_check_flag_on_success;
}; };
@ -208,6 +212,11 @@ namespace {
out << "This looks like XML. thin_check only checks the binary metadata format." << end_message(); out << "This looks like XML. thin_check only checks the binary metadata format." << end_message();
} }
block_address mapping_root(superblock_detail::superblock const &sb, flags const &fs)
{
return fs.override_mapping_root ? *fs.override_mapping_root : sb.data_mapping_root_;
}
error_state metadata_check(string const &path, flags fs) { error_state metadata_check(string const &path, flags fs) {
nested_output out(cerr, 2); nested_output out(cerr, 2);
if (fs.quiet) if (fs.quiet)
@ -253,7 +262,7 @@ namespace {
out << "examining top level of mapping tree" << end_message(); out << "examining top level of mapping tree" << end_message();
{ {
nested_output::nest _ = out.push(); nested_output::nest _ = out.push();
dev_tree dtree(*tm, sb.data_mapping_root_, dev_tree dtree(*tm, mapping_root(sb, fs),
mapping_tree_detail::mtree_traits::ref_counter(tm)); mapping_tree_detail::mtree_traits::ref_counter(tm));
check_mapping_tree(dtree, mapping_rep); check_mapping_tree(dtree, mapping_rep);
} }
@ -262,7 +271,7 @@ namespace {
out << "examining mapping tree" << end_message(); out << "examining mapping tree" << end_message();
{ {
nested_output::nest _ = out.push(); nested_output::nest _ = out.push();
mapping_tree mtree(*tm, sb.data_mapping_root_, mapping_tree mtree(*tm, mapping_root(sb, fs),
mapping_tree_detail::block_traits::ref_counter(tm->get_sm())); mapping_tree_detail::block_traits::ref_counter(tm->get_sm()));
check_mapping_tree(mtree, mapping_rep); check_mapping_tree(mtree, mapping_rep);
} }
@ -332,6 +341,7 @@ thin_check_cmd::usage(std::ostream &out) const
<< " {-q|--quiet}" << endl << " {-q|--quiet}" << endl
<< " {-h|--help}" << endl << " {-h|--help}" << endl
<< " {-V|--version}" << endl << " {-V|--version}" << endl
<< " {--override-mapping-root}" << endl
<< " {--clear-needs-check-flag}" << endl << " {--clear-needs-check-flag}" << endl
<< " {--ignore-non-fatal-errors}" << endl << " {--ignore-non-fatal-errors}" << endl
<< " {--skip-mappings}" << endl << " {--skip-mappings}" << endl
@ -353,6 +363,7 @@ thin_check_cmd::run(int argc, char **argv)
{ "skip-mappings", no_argument, NULL, 2}, { "skip-mappings", no_argument, NULL, 2},
{ "ignore-non-fatal-errors", no_argument, NULL, 3}, { "ignore-non-fatal-errors", no_argument, NULL, 3},
{ "clear-needs-check-flag", no_argument, NULL, 4 }, { "clear-needs-check-flag", no_argument, NULL, 4 },
{ "override-mapping-root", required_argument, NULL, 5},
{ NULL, no_argument, NULL, 0 } { NULL, no_argument, NULL, 0 }
}; };
@ -392,6 +403,11 @@ thin_check_cmd::run(int argc, char **argv)
fs.clear_needs_check_flag_on_success = true; fs.clear_needs_check_flag_on_success = true;
break; break;
case 5:
// override-mapping-root
fs.override_mapping_root = boost::lexical_cast<uint64_t>(optarg);
break;
default: default:
usage(cerr); usage(cerr);
return 1; return 1;