From 6fcda37dbce87c3b654f3939c7b5a949d487c466 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Tue, 21 May 2013 14:01:17 +0100 Subject: [PATCH] superblock damage visitor --- thin-provisioning/metadata.cc | 1 - thin-provisioning/metadata_checker.cc | 1 - thin-provisioning/superblock.cc | 34 ++++++++++++++++++++++++++- thin-provisioning/superblock.h | 28 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/thin-provisioning/metadata.cc b/thin-provisioning/metadata.cc index 0639cc1..08b0773 100644 --- a/thin-provisioning/metadata.cc +++ b/thin-provisioning/metadata.cc @@ -19,7 +19,6 @@ #include "thin-provisioning/device_tree.h" #include "thin-provisioning/file_utils.h" #include "thin-provisioning/metadata.h" -#include "thin-provisioning/superblock_validator.h" #include "persistent-data/math_utils.h" #include "persistent-data/space-maps/core.h" diff --git a/thin-provisioning/metadata_checker.cc b/thin-provisioning/metadata_checker.cc index 548ea2f..ae8a6c9 100644 --- a/thin-provisioning/metadata_checker.cc +++ b/thin-provisioning/metadata_checker.cc @@ -19,7 +19,6 @@ #include "thin-provisioning/file_utils.h" #include "thin-provisioning/metadata.h" #include "thin-provisioning/metadata_checker.h" -#include "thin-provisioning/superblock_validator.h" using namespace persistent_data; using namespace thin_provisioning; diff --git a/thin-provisioning/superblock.cc b/thin-provisioning/superblock.cc index 5c00d8a..96cecac 100644 --- a/thin-provisioning/superblock.cc +++ b/thin-provisioning/superblock.cc @@ -1,7 +1,6 @@ #include "persistent-data/checksum.h" #include "persistent-data/errors.h" #include "thin-provisioning/superblock.h" -#include "thin-provisioning/superblock_validator.h" using namespace thin_provisioning; 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())); + } + } +} + +//---------------------------------------------------------------- diff --git a/thin-provisioning/superblock.h b/thin-provisioning/superblock.h index c71967d..19d8d79 100644 --- a/thin-provisioning/superblock.h +++ b/thin-provisioning/superblock.h @@ -93,9 +93,37 @@ namespace thin_provisioning { block_address const SUPERBLOCK_LOCATION = 0; 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(); + + void check_superblock(block_manager<>::ptr bm, + superblock_detail::damage_visitor &visitor); } //----------------------------------------------------------------