2020-09-28 20:12:07 +05:30
|
|
|
extern crate clap;
|
|
|
|
extern crate thinp;
|
|
|
|
|
|
|
|
use atty::Stream;
|
|
|
|
use clap::{App, Arg};
|
|
|
|
use std::path::Path;
|
|
|
|
use std::process;
|
|
|
|
use std::process::exit;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use thinp::file_utils;
|
|
|
|
use thinp::report::*;
|
|
|
|
use thinp::thin::dump::{dump, ThinDumpOptions};
|
|
|
|
|
|
|
|
fn main() {
|
2021-06-15 14:07:04 +05:30
|
|
|
let parser = App::new("thin_dump")
|
2021-05-11 23:42:11 +05:30
|
|
|
.version(thinp::version::tools_version())
|
2021-06-15 14:07:04 +05:30
|
|
|
.about("Dump thin-provisioning metadata to stdout in XML format")
|
2021-06-23 10:14:38 +05:30
|
|
|
// flags
|
2021-06-23 09:10:12 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("ASYNC_IO")
|
|
|
|
.help("Force use of io_uring for synchronous io")
|
|
|
|
.long("async-io")
|
|
|
|
.hidden(true),
|
|
|
|
)
|
2020-09-28 20:12:07 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("QUIET")
|
|
|
|
.help("Suppress output messages, return only exit code.")
|
|
|
|
.short("q")
|
|
|
|
.long("quiet"),
|
|
|
|
)
|
|
|
|
.arg(
|
2021-06-15 14:07:04 +05:30
|
|
|
Arg::with_name("REPAIR")
|
|
|
|
.help("Repair the metadata whilst dumping it")
|
|
|
|
.short("r")
|
|
|
|
.long("repair"),
|
2020-09-28 20:12:07 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SKIP_MAPPINGS")
|
2021-06-15 14:07:04 +05:30
|
|
|
.help("Do not dump the mappings")
|
|
|
|
.long("skip-mappings"),
|
2020-09-28 20:12:07 +05:30
|
|
|
)
|
2021-06-23 10:14:38 +05:30
|
|
|
// options
|
2020-09-28 20:12:07 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("METADATA_SNAPSHOT")
|
2021-06-15 14:07:04 +05:30
|
|
|
.help("Access the metadata snapshot on a live pool")
|
2020-09-28 20:12:07 +05:30
|
|
|
.short("m")
|
|
|
|
.long("metadata-snapshot")
|
|
|
|
.value_name("METADATA_SNAPSHOT"),
|
|
|
|
)
|
2021-06-15 14:07:04 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("OUTPUT")
|
|
|
|
.help("Specify the output file rather than stdout")
|
|
|
|
.short("o")
|
|
|
|
.long("output")
|
|
|
|
.value_name("OUTPUT"),
|
|
|
|
)
|
2021-06-23 10:14:38 +05:30
|
|
|
// arguments
|
2020-09-28 20:12:07 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("INPUT")
|
2021-06-15 14:07:04 +05:30
|
|
|
.help("Specify the input device to dump")
|
2020-09-28 20:12:07 +05:30
|
|
|
.required(true)
|
|
|
|
.index(1),
|
|
|
|
);
|
|
|
|
|
|
|
|
let matches = parser.get_matches();
|
|
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
2021-06-15 14:07:04 +05:30
|
|
|
let output_file = if matches.is_present("OUTPUT") {
|
|
|
|
Some(Path::new(matches.value_of("OUTPUT").unwrap()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2020-09-28 20:12:07 +05:30
|
|
|
|
|
|
|
if !file_utils::file_exists(input_file) {
|
|
|
|
eprintln!("Couldn't find input file '{:?}'.", &input_file);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
let report;
|
|
|
|
|
|
|
|
if matches.is_present("QUIET") {
|
|
|
|
report = std::sync::Arc::new(mk_quiet_report());
|
|
|
|
} else if atty::is(Stream::Stdout) {
|
|
|
|
report = std::sync::Arc::new(mk_progress_bar_report());
|
|
|
|
} else {
|
|
|
|
report = Arc::new(mk_simple_report());
|
|
|
|
}
|
|
|
|
|
|
|
|
let opts = ThinDumpOptions {
|
2021-06-15 14:07:04 +05:30
|
|
|
input: input_file,
|
|
|
|
output: output_file,
|
2021-06-23 09:10:12 +05:30
|
|
|
async_io: matches.is_present("ASYNC_IO"),
|
2020-09-28 20:12:07 +05:30
|
|
|
report,
|
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(reason) = dump(opts) {
|
|
|
|
println!("{}", reason);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
}
|