thin-provisioning-tools/src/bin/thin_check.rs

99 lines
3.0 KiB
Rust
Raw Normal View History

2020-06-14 12:47:46 +05:30
extern crate clap;
extern crate thinp;
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 thinp::file_utils;
use thinp::thin::check::{check, ThinCheckOptions};
use std::sync::Arc;
2020-06-14 12:47:46 +05:30
use std::process::exit;
use thinp::report::*;
2020-06-14 12:47:46 +05:30
fn main() {
let parser = App::new("thin_check")
2020-07-27 20:23:42 +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.")
2020-07-27 20:23:42 +05:30
.arg(
Arg::with_name("QUIET")
.help("Suppress output messages, return only exit code.")
.short("q")
.long("quiet")
)
.arg(
Arg::with_name("SB_ONLY")
.help("Only check the superblock.")
.long("super-block-only")
.value_name("SB_ONLY"),
)
.arg(
Arg::with_name("ignore-non-fatal-errors")
.help("Only return a non-zero exit code if a fatal error is found.")
.long("ignore-non-fatal-errors")
.value_name("IGNORE_NON_FATAL"),
)
.arg(
Arg::with_name("clear-needs-check-flag")
.help("Clears the 'needs_check' flag in the superblock")
.long("clear-needs-check")
.value_name("CLEAR_NEEDS_CHECK"),
)
.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),
)
.arg(
Arg::with_name("SYNC_IO")
.help("Force use of synchronous io")
.long("sync-io")
.value_name("SYNC_IO")
.takes_value(false),
2020-07-27 20:23:42 +05:30
);
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
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 = ThinCheckOptions {
dev: &input_file,
async_io: !matches.is_present("SYNC_IO"),
report
};
if let Err(reason) = check(&opts) {
2020-06-14 12:47:46 +05:30
println!("Application error: {}", reason);
process::exit(1);
}
}