dump the metadata snap block in the superblock detail

This commit is contained in:
Joe Thornber 2012-05-17 13:03:10 +01:00
parent 9e00ab07b8
commit e25c211591
7 changed files with 49 additions and 23 deletions

View File

@ -20,6 +20,7 @@
#define EMITTER_H
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <string>
#include <stdint.h>
@ -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<uint64_t> metadata_snap) = 0;
virtual void end_superblock() = 0;
virtual void begin_device(uint32_t dev_id,

View File

@ -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<uint64_t> 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() {

View File

@ -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<uint64_t> 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);
}

View File

@ -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 <held_root>" << endl;
cerr << "couldn't parse <metadata_snap>" << 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);
}

View File

@ -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

View File

@ -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);

View File

@ -19,6 +19,7 @@
#include "xml_format.h"
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <expat.h>
#include <iostream>
#include <map>
@ -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<uint64_t> metadata_snap) {
indent();
out_ << "<superblock uuid=\"" << uuid << "\""
<< " time=\"" << time << "\""
<< " transaction=\"" << trans_id << "\""
<< " data_block_size=\"" << data_block_size << "\""
<< " nr_data_blocks=\"" << nr_data_blocks << "\">"
<< " 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<T>(it->second);
}
template <typename T>
optional<T> get_opt_attr(attributes const &attr, string const &key) {
typedef optional<T> rtype;
attributes::const_iterator it = attr.find(key);
if (it == attr.end())
return rtype();
return rtype(lexical_cast<T>(it->second));
}
void parse_superblock(emitter *e, attributes const &attr) {
e->begin_superblock(get_attr<string>(attr, "uuid"),
get_attr<uint64_t>(attr, "time"),
get_attr<uint64_t>(attr, "transaction"),
get_attr<uint32_t>(attr, "data_block_size"),
get_attr<uint64_t>(attr, "nr_data_blocks"));
get_attr<uint64_t>(attr, "nr_data_blocks"),
get_opt_attr<uint64_t>(attr, "metadata_snap"));
}
void parse_device(emitter *e, attributes const &attr) {