2013-06-19 17:09:28 +05:30
|
|
|
#include <iostream>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
2016-07-11 19:23:03 +05:30
|
|
|
#include "base/output_file_requirements.h"
|
2015-12-14 20:59:57 +05:30
|
|
|
#include "persistent-data/file_utils.h"
|
2014-08-27 18:31:31 +05:30
|
|
|
#include "thin-provisioning/commands.h"
|
2013-06-19 17:09:28 +05:30
|
|
|
#include "human_readable_format.h"
|
|
|
|
#include "metadata_dumper.h"
|
|
|
|
#include "metadata.h"
|
|
|
|
#include "restore_emitter.h"
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
using namespace persistent_data;
|
|
|
|
using namespace std;
|
|
|
|
using namespace thin_provisioning;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
int repair(string const &old_path, string const &new_path) {
|
|
|
|
try {
|
|
|
|
// block size gets updated by the restorer
|
2015-12-14 20:59:57 +05:30
|
|
|
block_manager<>::ptr new_bm = open_bm(new_path, block_manager<>::READ_WRITE);
|
|
|
|
metadata::ptr new_md(new metadata(new_bm, metadata::CREATE, 128, 0));
|
2013-06-19 17:09:28 +05:30
|
|
|
emitter::ptr e = create_restore_emitter(new_md);
|
|
|
|
|
2015-12-14 20:59:57 +05:30
|
|
|
block_manager<>::ptr old_bm = open_bm(old_path, block_manager<>::READ_ONLY);
|
2016-03-21 21:06:49 +05:30
|
|
|
|
2016-03-21 22:47:57 +05:30
|
|
|
metadata::ptr old_md(new metadata(old_bm, false));
|
2016-03-22 20:11:02 +05:30
|
|
|
|
|
|
|
dump_options opts;
|
|
|
|
opts.repair_ = true;
|
|
|
|
metadata_dump(old_md, e, opts);
|
2013-06-19 17:09:28 +05:30
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-08 18:21:52 +05:30
|
|
|
}
|
2013-06-19 17:09:28 +05:30
|
|
|
|
2016-01-08 18:21:52 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
thin_repair_cmd::thin_repair_cmd()
|
|
|
|
: command("thin_repair")
|
|
|
|
{
|
2013-06-19 17:09:28 +05:30
|
|
|
}
|
|
|
|
|
2016-01-08 18:21:52 +05:30
|
|
|
void
|
|
|
|
thin_repair_cmd::usage(std::ostream &out) const
|
|
|
|
{
|
|
|
|
out << "Usage: " << get_name() << " [options] {device|file}" << endl
|
|
|
|
<< "Options:" << endl
|
|
|
|
<< " {-h|--help}" << endl
|
|
|
|
<< " {-i|--input} <input metadata (binary format)>" << endl
|
|
|
|
<< " {-o|--output} <output metadata (binary format)>" << endl
|
|
|
|
<< " {-V|--version}" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
thin_repair_cmd::run(int argc, char **argv)
|
2013-06-19 17:09:28 +05:30
|
|
|
{
|
|
|
|
int c;
|
|
|
|
boost::optional<string> input_path, output_path;
|
|
|
|
const char shortopts[] = "hi:o:V";
|
|
|
|
|
|
|
|
const struct option longopts[] = {
|
|
|
|
{ "help", no_argument, NULL, 'h'},
|
|
|
|
{ "input", required_argument, NULL, 'i'},
|
|
|
|
{ "output", required_argument, NULL, 'o'},
|
|
|
|
{ "version", no_argument, NULL, 'V'},
|
|
|
|
{ NULL, no_argument, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) {
|
|
|
|
switch(c) {
|
|
|
|
case 'h':
|
2016-01-08 18:21:52 +05:30
|
|
|
usage(cout);
|
2013-06-19 17:09:28 +05:30
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
input_path = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
output_path = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
cout << THIN_PROVISIONING_TOOLS_VERSION << endl;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2016-01-08 18:21:52 +05:30
|
|
|
usage(cerr);
|
2013-06-19 17:09:28 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!input_path) {
|
|
|
|
cerr << "no input file provided" << endl;
|
2016-01-08 18:21:52 +05:30
|
|
|
usage(cerr);
|
2013-06-19 17:09:28 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-07-11 19:23:03 +05:30
|
|
|
if (output_path)
|
|
|
|
check_output_file_requirements(*output_path);
|
|
|
|
|
|
|
|
else {
|
2013-06-19 17:09:28 +05:30
|
|
|
cerr << "no output file provided" << endl;
|
2016-01-08 18:21:52 +05:30
|
|
|
usage(cerr);
|
2013-06-19 17:09:28 +05:30
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return repair(*input_path, *output_path);
|
|
|
|
}
|
2014-08-27 18:31:31 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|