2020-06-14 12:47:46 +05:30
|
|
|
extern crate clap;
|
|
|
|
extern crate thinp;
|
|
|
|
|
2020-08-17 20:22:12 +05:30
|
|
|
use atty::Stream;
|
2020-06-14 12:47:46 +05:30
|
|
|
use clap::{App, Arg};
|
2020-07-27 20:23:42 +05:30
|
|
|
use std::path::Path;
|
2020-06-14 12:47:46 +05:30
|
|
|
use std::process;
|
|
|
|
use std::process::exit;
|
2020-08-18 16:17:42 +05:30
|
|
|
use std::sync::Arc;
|
|
|
|
use thinp::file_utils;
|
2021-04-08 15:15:50 +05:30
|
|
|
use thinp::io_engine::*;
|
2020-08-17 20:22:12 +05:30
|
|
|
use thinp::report::*;
|
2021-04-08 15:15:50 +05:30
|
|
|
use thinp::thin::check::{check, ThinCheckOptions, MAX_CONCURRENT_IO};
|
2020-06-14 12:47:46 +05:30
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let parser = App::new("thin_check")
|
2021-05-11 23:42:11 +05:30
|
|
|
.version(thinp::version::tools_version())
|
2020-06-14 12:47:46 +05:30
|
|
|
.about("Validates thin provisioning metadata on a device or file.")
|
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-07-27 20:23:42 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("QUIET")
|
|
|
|
.help("Suppress output messages, return only exit code.")
|
|
|
|
.short("q")
|
2020-08-18 16:17:42 +05:30
|
|
|
.long("quiet"),
|
2020-07-27 20:23:42 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SB_ONLY")
|
|
|
|
.help("Only check the superblock.")
|
2021-06-21 13:14:56 +05:30
|
|
|
.long("super-block-only"),
|
2020-09-24 18:25:58 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SKIP_MAPPINGS")
|
|
|
|
.help("Don't check the mapping tree")
|
2021-06-21 13:14:56 +05:30
|
|
|
.long("skip-mappings"),
|
2020-09-24 18:25:58 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("AUTO_REPAIR")
|
2020-08-18 16:17:42 +05:30
|
|
|
.help("Auto repair trivial issues.")
|
|
|
|
.long("auto-repair"),
|
2020-07-27 20:23:42 +05:30
|
|
|
)
|
|
|
|
.arg(
|
2020-08-18 16:17:42 +05:30
|
|
|
Arg::with_name("IGNORE_NON_FATAL")
|
2020-07-27 20:23:42 +05:30
|
|
|
.help("Only return a non-zero exit code if a fatal error is found.")
|
2020-08-18 16:17:42 +05:30
|
|
|
.long("ignore-non-fatal-errors"),
|
2020-07-27 20:23:42 +05:30
|
|
|
)
|
|
|
|
.arg(
|
2020-08-18 16:17:42 +05:30
|
|
|
Arg::with_name("CLEAR_NEEDS_CHECK")
|
2020-07-27 20:23:42 +05:30
|
|
|
.help("Clears the 'needs_check' flag in the superblock")
|
2021-06-21 13:14:56 +05:30
|
|
|
.long("clear-needs-check-flag"),
|
2020-07-27 20:23:42 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("OVERRIDE_MAPPING_ROOT")
|
|
|
|
.help("Specify a mapping root to use")
|
|
|
|
.long("override-mapping-root")
|
|
|
|
.value_name("OVERRIDE_MAPPING_ROOT")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("METADATA_SNAPSHOT")
|
|
|
|
.help("Check the metadata snapshot on a live pool")
|
|
|
|
.short("m")
|
|
|
|
.long("metadata-snapshot")
|
|
|
|
.value_name("METADATA_SNAPSHOT"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("INPUT")
|
|
|
|
.help("Specify the input device to check")
|
|
|
|
.required(true)
|
|
|
|
.index(1),
|
|
|
|
);
|
2020-06-14 12:47:46 +05:30
|
|
|
|
|
|
|
let matches = parser.get_matches();
|
2020-07-27 20:23:42 +05:30
|
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
2020-06-14 12:47:46 +05:30
|
|
|
|
|
|
|
if !file_utils::file_exists(input_file) {
|
2020-07-27 20:23:42 +05:30
|
|
|
eprintln!("Couldn't find input file '{:?}'.", &input_file);
|
2020-06-14 12:47:46 +05:30
|
|
|
exit(1);
|
|
|
|
}
|
2020-07-27 20:23:42 +05:30
|
|
|
|
2020-08-17 20:22:12 +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 {
|
2020-08-18 16:17:42 +05:30
|
|
|
report = Arc::new(mk_simple_report());
|
2020-08-17 20:22:12 +05:30
|
|
|
}
|
|
|
|
|
2021-04-08 15:15:50 +05:30
|
|
|
let engine: Arc<dyn IoEngine + Send + Sync>;
|
2020-12-02 17:03:05 +05:30
|
|
|
|
2021-04-08 15:15:50 +05:30
|
|
|
if matches.is_present("ASYNC_IO") {
|
2021-05-11 18:11:30 +05:30
|
|
|
engine = Arc::new(
|
|
|
|
AsyncIoEngine::new(&input_file, MAX_CONCURRENT_IO, false)
|
|
|
|
.expect("unable to open input file"),
|
|
|
|
);
|
2021-04-08 15:15:50 +05:30
|
|
|
} else {
|
|
|
|
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
|
2021-05-11 18:11:30 +05:30
|
|
|
engine = Arc::new(
|
|
|
|
SyncIoEngine::new(&input_file, nr_threads, false).expect("unable to open input file"),
|
|
|
|
);
|
2020-12-02 17:03:05 +05:30
|
|
|
}
|
|
|
|
|
2020-08-10 15:54:50 +05:30
|
|
|
let opts = ThinCheckOptions {
|
2021-05-11 18:11:30 +05:30
|
|
|
engine,
|
2020-09-24 18:25:58 +05:30
|
|
|
sb_only: matches.is_present("SB_ONLY"),
|
|
|
|
skip_mappings: matches.is_present("SKIP_MAPPINGS"),
|
2020-08-18 16:17:42 +05:30
|
|
|
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
|
|
|
auto_repair: matches.is_present("AUTO_REPAIR"),
|
|
|
|
report,
|
2020-08-10 15:54:50 +05:30
|
|
|
};
|
|
|
|
|
2020-08-18 14:18:51 +05:30
|
|
|
if let Err(reason) = check(opts) {
|
2020-12-02 17:03:05 +05:30
|
|
|
eprintln!("{}", reason);
|
2020-06-14 12:47:46 +05:30
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
}
|