superblock damage visitor

This commit is contained in:
Joe Thornber 2013-05-21 14:01:17 +01:00
parent 24ddc4f5c4
commit 6fcda37dbc
4 changed files with 61 additions and 3 deletions

View File

@ -19,7 +19,6 @@
#include "thin-provisioning/device_tree.h" #include "thin-provisioning/device_tree.h"
#include "thin-provisioning/file_utils.h" #include "thin-provisioning/file_utils.h"
#include "thin-provisioning/metadata.h" #include "thin-provisioning/metadata.h"
#include "thin-provisioning/superblock_validator.h"
#include "persistent-data/math_utils.h" #include "persistent-data/math_utils.h"
#include "persistent-data/space-maps/core.h" #include "persistent-data/space-maps/core.h"

View File

@ -19,7 +19,6 @@
#include "thin-provisioning/file_utils.h" #include "thin-provisioning/file_utils.h"
#include "thin-provisioning/metadata.h" #include "thin-provisioning/metadata.h"
#include "thin-provisioning/metadata_checker.h" #include "thin-provisioning/metadata_checker.h"
#include "thin-provisioning/superblock_validator.h"
using namespace persistent_data; using namespace persistent_data;
using namespace thin_provisioning; using namespace thin_provisioning;

View File

@ -1,7 +1,6 @@
#include "persistent-data/checksum.h" #include "persistent-data/checksum.h"
#include "persistent-data/errors.h" #include "persistent-data/errors.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "thin-provisioning/superblock_validator.h"
using namespace thin_provisioning; using namespace thin_provisioning;
using namespace superblock_detail; using namespace superblock_detail;
@ -109,3 +108,36 @@ thin_provisioning::superblock_validator()
} }
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace thin_provisioning {
namespace superblock_detail {
superblock_corruption::superblock_corruption(std::string const &desc)
: desc_(desc) {
}
void
superblock_corruption::visit(damage_visitor &v) const {
v.visit(*this);
}
void
damage_visitor::visit(damage const &d) {
d.visit(*this);
}
}
void
check_superblock(block_manager<>::ptr bm,
superblock_detail::damage_visitor &visitor) {
using namespace superblock_detail;
try {
bm->read_lock(SUPERBLOCK_LOCATION, superblock_validator());
} catch (std::exception const &e) {
visitor.visit(superblock_corruption(e.what()));
}
}
}
//----------------------------------------------------------------

View File

@ -93,9 +93,37 @@ namespace thin_provisioning {
block_address const SUPERBLOCK_LOCATION = 0; block_address const SUPERBLOCK_LOCATION = 0;
uint32_t const SUPERBLOCK_MAGIC = 27022010; uint32_t const SUPERBLOCK_MAGIC = 27022010;
//--------------------------------
class damage_visitor;
struct damage {
virtual ~damage() {}
virtual void visit(damage_visitor &v) const = 0;
};
struct superblock_corruption : public damage {
superblock_corruption(std::string const &desc);
void visit(damage_visitor &v) const;
std::string desc_;
};
class damage_visitor {
public:
virtual ~damage_visitor() {}
void visit(damage const &d);
virtual void visit(superblock_corruption const &d) = 0;
};
} }
block_manager<>::validator::ptr superblock_validator(); block_manager<>::validator::ptr superblock_validator();
void check_superblock(block_manager<>::ptr bm,
superblock_detail::damage_visitor &visitor);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------