From 1a8b1b29e8e6fb0c03ea1746e0aecd570aa0fb46 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Mon, 29 Apr 2013 13:24:19 +0100 Subject: [PATCH] Start device_checker --- Makefile.in | 4 +++- thin-provisioning/device_checker.cc | 19 +++++++++++++++++ thin-provisioning/device_checker.h | 22 +++++++++++++++++++ thin-provisioning/metadata_checker.h | 1 + thin-provisioning/superblock_checker.h | 5 ++--- unit-tests/metadata_checker_t.cc | 29 ++++++++++++++++++++++---- 6 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 thin-provisioning/device_checker.cc create mode 100644 thin-provisioning/device_checker.h diff --git a/Makefile.in b/Makefile.in index fcdbfe3..0b2fd7c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -48,6 +48,7 @@ SOURCE=\ \ cache/metadata_disk_structures.cc \ \ + thin-provisioning/device_checker.cc \ thin-provisioning/file_utils.cc \ thin-provisioning/human_readable_format.cc \ thin-provisioning/metadata.cc \ @@ -55,10 +56,11 @@ SOURCE=\ thin-provisioning/metadata_disk_structures.cc \ thin-provisioning/metadata_dumper.cc \ thin-provisioning/restore_emitter.cc \ - thin-provisioning/superblock_validator.cc \ thin-provisioning/superblock_checker.cc \ + thin-provisioning/superblock_validator.cc \ thin-provisioning/thin_pool.cc \ thin-provisioning/xml_format.cc + PDATA_OBJECTS=$(subst .cc,.o,$(SOURCE)) PROGRAM_SOURCE=\ diff --git a/thin-provisioning/device_checker.cc b/thin-provisioning/device_checker.cc new file mode 100644 index 0000000..6521f95 --- /dev/null +++ b/thin-provisioning/device_checker.cc @@ -0,0 +1,19 @@ +#include "thin-provisioning/device_checker.h" + +using namespace thin_provisioning; + +//---------------------------------------------------------------- + +device_checker::device_checker(block_manager::ptr bm) + : bm_(bm) +{ +} + +damage_list_ptr +device_checker::check() +{ + // FIXME: finish. + return damage_list_ptr(new damage_list); +} + +//---------------------------------------------------------------- diff --git a/thin-provisioning/device_checker.h b/thin-provisioning/device_checker.h new file mode 100644 index 0000000..413f49e --- /dev/null +++ b/thin-provisioning/device_checker.h @@ -0,0 +1,22 @@ +#ifndef THIN_DEVICE_CHECKER_H +#define THIN_DEVICE_CHECKER_H + +#include "thin-provisioning/metadata_checker.h" + +//---------------------------------------------------------------- + +namespace thin_provisioning { + class device_checker : public checker { + public: + device_checker(block_manager::ptr bm); + damage_list_ptr check(); + + private: + block_manager::ptr bm_; + damage_list_ptr damage_; + }; +} + +//---------------------------------------------------------------- + +#endif diff --git a/thin-provisioning/metadata_checker.h b/thin-provisioning/metadata_checker.h index e31823e..4c37e1c 100644 --- a/thin-provisioning/metadata_checker.h +++ b/thin-provisioning/metadata_checker.h @@ -153,6 +153,7 @@ namespace thin_provisioning { class checker { public: + typedef persistent_data::block_manager<> block_manager; typedef boost::shared_ptr ptr; virtual ~checker() {}; diff --git a/thin-provisioning/superblock_checker.h b/thin-provisioning/superblock_checker.h index 696f709..bf0253b 100644 --- a/thin-provisioning/superblock_checker.h +++ b/thin-provisioning/superblock_checker.h @@ -8,12 +8,11 @@ namespace thin_provisioning { class superblock_checker : public checker { public: - typedef persistent_data::block_manager<> block_manager; - superblock_checker(block_manager::ptr bm); - boost::shared_ptr check(); + damage_list_ptr check(); private: + // FIXME: surely we can push these down to the base class? block_manager::ptr bm_; damage_list_ptr damage; }; diff --git a/unit-tests/metadata_checker_t.cc b/unit-tests/metadata_checker_t.cc index d2a169c..324fee0 100644 --- a/unit-tests/metadata_checker_t.cc +++ b/unit-tests/metadata_checker_t.cc @@ -3,6 +3,7 @@ #include "test_utils.h" #include "persistent-data/block.h" +#include "thin-provisioning/device_checker.h" #include "thin-provisioning/restore_emitter.h" #include "thin-provisioning/superblock_checker.h" @@ -110,21 +111,34 @@ namespace { block_manager<>::ptr bm_; }; - class SuperBlockCheckerTests : public Test { + //-------------------------------- + + class MetadataCheckerTests : public Test { public: - SuperBlockCheckerTests() + MetadataCheckerTests() : bm_(create_bm()) { metadata_builder builder(bm_); builder.build(); } + with_temp_directory dir_; + block_manager<>::ptr bm_; + + }; + + class SuperBlockCheckerTests : public MetadataCheckerTests { + public: void corrupt_superblock() { zero_block(bm_, SUPERBLOCK_LOCATION); } + }; - with_temp_directory dir_; - block_manager<>::ptr bm_; + //-------------------------------- + + class DevicesCheckerTests : public MetadataCheckerTests { + public: + }; } @@ -155,3 +169,10 @@ TEST_F(SuperBlockCheckerTests, fails_with_bad_checksum) } //---------------------------------------------------------------- + +TEST_F(DevicesCheckerTests, create_require_a_block_manager) +{ + device_checker dc(bm_); +} + +//----------------------------------------------------------------