[thin] Make the metadata class resposible for locating metadata snapshots
This commit is contained in:
@@ -29,27 +29,42 @@
|
||||
#include "thin-provisioning/commands.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
|
||||
using namespace boost;
|
||||
using namespace persistent_data;
|
||||
using namespace std;
|
||||
using namespace thin_provisioning;
|
||||
|
||||
struct flags {
|
||||
bool find_metadata_snap;
|
||||
bool repair;
|
||||
};
|
||||
|
||||
namespace {
|
||||
int dump_(string const &path, ostream &out, string const &format, struct flags &flags,
|
||||
block_address metadata_snap) {
|
||||
// FIXME: put the path into the flags
|
||||
struct flags {
|
||||
flags()
|
||||
: repair(false),
|
||||
use_metadata_snap(false) {
|
||||
}
|
||||
|
||||
bool repair;
|
||||
bool use_metadata_snap;
|
||||
optional<block_address> snap_location;
|
||||
};
|
||||
|
||||
metadata::ptr open_metadata(string const &path, struct flags &flags) {
|
||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY, !flags.use_metadata_snap);
|
||||
metadata::ptr md(flags.use_metadata_snap ? new metadata(bm, flags.snap_location) : new metadata(bm));
|
||||
|
||||
return md;
|
||||
}
|
||||
|
||||
int dump_(string const &path, ostream &out, string const &format, struct flags &flags) {
|
||||
try {
|
||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY, !metadata_snap);
|
||||
metadata::ptr md(new metadata(bm, metadata_snap));
|
||||
metadata::ptr md = open_metadata(path, flags);
|
||||
emitter::ptr e;
|
||||
|
||||
if (format == "xml")
|
||||
e = create_xml_emitter(out);
|
||||
|
||||
else if (format == "human_readable")
|
||||
e = create_human_readable_emitter(out);
|
||||
|
||||
else {
|
||||
cerr << "unknown format '" << format << "'" << endl;
|
||||
exit(1);
|
||||
@@ -65,13 +80,12 @@ namespace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dump(string const &path, char const *output, string const &format, struct flags &flags,
|
||||
block_address metadata_snap = 0) {
|
||||
int dump(string const &path, char const *output, string const &format, struct flags &flags) {
|
||||
if (output) {
|
||||
ofstream out(output);
|
||||
return dump_(path, out, format, flags, metadata_snap);
|
||||
return dump_(path, out, format, flags);
|
||||
} else
|
||||
return dump_(path, cout, format, flags, metadata_snap);
|
||||
return dump_(path, cout, format, flags);
|
||||
}
|
||||
|
||||
void usage(ostream &out, string const &cmd) {
|
||||
@@ -95,7 +109,6 @@ int thin_dump_main(int argc, char **argv)
|
||||
string format = "xml";
|
||||
block_address metadata_snap = 0;
|
||||
struct flags flags;
|
||||
flags.find_metadata_snap = flags.repair = false;
|
||||
|
||||
const struct option longopts[] = {
|
||||
{ "help", no_argument, NULL, 'h'},
|
||||
@@ -122,16 +135,18 @@ int thin_dump_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
flags.use_metadata_snap = true;
|
||||
if (optarg) {
|
||||
// FIXME: deprecate this option
|
||||
metadata_snap = strtoull(optarg, &end_ptr, 10);
|
||||
if (end_ptr == optarg) {
|
||||
cerr << "couldn't parse <metadata_snap>" << endl;
|
||||
usage(cerr, basename(argv[0]));
|
||||
return 1;
|
||||
}
|
||||
} else
|
||||
flags.find_metadata_snap = true;
|
||||
|
||||
flags.snap_location = metadata_snap;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
@@ -154,10 +169,7 @@ int thin_dump_main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (flags.find_metadata_snap)
|
||||
metadata_snap = find_metadata_snap(argv[optind]);
|
||||
|
||||
return dump(argv[optind], output, format, flags, metadata_snap);
|
||||
return dump(argv[optind], output, format, flags);
|
||||
}
|
||||
|
||||
base::command thin_provisioning::thin_dump_cmd("thin_dump", thin_dump_main);
|
||||
|
||||
Reference in New Issue
Block a user