[cache_check] Now checks discard bitset

This commit is contained in:
Joe Thornber 2013-10-11 10:22:02 +01:00
parent e3d87c5386
commit ea15a329d7
3 changed files with 60 additions and 14 deletions

View File

@ -139,6 +139,24 @@ namespace {
using reporter_base::get_error;
};
class discard_reporter : public bitset_detail::bitset_visitor, reporter_base {
public:
discard_reporter(nested_output &o)
: reporter_base(o) {
}
virtual void visit(uint32_t index, bool value) {
// no op
}
virtual void visit(bitset_detail::missing_bits const &d) {
out() << "missing discard bits " << d.keys_ << end_message();
mplus_error(FATAL);
}
using reporter_base::get_error;
};
//--------------------------------
transaction_manager::ptr open_tm(block_manager<>::ptr bm) {
@ -152,14 +170,16 @@ namespace {
struct flags {
flags()
: check_mappings_(false),
check_hints_(false),
: check_mappings_(true),
check_hints_(true),
check_discards_(true),
ignore_non_fatal_errors_(false),
quiet_(false) {
}
bool check_mappings_;
bool check_hints_;
bool check_discards_;
bool ignore_non_fatal_errors_;
bool quiet_;
};
@ -188,6 +208,7 @@ namespace {
superblock_reporter sb_rep(out);
mapping_reporter mapping_rep(out);
hint_reporter hint_rep(out);
discard_reporter discard_rep(out);
out << "examining superblock" << end_message();
{
@ -211,17 +232,37 @@ namespace {
}
if (fs.check_hints_) {
out << "examining hint array" << end_message();
{
nested_output::nest _ = out.push();
hint_array ha(tm, sb.policy_hint_size, sb.hint_root, sb.cache_blocks);
ha.check(hint_rep);
if (!sb.hint_root)
out << "no hint array present" << end_message();
else {
out << "examining hint array" << end_message();
{
nested_output::nest _ = out.push();
hint_array ha(tm, sb.policy_hint_size, sb.hint_root, sb.cache_blocks);
ha.check(hint_rep);
}
}
}
if (fs.check_discards_) {
if (!sb.discard_root)
out << "no discard bitset present" << end_message();
else {
out << "examining discard bitset" << end_message();
{
nested_output::nest _ = out.push();
bitset discards(tm, sb.discard_root, sb.discard_nr_blocks);
}
}
}
// FIXME: make an error class that's an instance of mplus
return combine_errors(sb_rep.get_error(),
combine_errors(mapping_rep.get_error(),
hint_rep.get_error()));
combine_errors(hint_rep.get_error(),
discard_rep.get_error())));
}
int check(string const &path, flags const &fs) {
@ -255,8 +296,8 @@ namespace {
<< " {-V|--version}" << endl
<< " {--super-block-only}" << endl
<< " {--skip-mappings}" << endl
<< " {--skip-hints}" << endl;
<< " {--skip-hints}" << endl
<< " {--skip-discards}" << endl;
}
char const *TOOLS_VERSION = "0.1.6";
@ -274,6 +315,7 @@ int main(int argc, char **argv)
{ "superblock-only", no_argument, NULL, 1 },
{ "skip-mappings", no_argument, NULL, 2 },
{ "skip-hints", no_argument, NULL, 3 },
{ "skip-discards", no_argument, NULL, 4 },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ NULL, no_argument, NULL, 0 }
@ -294,6 +336,10 @@ int main(int argc, char **argv)
fs.check_hints_ = false;
break;
case 4:
fs.check_discards_ = false;
break;
case 'h':
usage(cout, basename(argv[0]));
return 0;

View File

@ -118,7 +118,7 @@ metadata::open_metadata(block_manager<>::ptr bm)
if (sb_.discard_root)
discard_bits_ = bitset::ptr(
new bitset(tm_, sb_.discard_root, sb_.cache_blocks));
new bitset(tm_, sb_.discard_root, sb_.discard_nr_blocks));
}
void

View File

@ -40,9 +40,9 @@ namespace persistent_data {
public:
typedef boost::shared_ptr<bitset_visitor> ptr;
virtual ~bitset_visitor();
virtual void visit(uint32_t index, bool value);
virtual void visit(missing_bits const &d);
virtual ~bitset_visitor() {}
virtual void visit(uint32_t index, bool value) = 0;
virtual void visit(missing_bits const &d) = 0;
};
}