From e25c2115913ad0dbb5ba2ca94da53f1db3c6ca06 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 17 May 2012 13:03:10 +0100 Subject: [PATCH] dump the metadata snap block in the superblock detail --- emitter.h | 4 +++- human_readable_format.cc | 10 +++++++--- restore_emitter.cc | 4 +++- thin_dump.cc | 24 ++++++++++++------------ thin_pool.cc | 4 ++-- thin_pool.h | 2 +- xml_format.cc | 24 +++++++++++++++++++++--- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/emitter.h b/emitter.h index 8409cfb..c7dc1e3 100644 --- a/emitter.h +++ b/emitter.h @@ -20,6 +20,7 @@ #define EMITTER_H #include +#include #include #include @@ -48,7 +49,8 @@ namespace thin_provisioning { uint64_t time, uint64_t trans_id, uint32_t data_block_size, - uint64_t nr_data_blocks) = 0; + uint64_t nr_data_blocks, + boost::optional metadata_snap) = 0; virtual void end_superblock() = 0; virtual void begin_device(uint32_t dev_id, diff --git a/human_readable_format.cc b/human_readable_format.cc index f30f50c..0726aa9 100644 --- a/human_readable_format.cc +++ b/human_readable_format.cc @@ -36,13 +36,17 @@ namespace { uint64_t time, uint64_t trans_id, uint32_t data_block_size, - uint64_t nr_data_blocks) { + uint64_t nr_data_blocks, + boost::optional metadata_snap) { out_ << "begin superblock: \"" << uuid << "\"" << ", " << time << ", " << trans_id << ", " << data_block_size - << ", " << nr_data_blocks - << endl; + << ", " << nr_data_blocks; + if (metadata_snap) + out_ << ", " << metadata_snap; + + out_ << endl; } void end_superblock() { diff --git a/restore_emitter.cc b/restore_emitter.cc index d8dbaae..b471578 100644 --- a/restore_emitter.cc +++ b/restore_emitter.cc @@ -39,7 +39,8 @@ namespace { uint64_t time, uint64_t trans_id, uint32_t data_block_size, - uint64_t nr_data_blocks) { + uint64_t nr_data_blocks, + optional metadata_snap) { in_superblock_ = true; superblock &sb = md_->sb_; @@ -47,6 +48,7 @@ namespace { sb.time_ = time; sb.trans_id_ = trans_id; sb.data_block_size_ = data_block_size; + sb.metadata_snap_ = metadata_snap ? *metadata_snap : 0; md_->data_sm_->extend(nr_data_blocks); } diff --git a/thin_dump.cc b/thin_dump.cc index 4a85432..8c656c2 100644 --- a/thin_dump.cc +++ b/thin_dump.cc @@ -32,10 +32,10 @@ using namespace thin_provisioning; namespace { int dump(string const &path, string const &format, bool repair, - block_address held_root = 0) { + block_address metadata_snap = 0) { try { - metadata::ptr md(held_root ? - new metadata(path, held_root) : + metadata::ptr md(metadata_snap ? + new metadata(path, metadata_snap) : new metadata(path, metadata::OPEN)); emitter::ptr e; @@ -64,7 +64,7 @@ namespace { << " {-h|--help}" << endl << " {-f|--format} {xml|human_readable}" << endl << " {-r|--repair}" << endl - << " {-s|--held-superblock}" << endl + << " {-m|--metadata-snap}" << endl << " {-V|--version}" << endl; } } @@ -73,14 +73,14 @@ int main(int argc, char **argv) { int c; bool repair = false; - const char shortopts[] = "hs:f:rV"; + const char shortopts[] = "hm:f:rV"; string format = "xml"; - block_address held_root = 0; + block_address metadata_snap = 0; char *end_ptr; const struct option longopts[] = { { "help", no_argument, NULL, 'h'}, - { "held-root", required_argument, NULL, 's' }, + { "metadata-snap", required_argument, NULL, 'm' }, { "format", required_argument, NULL, 'f' }, { "repair", no_argument, NULL, 'r'}, { "version", no_argument, NULL, 'V'}, @@ -101,17 +101,17 @@ int main(int argc, char **argv) repair = true; break; - case 's': - held_root = strtoull(optarg, &end_ptr, 10); + case 'm': + metadata_snap = strtoull(optarg, &end_ptr, 10); if (end_ptr == optarg) { - cerr << "couldn't parse " << endl; + cerr << "couldn't parse " << endl; usage(cerr, basename(argv[0])); return 1; } break; case 'V': - cerr << THIN_PROVISIONING_TOOLS_VERSION << endl; + cout << THIN_PROVISIONING_TOOLS_VERSION << endl; return 0; default: @@ -126,5 +126,5 @@ int main(int argc, char **argv) return 1; } - return dump(argv[optind], format, repair, held_root); + return dump(argv[optind], format, repair, metadata_snap); } diff --git a/thin_pool.cc b/thin_pool.cc index c91ab3c..eb7f9c5 100644 --- a/thin_pool.cc +++ b/thin_pool.cc @@ -177,9 +177,9 @@ thin_pool::get_transaction_id() const } block_address -thin_pool::get_held_root() const +thin_pool::get_metadata_snap() const { - return md_->sb_.held_root_; + return md_->sb_.metadata_snap_; } block_address diff --git a/thin_pool.h b/thin_pool.h index d2e2bc7..f5bb588 100644 --- a/thin_pool.h +++ b/thin_pool.h @@ -69,7 +69,7 @@ namespace thin_provisioning { void set_transaction_id(uint64_t id); uint64_t get_transaction_id() const; - block_address get_held_root() const; + block_address get_metadata_snap() const; block_address alloc_data_block(); void free_data_block(block_address b); diff --git a/xml_format.cc b/xml_format.cc index 5e5004d..86f5a35 100644 --- a/xml_format.cc +++ b/xml_format.cc @@ -19,6 +19,7 @@ #include "xml_format.h" #include +#include #include #include #include @@ -49,13 +50,19 @@ namespace { uint64_t time, uint64_t trans_id, uint32_t data_block_size, - uint64_t nr_data_blocks) { + uint64_t nr_data_blocks, + optional metadata_snap) { indent(); out_ << "" + << " nr_data_blocks=\"" << nr_data_blocks; + + if (metadata_snap) + out_ << " metadata_snap=\"" << *metadata_snap; + + out_ << "\">" << endl; inc(); } @@ -174,12 +181,23 @@ namespace { return lexical_cast(it->second); } + template + optional get_opt_attr(attributes const &attr, string const &key) { + typedef optional rtype; + attributes::const_iterator it = attr.find(key); + if (it == attr.end()) + return rtype(); + + return rtype(lexical_cast(it->second)); + } + void parse_superblock(emitter *e, attributes const &attr) { e->begin_superblock(get_attr(attr, "uuid"), get_attr(attr, "time"), get_attr(attr, "transaction"), get_attr(attr, "data_block_size"), - get_attr(attr, "nr_data_blocks")); + get_attr(attr, "nr_data_blocks"), + get_opt_attr(attr, "metadata_snap")); } void parse_device(emitter *e, attributes const &attr) {