add support for held_root to thin_dump

This commit is contained in:
Joe Thornber 2012-05-17 12:28:23 +01:00
parent ae220c977d
commit 9e00ab07b8
5 changed files with 58 additions and 10 deletions

View File

@ -99,9 +99,9 @@ namespace {
} }
superblock superblock
read_superblock(block_manager<>::ptr bm) { read_superblock(block_manager<>::ptr bm, block_address location = SUPERBLOCK_LOCATION) {
superblock sb; superblock sb;
block_manager<>::read_ref r = bm->read_lock(SUPERBLOCK_LOCATION, block_manager<>::read_ref r = bm->read_lock(location,
mk_validator(new superblock_validator)); mk_validator(new superblock_validator));
superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&r.data()); superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&r.data());
superblock_traits::unpack(*sbd, sb); superblock_traits::unpack(*sbd, sb);
@ -161,6 +161,20 @@ metadata::metadata(std::string const &dev_path, open_type ot,
} }
} }
metadata::metadata(std::string const &dev_path, block_address held_root)
{
tm_ = open_tm(dev_path, false);
sb_ = read_superblock(tm_->get_bm(), held_root);
// We don't open the metadata sm for a held root
//metadata_sm_ = open_metadata_sm(tm_, &sb_.metadata_space_map_root_);
tm_->set_sm(metadata_sm_);
data_sm_ = open_disk_sm(tm_, static_cast<void *>(&sb_.data_space_map_root_));
details_ = detail_tree::ptr(new detail_tree(tm_, sb_.device_details_root_, device_details_traits::ref_counter()));
mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_)));
mappings_ = mapping_tree::ptr(new mapping_tree(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_)));
}
namespace { namespace {
void print_superblock(superblock const &sb) { void print_superblock(superblock const &sb) {
using namespace std; using namespace std;

View File

@ -151,6 +151,8 @@ namespace thin_provisioning {
sector_t data_block_size = 128, sector_t data_block_size = 128,
block_address nr_data_blocks = 0); // Only used if CREATE block_address nr_data_blocks = 0); // Only used if CREATE
metadata(std::string const &dev_path, block_address held_root);
void commit(); void commit();
typedef block_manager<>::read_ref read_ref; typedef block_manager<>::read_ref read_ref;

View File

@ -171,8 +171,22 @@ thin_provisioning::metadata_check(metadata::ptr md)
block_counter metadata_counter, data_counter; block_counter metadata_counter, data_counter;
if (md->sb_.held_root_) if (md->sb_.held_root_) {
metadata_counter.inc(md->sb_.held_root_); block_manager<>::ptr bm = md->tm_->get_bm();
block_address root = md->sb_.held_root_;
metadata_counter.inc(root);
superblock sb;
block_manager<>::read_ref r = bm->read_lock(root);
superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&r.data());
superblock_traits::unpack(*sbd, sb);
metadata_counter.inc(sb.data_mapping_root_);
metadata_counter.inc(sb.device_details_root_);
}
mapping_validator::ptr mv(new mapping_validator(metadata_counter, mapping_validator::ptr mv(new mapping_validator(metadata_counter,
data_counter)); data_counter));

View File

@ -32,7 +32,7 @@ namespace {
mappings_extractor(uint64_t dev_id, emitter::ptr e, mappings_extractor(uint64_t dev_id, emitter::ptr e,
space_map::ptr md_sm, space_map::ptr data_sm) space_map::ptr md_sm, space_map::ptr data_sm)
: counter_(), : counter_(),
checker_(counter_), checker_(counter_, false),
dev_id_(dev_id), dev_id_(dev_id),
e_(e), e_(e),
md_sm_(md_sm), md_sm_(md_sm),

View File

@ -31,9 +31,12 @@ using namespace std;
using namespace thin_provisioning; using namespace thin_provisioning;
namespace { namespace {
int dump(string const &path, string const &format, bool repair) { int dump(string const &path, string const &format, bool repair,
block_address held_root = 0) {
try { try {
metadata::ptr md(new metadata(path, metadata::OPEN)); metadata::ptr md(held_root ?
new metadata(path, held_root) :
new metadata(path, metadata::OPEN));
emitter::ptr e; emitter::ptr e;
if (format == "xml") if (format == "xml")
@ -46,6 +49,7 @@ namespace {
} }
metadata_dump(md, e, repair); metadata_dump(md, e, repair);
} catch (std::exception &e) { } catch (std::exception &e) {
cerr << e.what() << endl; cerr << e.what() << endl;
return 1; return 1;
@ -60,6 +64,7 @@ namespace {
<< " {-h|--help}" << endl << " {-h|--help}" << endl
<< " {-f|--format} {xml|human_readable}" << endl << " {-f|--format} {xml|human_readable}" << endl
<< " {-r|--repair}" << endl << " {-r|--repair}" << endl
<< " {-s|--held-superblock}" << endl
<< " {-V|--version}" << endl; << " {-V|--version}" << endl;
} }
} }
@ -68,10 +73,14 @@ int main(int argc, char **argv)
{ {
int c; int c;
bool repair = false; bool repair = false;
const char shortopts[] = "hf:rV"; const char shortopts[] = "hs:f:rV";
string format = "xml"; string format = "xml";
block_address held_root = 0;
char *end_ptr;
const struct option longopts[] = { const struct option longopts[] = {
{ "help", no_argument, NULL, 'h'}, { "help", no_argument, NULL, 'h'},
{ "held-root", required_argument, NULL, 's' },
{ "format", required_argument, NULL, 'f' }, { "format", required_argument, NULL, 'f' },
{ "repair", no_argument, NULL, 'r'}, { "repair", no_argument, NULL, 'r'},
{ "version", no_argument, NULL, 'V'}, { "version", no_argument, NULL, 'V'},
@ -92,8 +101,17 @@ int main(int argc, char **argv)
repair = true; repair = true;
break; break;
case 's':
held_root = strtoull(optarg, &end_ptr, 10);
if (end_ptr == optarg) {
cerr << "couldn't parse <held_root>" << endl;
usage(cerr, basename(argv[0]));
return 1;
}
break;
case 'V': case 'V':
cout << THIN_PROVISIONING_TOOLS_VERSION << endl; cerr << THIN_PROVISIONING_TOOLS_VERSION << endl;
return 0; return 0;
default: default:
@ -108,5 +126,5 @@ int main(int argc, char **argv)
return 1; return 1;
} }
return dump(argv[optind], format, repair); return dump(argv[optind], format, repair, held_root);
} }