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::sync::Arc;
|
|
|
|
use thinp::file_utils;
|
|
|
|
use thinp::report::*;
|
|
|
|
use thinp::thin::dump::{dump, ThinDumpOptions};
|
2021-08-23 23:48:08 +05:30
|
|
|
use thinp::thin::metadata_repair::SuperblockOverrides;
|
2020-09-28 20:12:07 +05:30
|
|
|
|
|
|
|
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
|
2021-08-23 23:48:08 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("DATA_BLOCK_SIZE")
|
|
|
|
.help("Provide the data block size for repairing")
|
|
|
|
.long("data-block-size")
|
|
|
|
.value_name("SECTORS"),
|
|
|
|
)
|
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-08-23 23:48:08 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("NR_DATA_BLOCKS")
|
|
|
|
.help("Override the number of data blocks if needed")
|
|
|
|
.long("nr-data-blocks")
|
|
|
|
.value_name("NUM"),
|
|
|
|
)
|
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")
|
2021-08-23 23:47:24 +05:30
|
|
|
.value_name("FILE"),
|
2021-06-15 14:07:04 +05:30
|
|
|
)
|
2021-08-23 23:48:08 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("TRANSACTION_ID")
|
|
|
|
.help("Override the transaction id if needed")
|
|
|
|
.long("transaction-id")
|
|
|
|
.value_name("NUM"),
|
|
|
|
)
|
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
|
|
|
|
2021-09-06 21:31:37 +05:30
|
|
|
if let Err(e) = file_utils::is_file_or_blk(input_file) {
|
|
|
|
eprintln!("Invalid input file '{}': {}.", input_file.display(), e);
|
|
|
|
process::exit(1);
|
2020-09-28 20:12:07 +05:30
|
|
|
}
|
|
|
|
|
2021-08-23 23:48:08 +05:30
|
|
|
let transaction_id = matches.value_of("TRANSACTION_ID").map(|s| {
|
|
|
|
s.parse::<u64>().unwrap_or_else(|_| {
|
|
|
|
eprintln!("Couldn't parse transaction_id");
|
2021-09-06 21:31:37 +05:30
|
|
|
process::exit(1);
|
2021-08-23 23:48:08 +05:30
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let data_block_size = matches.value_of("DATA_BLOCK_SIZE").map(|s| {
|
|
|
|
s.parse::<u32>().unwrap_or_else(|_| {
|
|
|
|
eprintln!("Couldn't parse data_block_size");
|
2021-09-06 21:31:37 +05:30
|
|
|
process::exit(1);
|
2021-08-23 23:48:08 +05:30
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
let nr_data_blocks = matches.value_of("NR_DATA_BLOCKS").map(|s| {
|
|
|
|
s.parse::<u64>().unwrap_or_else(|_| {
|
|
|
|
eprintln!("Couldn't parse nr_data_blocks");
|
2021-09-06 21:31:37 +05:30
|
|
|
process::exit(1);
|
2021-08-23 23:48:08 +05:30
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2020-09-28 20:12:07 +05:30
|
|
|
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,
|
2021-08-23 23:48:08 +05:30
|
|
|
repair: matches.is_present("REPAIR"),
|
|
|
|
overrides: SuperblockOverrides {
|
|
|
|
transaction_id,
|
|
|
|
data_block_size,
|
|
|
|
nr_data_blocks,
|
|
|
|
},
|
2020-09-28 20:12:07 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(reason) = dump(opts) {
|
|
|
|
println!("{}", reason);
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
}
|