diff --git a/man8/thin_dump.8 b/man8/thin_dump.8 index 697df83..07da225 100644 --- a/man8/thin_dump.8 +++ b/man8/thin_dump.8 @@ -22,6 +22,9 @@ Print output in XML or human readable format. .IP "\fB\-r, \-\-repair\fP". +.IP "\fB\-m, \-\-metadata_snap\fP block#". +Dump metadata snapshot at block# + .IP "\fB\-h, \-\-help\fP". Print help and exit. diff --git a/thin-provisioning/metadata.cc b/thin-provisioning/metadata.cc index c841614..771325a 100644 --- a/thin-provisioning/metadata.cc +++ b/thin-provisioning/metadata.cc @@ -57,15 +57,6 @@ namespace { return tm; } - superblock - read_superblock(block_manager<>::ptr bm, block_address location = SUPERBLOCK_LOCATION) { - superblock sb; - block_manager<>::read_ref r = bm->read_lock(location, superblock_validator()); - superblock_disk const *sbd = reinterpret_cast(&r.data()); - superblock_traits::unpack(*sbd, sb); - return sb; - } - void copy_space_maps(space_map::ptr lhs, space_map::ptr rhs) { for (block_address b = 0; b < rhs->get_nr_blocks(); b++) { @@ -149,10 +140,10 @@ metadata::metadata(std::string const &dev_path, open_type ot, } } -metadata::metadata(std::string const &dev_path) +metadata::metadata(std::string const &dev_path, block_address metadata_snap) { tm_ = open_tm(open_bm(dev_path, false)); - sb_ = read_superblock(tm_->get_bm()); + sb_ = read_superblock(tm_->get_bm(), metadata_snap); // We don't open the metadata sm for a held root //metadata_sm_ = open_metadata_sm(tm_, &sb_.metadata_space_map_root_); diff --git a/thin-provisioning/metadata.h b/thin-provisioning/metadata.h index 250c216..9749acb 100644 --- a/thin-provisioning/metadata.h +++ b/thin-provisioning/metadata.h @@ -62,10 +62,11 @@ namespace thin_provisioning { // Deprecated: it would be better if we passed in an already // constructed block_manager. metadata(std::string const &dev_path, open_type ot, - sector_t data_block_size = 128, + sector_t data_block_size = 128, // Only used if CREATE block_address nr_data_blocks = 0); // Only used if CREATE - metadata(std::string const &dev_path); + metadata(std::string const &dev_path, + block_address metadata_snap = 0); // ... use these instead ... metadata(block_manager<>::ptr bm, open_type ot, diff --git a/thin-provisioning/superblock.cc b/thin-provisioning/superblock.cc index c23fbc1..bf9544b 100644 --- a/thin-provisioning/superblock.cc +++ b/thin-provisioning/superblock.cc @@ -126,17 +126,22 @@ namespace thin_provisioning { } } - superblock_detail::superblock read_superblock(block_manager<>::ptr bm) + superblock_detail::superblock read_superblock(block_manager<>::ptr bm, block_address location) { using namespace superblock_detail; superblock sb; - auto r = bm->read_lock(SUPERBLOCK_LOCATION, superblock_validator()); + auto r = bm->read_lock(location, superblock_validator()); superblock_disk const *sbd = reinterpret_cast(&r.data()); superblock_traits::unpack(*sbd, sb); return sb; } + superblock_detail::superblock read_superblock(block_manager<>::ptr bm) + { + return read_superblock(bm, SUPERBLOCK_LOCATION); + } + void check_superblock(block_manager<>::ptr bm, superblock_detail::damage_visitor &visitor) { diff --git a/thin-provisioning/superblock.h b/thin-provisioning/superblock.h index e993497..a9377b0 100644 --- a/thin-provisioning/superblock.h +++ b/thin-provisioning/superblock.h @@ -123,6 +123,7 @@ namespace thin_provisioning { persistent_data::block_manager<>::validator::ptr superblock_validator(); superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm); + superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm, persistent_data::block_address location); void check_superblock(persistent_data::block_manager<>::ptr bm, superblock_detail::damage_visitor &visitor); } diff --git a/thin-provisioning/thin_dump.cc b/thin-provisioning/thin_dump.cc index a4bcf66..029a635 100644 --- a/thin-provisioning/thin_dump.cc +++ b/thin-provisioning/thin_dump.cc @@ -35,7 +35,7 @@ namespace { int dump(string const &path, ostream &out, string const &format, bool repair, block_address metadata_snap = 0) { try { - metadata::ptr md(new metadata(path, metadata::OPEN)); + metadata::ptr md(metadata_snap ? new metadata(path, metadata_snap) : new metadata(path, metadata::OPEN, 0, 0)); emitter::ptr e; if (format == "xml") @@ -63,7 +63,7 @@ namespace { << " {-h|--help}" << endl << " {-f|--format} {xml|human_readable}" << endl << " {-r|--repair}" << endl - << " {-m|--metadata-snap}" << endl + << " {-m|--metadata-snap} block#" << endl << " {-o }" << endl << " {-V|--version}" << endl; } diff --git a/thin-provisioning/thin_metadata_size.c b/thin-provisioning/thin_metadata_size.c index e5952fe..51e9454 100755 --- a/thin-provisioning/thin_metadata_size.c +++ b/thin-provisioning/thin_metadata_size.c @@ -3,7 +3,6 @@ * * This file is released under the GPL * - * * Calculates device-mapper thin privisioning * metadata device size based on pool, block size and * maximum expected thin provisioned devices and snapshots.