2020-12-20 17:53:30 +05:30
|
|
|
extern crate clap;
|
|
|
|
extern crate thinp;
|
|
|
|
|
2021-04-20 13:37:25 +05:30
|
|
|
use atty::Stream;
|
2020-12-20 17:53:30 +05:30
|
|
|
use clap::{App, Arg};
|
|
|
|
use std::path::Path;
|
2021-09-06 21:31:37 +05:30
|
|
|
use std::process;
|
2021-04-20 13:37:25 +05:30
|
|
|
use std::sync::Arc;
|
|
|
|
|
2020-12-20 17:53:30 +05:30
|
|
|
use thinp::cache::check::{check, CacheCheckOptions};
|
2021-09-06 21:31:37 +05:30
|
|
|
use thinp::file_utils;
|
2021-05-11 18:11:30 +05:30
|
|
|
use thinp::report::*;
|
2020-12-20 17:53:30 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let parser = App::new("cache_check")
|
2021-05-11 23:42:11 +05:30
|
|
|
.version(thinp::version::tools_version())
|
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-12-20 17:53:30 +05:30
|
|
|
.arg(
|
2021-06-23 10:14:38 +05:30
|
|
|
Arg::with_name("AUTO_REPAIR")
|
|
|
|
.help("Auto repair trivial issues.")
|
|
|
|
.long("auto-repair"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("IGNORE_NON_FATAL")
|
|
|
|
.help("Only return a non-zero exit code if a fatal error is found.")
|
|
|
|
.long("ignore-non-fatal-errors"),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("QUIET")
|
|
|
|
.help("Suppress output messages, return only exit code.")
|
|
|
|
.short("q")
|
|
|
|
.long("quiet"),
|
2020-12-20 17:53:30 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SB_ONLY")
|
|
|
|
.help("Only check the superblock.")
|
2021-06-23 10:14:38 +05:30
|
|
|
.long("super-block-only"),
|
2020-12-20 17:53:30 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SKIP_MAPPINGS")
|
|
|
|
.help("Don't check the mapping array")
|
2021-06-23 10:14:38 +05:30
|
|
|
.long("skip-mappings"),
|
2020-12-20 17:53:30 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SKIP_HINTS")
|
|
|
|
.help("Don't check the hint array")
|
2021-06-23 10:14:38 +05:30
|
|
|
.long("skip-hints"),
|
2020-12-20 17:53:30 +05:30
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("SKIP_DISCARDS")
|
|
|
|
.help("Don't check the discard bitset")
|
2021-06-23 10:14:38 +05:30
|
|
|
.long("skip-discards"),
|
2021-04-20 13:37:25 +05:30
|
|
|
)
|
2021-06-23 10:14:38 +05:30
|
|
|
// arguments
|
2021-04-21 12:06:16 +05:30
|
|
|
.arg(
|
2021-06-23 10:14:38 +05:30
|
|
|
Arg::with_name("INPUT")
|
|
|
|
.help("Specify the input device to check")
|
|
|
|
.required(true)
|
|
|
|
.index(1),
|
2020-12-20 17:53:30 +05:30
|
|
|
);
|
|
|
|
|
|
|
|
let matches = parser.get_matches();
|
|
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:37:25 +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());
|
|
|
|
}
|
|
|
|
|
2020-12-20 17:53:30 +05:30
|
|
|
let opts = CacheCheckOptions {
|
|
|
|
dev: &input_file,
|
2021-06-23 09:10:12 +05:30
|
|
|
async_io: matches.is_present("ASYNC_IO"),
|
2020-12-20 17:53:30 +05:30
|
|
|
sb_only: matches.is_present("SB_ONLY"),
|
|
|
|
skip_mappings: matches.is_present("SKIP_MAPPINGS"),
|
|
|
|
skip_hints: matches.is_present("SKIP_HINTS"),
|
|
|
|
skip_discards: matches.is_present("SKIP_DISCARDS"),
|
2021-04-21 12:06:16 +05:30
|
|
|
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
2021-04-21 21:06:10 +05:30
|
|
|
auto_repair: matches.is_present("AUTO_REPAIR"),
|
2021-04-20 13:37:25 +05:30
|
|
|
report,
|
2020-12-20 17:53:30 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
if let Err(reason) = check(opts) {
|
|
|
|
eprintln!("{}", reason);
|
2021-09-06 21:31:37 +05:30
|
|
|
process::exit(1);
|
2020-12-20 17:53:30 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|