diff --git a/Makefile.in b/Makefile.in index 2822626..e8398e9 100644 --- a/Makefile.in +++ b/Makefile.in @@ -57,7 +57,6 @@ SOURCE=\ thin-provisioning/metadata_dumper.cc \ thin-provisioning/restore_emitter.cc \ thin-provisioning/superblock.cc \ - thin-provisioning/superblock_validator.cc \ thin-provisioning/thin_pool.cc \ thin-provisioning/xml_format.cc @@ -138,8 +137,7 @@ THIN_CHECK_SOURCE=\ thin-provisioning/file_utils.cc \ thin-provisioning/metadata.cc \ thin-provisioning/metadata_checker.cc \ - thin-provisioning/superblock.cc \ - thin-provisioning/superblock_validator.cc + thin-provisioning/superblock.cc THIN_DEBUG_OBJECTS=$(subst .cc,.o,$(THIN_DEBUG_SOURCE)) THIN_DUMP_OBJECTS=$(subst .cc,.o,$(THIN_DUMP_SOURCE)) diff --git a/thin-provisioning/superblock.cc b/thin-provisioning/superblock.cc index c9c9751..5c00d8a 100644 --- a/thin-provisioning/superblock.cc +++ b/thin-provisioning/superblock.cc @@ -1,3 +1,5 @@ +#include "persistent-data/checksum.h" +#include "persistent-data/errors.h" #include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock_validator.h" @@ -74,39 +76,36 @@ superblock_traits::pack(superblock const &value, superblock_disk &disk) //---------------------------------------------------------------- +namespace { + using namespace persistent_data; + using namespace superblock_detail; -#if 0 -superblock_checker::superblock_checker(block_manager::ptr bm) - : checker(bm) -{ + uint32_t const VERSION = 1; + unsigned const SECTOR_TO_BLOCK_SHIFT = 3; + uint32_t const SUPERBLOCK_CSUM_SEED = 160774; + + struct sb_validator : public block_manager<>::validator { + virtual void check(buffer<> const &b, block_address location) const { + superblock_disk const *sbd = reinterpret_cast(&b); + crc32c sum(SUPERBLOCK_CSUM_SEED); + sum.append(&sbd->flags_, MD_BLOCK_SIZE - sizeof(uint32_t)); + if (sum.get_sum() != to_cpu(sbd->csum_)) + throw checksum_error("bad checksum in superblock"); + } + + virtual void prepare(buffer<> &b, block_address location) const { + superblock_disk *sbd = reinterpret_cast(&b); + crc32c sum(SUPERBLOCK_CSUM_SEED); + sum.append(&sbd->flags_, MD_BLOCK_SIZE - sizeof(uint32_t)); + sbd->csum_ = to_disk(sum.get_sum()); + } + }; } -// FIXME: Other things to check: -// - magic -// - version -// - 3 * flags (should be zero) -// - in bounds: metadata_snap, data_mapping_root -// - metadata_nr_blocks_ matches what we've been given. -damage_list_ptr -superblock_checker::check() +block_manager<>::validator::ptr +thin_provisioning::superblock_validator() { - superblock sb; - - damage_list_ptr damage(new damage_list); - - try { - block_manager::read_ref r = bm_->read_lock(SUPERBLOCK_LOCATION, superblock_validator()); - superblock_disk const *sbd = reinterpret_cast(&r.data()); - superblock_traits::unpack(*sbd, sb); - - } catch (checksum_error const &e) { - metadata_damage::ptr err(new super_block_corruption); - err->set_message("checksum error"); - damage->push_back(err); - } - - return damage; + return block_manager<>::validator::ptr(new sb_validator); } //---------------------------------------------------------------- -#endif diff --git a/thin-provisioning/superblock.h b/thin-provisioning/superblock.h index ce69ef6..c71967d 100644 --- a/thin-provisioning/superblock.h +++ b/thin-provisioning/superblock.h @@ -92,15 +92,10 @@ namespace thin_provisioning { }; block_address const SUPERBLOCK_LOCATION = 0; + uint32_t const SUPERBLOCK_MAGIC = 27022010; } -#if 0 - class superblock_checker : public checker { - public: - superblock_checker(block_manager::ptr bm); - damage_list_ptr check(); - }; -#endif + block_manager<>::validator::ptr superblock_validator(); } //---------------------------------------------------------------- diff --git a/thin-provisioning/superblock_validator.cc b/thin-provisioning/superblock_validator.cc deleted file mode 100644 index 1f5b561..0000000 --- a/thin-provisioning/superblock_validator.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include "persistent-data/checksum.h" -#include "persistent-data/errors.h" - -#include "thin-provisioning/superblock_validator.h" -#include "thin-provisioning/superblock.h" - -using namespace thin_provisioning; - -//---------------------------------------------------------------- - -namespace { - using namespace persistent_data; - using namespace superblock_detail; - - uint32_t const VERSION = 1; - unsigned const SECTOR_TO_BLOCK_SHIFT = 3; - uint32_t const SUPERBLOCK_CSUM_SEED = 160774; - - struct sb_validator : public block_manager<>::validator { - virtual void check(buffer<> const &b, block_address location) const { - superblock_disk const *sbd = reinterpret_cast(&b); - crc32c sum(SUPERBLOCK_CSUM_SEED); - sum.append(&sbd->flags_, MD_BLOCK_SIZE - sizeof(uint32_t)); - if (sum.get_sum() != to_cpu(sbd->csum_)) - throw checksum_error("bad checksum in superblock"); - } - - virtual void prepare(buffer<> &b, block_address location) const { - superblock_disk *sbd = reinterpret_cast(&b); - crc32c sum(SUPERBLOCK_CSUM_SEED); - sum.append(&sbd->flags_, MD_BLOCK_SIZE - sizeof(uint32_t)); - sbd->csum_ = to_disk(sum.get_sum()); - } - }; -} - -//---------------------------------------------------------------- - -block_manager<>::validator::ptr -thin_provisioning::superblock_validator() -{ - return block_manager<>::validator::ptr(new sb_validator); -} - -//---------------------------------------------------------------- diff --git a/thin-provisioning/superblock_validator.h b/thin-provisioning/superblock_validator.h deleted file mode 100644 index 0b40dc6..0000000 --- a/thin-provisioning/superblock_validator.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef THIN_SUPERBLOCK_VALIDATOR_H -#define THIN_SUPERBLOCK_VALIDATOR_H - -#include "persistent-data/block.h" - -//---------------------------------------------------------------- - -namespace thin_provisioning { - // FIXME: put with metadata disk structures? - uint32_t const SUPERBLOCK_MAGIC = 27022010; - - block_manager<>::validator::ptr superblock_validator(); -} - -//---------------------------------------------------------------- - -#endif