[caching/metadata_dump] only dump valid hints

This commit is contained in:
Joe Thornber 2013-10-09 10:49:53 +01:00
parent c6487fd283
commit 83f1e4bdd9

View File

@ -1,5 +1,7 @@
#include "caching/metadata_dump.h" #include "caching/metadata_dump.h"
#include <set>
using namespace std; using namespace std;
using namespace caching; using namespace caching;
@ -20,17 +22,26 @@ namespace {
class mapping_emitter : public mapping_visitor { class mapping_emitter : public mapping_visitor {
public: public:
mapping_emitter(emitter::ptr e) mapping_emitter(emitter::ptr e, set<block_address> &valid_blocks)
: e_(e) { : e_(e),
valid_blocks_(valid_blocks) {
} }
void visit(block_address cblock, mapping const &m) { void visit(block_address cblock, mapping const &m) {
if (m.flags_ & M_VALID) if (m.flags_ & M_VALID) {
e_->mapping(cblock, m.oblock_, m.flags_ & M_DIRTY); e_->mapping(cblock, m.oblock_, m.flags_ & M_DIRTY);
mark_valid(cblock);
}
} }
private: private:
void mark_valid(block_address cblock) {
valid_blocks_.insert(cblock);
}
emitter::ptr e_; emitter::ptr e_;
set<block_address> &valid_blocks_;
}; };
struct ignore_mapping_damage : public mapping_array_damage::damage_visitor { struct ignore_mapping_damage : public mapping_array_damage::damage_visitor {
@ -53,16 +64,23 @@ namespace {
class hint_emitter : public hint_visitor { class hint_emitter : public hint_visitor {
public: public:
hint_emitter(emitter::ptr e) hint_emitter(emitter::ptr e, set<block_address> valid_blocks)
: e_(e) { : e_(e),
valid_blocks_(valid_blocks) {
} }
virtual void visit(block_address cblock, std::vector<unsigned char> const &data) { virtual void visit(block_address cblock, std::vector<unsigned char> const &data) {
if (valid(cblock))
e_->hint(cblock, data); e_->hint(cblock, data);
} }
private: private:
bool valid(block_address cblock) const {
return valid_blocks_.find(cblock) != valid_blocks_.end();
}
emitter::ptr e_; emitter::ptr e_;
set<block_address> &valid_blocks_;
}; };
struct ignore_hint_damage : public hint_array_damage::damage_visitor { struct ignore_hint_damage : public hint_array_damage::damage_visitor {
@ -81,6 +99,8 @@ namespace {
void void
caching::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair) caching::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
{ {
set<block_address> valid_blocks;
superblock const &sb = md->sb_; superblock const &sb = md->sb_;
e->begin_superblock(to_string(sb.uuid), sb.data_block_size, e->begin_superblock(to_string(sb.uuid), sb.data_block_size,
sb.cache_blocks, to_string(sb.policy_name), sb.cache_blocks, to_string(sb.policy_name),
@ -90,7 +110,7 @@ caching::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
{ {
namespace mad = mapping_array_damage; namespace mad = mapping_array_damage;
mapping_emitter me(e); mapping_emitter me(e, valid_blocks);
ignore_mapping_damage ignore; ignore_mapping_damage ignore;
fatal_mapping_damage fatal; fatal_mapping_damage fatal;
mad::damage_visitor &dv = repair ? mad::damage_visitor &dv = repair ?
@ -105,7 +125,7 @@ caching::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
{ {
using namespace hint_array_damage; using namespace hint_array_damage;
hint_emitter he(e); hint_emitter he(e, valid_blocks);
ignore_hint_damage ignore; ignore_hint_damage ignore;
fatal_hint_damage fatal; fatal_hint_damage fatal;
damage_visitor &dv = repair ? damage_visitor &dv = repair ?