[thin_dump] --dev-id
This commit is contained in:
parent
8b2ec7a3aa
commit
a3f4940f1e
@ -39,6 +39,10 @@ the thin provisioning device-mapper target, else try the one at block#.
|
|||||||
See the thin provisioning target documentation on how to create or release
|
See the thin provisioning target documentation on how to create or release
|
||||||
a metadata snapshot and retrieve the block number from the kernel.
|
a metadata snapshot and retrieve the block number from the kernel.
|
||||||
|
|
||||||
|
.IP "\fN\-\-dev\-id\fP <dev-id>".
|
||||||
|
Dump the specified device. This option may be specified multiple
|
||||||
|
times to select more than one thin device.
|
||||||
|
|
||||||
.IP "\fB\-h, \-\-help\fP".
|
.IP "\fB\-h, \-\-help\fP".
|
||||||
Print help and exit.
|
Print help and exit.
|
||||||
|
|
||||||
|
@ -88,8 +88,13 @@ namespace {
|
|||||||
|
|
||||||
class details_extractor : public device_tree_detail::device_visitor {
|
class details_extractor : public device_tree_detail::device_visitor {
|
||||||
public:
|
public:
|
||||||
|
details_extractor(dump_options const &opts)
|
||||||
|
: opts_(opts) {
|
||||||
|
}
|
||||||
|
|
||||||
void visit(block_address dev_id, device_tree_detail::device_details const &dd) {
|
void visit(block_address dev_id, device_tree_detail::device_details const &dd) {
|
||||||
dd_.insert(make_pair(dev_id, dd));
|
if (opts_.selected_dev(dev_id))
|
||||||
|
dd_.insert(make_pair(dev_id, dd));
|
||||||
}
|
}
|
||||||
|
|
||||||
dd_map const &get_details() const {
|
dd_map const &get_details() const {
|
||||||
@ -97,6 +102,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
dump_options const &opts_;
|
||||||
dd_map dd_;
|
dd_map dd_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -161,21 +167,24 @@ namespace {
|
|||||||
|
|
||||||
class mapping_tree_emitter : public mapping_tree_detail::device_visitor {
|
class mapping_tree_emitter : public mapping_tree_detail::device_visitor {
|
||||||
public:
|
public:
|
||||||
mapping_tree_emitter(metadata::ptr md,
|
mapping_tree_emitter(dump_options const &opts,
|
||||||
|
metadata::ptr md,
|
||||||
emitter::ptr e,
|
emitter::ptr e,
|
||||||
dd_map const &dd,
|
dd_map const &dd,
|
||||||
bool repair,
|
|
||||||
mapping_tree_detail::damage_visitor::ptr damage_policy)
|
mapping_tree_detail::damage_visitor::ptr damage_policy)
|
||||||
: md_(md),
|
: opts_(opts),
|
||||||
|
md_(md),
|
||||||
e_(e),
|
e_(e),
|
||||||
dd_(dd),
|
dd_(dd),
|
||||||
repair_(repair),
|
|
||||||
damage_policy_(damage_policy) {
|
damage_policy_(damage_policy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void visit(btree_path const &path, block_address tree_root) {
|
void visit(btree_path const &path, block_address tree_root) {
|
||||||
block_address dev_id = path[0];
|
block_address dev_id = path[0];
|
||||||
|
|
||||||
|
if (!opts_.selected_dev(dev_id))
|
||||||
|
return;
|
||||||
|
|
||||||
dd_map::const_iterator it = dd_.find(path[0]);
|
dd_map::const_iterator it = dd_.find(path[0]);
|
||||||
if (it != dd_.end()) {
|
if (it != dd_.end()) {
|
||||||
device_tree_detail::device_details const &d = it->second;
|
device_tree_detail::device_details const &d = it->second;
|
||||||
@ -194,7 +203,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
e_->end_device();
|
e_->end_device();
|
||||||
|
|
||||||
} else if (!repair_) {
|
} else if (!opts_.repair_) {
|
||||||
ostringstream msg;
|
ostringstream msg;
|
||||||
msg << "mappings present for device " << dev_id
|
msg << "mappings present for device " << dev_id
|
||||||
<< ", but it isn't present in device tree";
|
<< ", but it isn't present in device tree";
|
||||||
@ -210,10 +219,10 @@ namespace {
|
|||||||
walk_mapping_tree(tree, static_cast<mapping_tree_detail::mapping_visitor &>(me), *damage_policy_);
|
walk_mapping_tree(tree, static_cast<mapping_tree_detail::mapping_visitor &>(me), *damage_policy_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump_options const &opts_;
|
||||||
metadata::ptr md_;
|
metadata::ptr md_;
|
||||||
emitter::ptr e_;
|
emitter::ptr e_;
|
||||||
dd_map const &dd_;
|
dd_map const &dd_;
|
||||||
bool repair_;
|
|
||||||
mapping_tree_detail::damage_visitor::ptr damage_policy_;
|
mapping_tree_detail::damage_visitor::ptr damage_policy_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -234,10 +243,10 @@ namespace {
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
|
thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, dump_options const &opts)
|
||||||
{
|
{
|
||||||
details_extractor de;
|
details_extractor de(opts);
|
||||||
device_tree_detail::damage_visitor::ptr dd_policy(details_damage_policy(repair));
|
device_tree_detail::damage_visitor::ptr dd_policy(details_damage_policy(opts.repair_));
|
||||||
walk_device_tree(*md->details_, de, *dd_policy);
|
walk_device_tree(*md->details_, de, *dd_policy);
|
||||||
|
|
||||||
e->begin_superblock("", md->sb_.time_,
|
e->begin_superblock("", md->sb_.time_,
|
||||||
@ -249,8 +258,8 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair)
|
|||||||
boost::optional<block_address>());
|
boost::optional<block_address>());
|
||||||
|
|
||||||
{
|
{
|
||||||
mapping_tree_detail::damage_visitor::ptr md_policy(mapping_damage_policy(repair));
|
mapping_tree_detail::damage_visitor::ptr md_policy(mapping_damage_policy(opts.repair_));
|
||||||
mapping_tree_emitter mte(md, e, de.get_details(), repair, mapping_damage_policy(repair));
|
mapping_tree_emitter mte(opts, md, e, de.get_details(), mapping_damage_policy(opts.repair_));
|
||||||
walk_mapping_tree(*md->mappings_top_level_, mte, *md_policy);
|
walk_mapping_tree(*md->mappings_top_level_, mte, *md_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,13 +22,40 @@
|
|||||||
#include "emitter.h"
|
#include "emitter.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
|
||||||
|
#include <boost/optional.hpp>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
namespace thin_provisioning {
|
namespace thin_provisioning {
|
||||||
|
class dump_options {
|
||||||
|
public:
|
||||||
|
dump_options()
|
||||||
|
: repair_(false) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool selected_dev(uint64_t dev_id) const {
|
||||||
|
return !dev_filter_ || dev_filter_->count(dev_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void select_dev(uint64_t dev_id) {
|
||||||
|
if (!dev_filter_)
|
||||||
|
dev_filter_ = dev_set();
|
||||||
|
|
||||||
|
dev_filter_->insert(dev_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool repair_;
|
||||||
|
|
||||||
|
using dev_set = std::set<uint64_t>;
|
||||||
|
using maybe_dev_set = boost::optional<dev_set>;
|
||||||
|
maybe_dev_set dev_filter_;
|
||||||
|
};
|
||||||
|
|
||||||
// Set the @repair flag if your metadata is corrupt, and you'd like
|
// Set the @repair flag if your metadata is corrupt, and you'd like
|
||||||
// the dumper to do it's best to recover info. If not set, any
|
// the dumper to do it's best to recover info. If not set, any
|
||||||
// corruption encountered will cause an exception to be thrown.
|
// corruption encountered will cause an exception to be thrown.
|
||||||
void metadata_dump(metadata::ptr md, emitter::ptr e, bool repair);
|
void metadata_dump(metadata::ptr md, emitter::ptr e, dump_options const &opts);
|
||||||
void metadata_dump_subtree(metadata::ptr md, emitter::ptr e, bool repair, uint64_t subtree_root);
|
void metadata_dump_subtree(metadata::ptr md, emitter::ptr e, bool repair, uint64_t subtree_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,11 +38,10 @@ namespace {
|
|||||||
// FIXME: put the path into the flags
|
// FIXME: put the path into the flags
|
||||||
struct flags {
|
struct flags {
|
||||||
flags()
|
flags()
|
||||||
: repair(false),
|
: use_metadata_snap(false) {
|
||||||
use_metadata_snap(false) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool repair;
|
dump_options opts;
|
||||||
bool use_metadata_snap;
|
bool use_metadata_snap;
|
||||||
optional<block_address> snap_location;
|
optional<block_address> snap_location;
|
||||||
};
|
};
|
||||||
@ -70,7 +69,7 @@ namespace {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata_dump(md, e, flags.repair);
|
metadata_dump(md, e, flags.opts);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
@ -99,13 +98,14 @@ thin_dump_cmd::thin_dump_cmd()
|
|||||||
void
|
void
|
||||||
thin_dump_cmd::usage(std::ostream &out) const
|
thin_dump_cmd::usage(std::ostream &out) const
|
||||||
{
|
{
|
||||||
out << "Usage: " << get_name() << " [options] {device|file}" << endl
|
out << "Usage: " << get_name() << " [options] {device|file}\n"
|
||||||
<< "Options:" << endl
|
<< "Options:\n"
|
||||||
<< " {-h|--help}" << endl
|
<< " {-h|--help}\n"
|
||||||
<< " {-f|--format} {xml|human_readable}" << endl
|
<< " {-f|--format} {xml|human_readable}\n"
|
||||||
<< " {-r|--repair}" << endl
|
<< " {-r|--repair}\n"
|
||||||
<< " {-m|--metadata-snap} [block#]" << endl
|
<< " {-m|--metadata-snap} [block#]\n"
|
||||||
<< " {-o <xml file>}" << endl
|
<< " {-o <xml file>}\n"
|
||||||
|
<< " {--dev-id} <dev-id>\n"
|
||||||
<< " {-V|--version}" << endl;
|
<< " {-V|--version}" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +118,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
char *end_ptr;
|
char *end_ptr;
|
||||||
string format = "xml";
|
string format = "xml";
|
||||||
block_address metadata_snap = 0;
|
block_address metadata_snap = 0;
|
||||||
|
uint64_t dev_id;
|
||||||
struct flags flags;
|
struct flags flags;
|
||||||
|
|
||||||
const struct option longopts[] = {
|
const struct option longopts[] = {
|
||||||
@ -126,6 +127,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
{ "output", required_argument, NULL, 'o'},
|
{ "output", required_argument, NULL, 'o'},
|
||||||
{ "format", required_argument, NULL, 'f' },
|
{ "format", required_argument, NULL, 'f' },
|
||||||
{ "repair", no_argument, NULL, 'r'},
|
{ "repair", no_argument, NULL, 'r'},
|
||||||
|
{ "dev-id", required_argument, NULL, 1 },
|
||||||
{ "version", no_argument, NULL, 'V'},
|
{ "version", no_argument, NULL, 'V'},
|
||||||
{ NULL, no_argument, NULL, 0 }
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
@ -141,7 +143,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'r':
|
case 'r':
|
||||||
flags.repair = true;
|
flags.opts.repair_ = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
case 'm':
|
||||||
@ -150,7 +152,7 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
// FIXME: deprecate this option
|
// FIXME: deprecate this option
|
||||||
metadata_snap = strtoull(optarg, &end_ptr, 10);
|
metadata_snap = strtoull(optarg, &end_ptr, 10);
|
||||||
if (end_ptr == optarg) {
|
if (end_ptr == optarg) {
|
||||||
cerr << "couldn't parse <metadata_snap>" << endl;
|
cerr << "couldn't parse <metadata-snap>" << endl;
|
||||||
usage(cerr);
|
usage(cerr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -163,6 +165,16 @@ thin_dump_cmd::run(int argc, char **argv)
|
|||||||
output = optarg;
|
output = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
dev_id = strtoull(optarg, &end_ptr, 10);
|
||||||
|
if (end_ptr == optarg) {
|
||||||
|
cerr << "couldn't parse <dev-id>\n";
|
||||||
|
usage(cerr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
flags.opts.select_dev(dev_id);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'V':
|
case 'V':
|
||||||
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -25,7 +25,10 @@ namespace {
|
|||||||
block_manager<>::ptr old_bm = open_bm(old_path, block_manager<>::READ_ONLY);
|
block_manager<>::ptr old_bm = open_bm(old_path, block_manager<>::READ_ONLY);
|
||||||
|
|
||||||
metadata::ptr old_md(new metadata(old_bm, false));
|
metadata::ptr old_md(new metadata(old_bm, false));
|
||||||
metadata_dump(old_md, e, true);
|
|
||||||
|
dump_options opts;
|
||||||
|
opts.repair_ = true;
|
||||||
|
metadata_dump(old_md, e, opts);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
cerr << e.what() << endl;
|
cerr << e.what() << endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user