[thin_check (rust)] move report creation to top level
This commit is contained in:
parent
5743e3e9ba
commit
e8d7e5cf1e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -704,6 +704,7 @@ name = "thinp"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"atty",
|
||||||
"base64",
|
"base64",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -6,6 +6,7 @@ edition = "2018"
|
|||||||
license = "GPL3"
|
license = "GPL3"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
atty = "0.2"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
base64 = "0.12"
|
base64 = "0.12"
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate thinp;
|
extern crate thinp;
|
||||||
|
|
||||||
|
use atty::Stream;
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
use thinp::file_utils;
|
use thinp::file_utils;
|
||||||
use thinp::thin::check::{check, ThinCheckOptions};
|
use thinp::thin::check::{check, ThinCheckOptions};
|
||||||
|
use std::sync::Arc;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use thinp::report::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let parser = App::new("thin_check")
|
let parser = App::new("thin_check")
|
||||||
@ -18,7 +20,6 @@ fn main() {
|
|||||||
.help("Suppress output messages, return only exit code.")
|
.help("Suppress output messages, return only exit code.")
|
||||||
.short("q")
|
.short("q")
|
||||||
.long("quiet")
|
.long("quiet")
|
||||||
.value_name("QUIET"),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("SB_ONLY")
|
Arg::with_name("SB_ONLY")
|
||||||
@ -74,9 +75,20 @@ fn main() {
|
|||||||
exit(1);
|
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 = ThinCheckOptions {
|
let opts = ThinCheckOptions {
|
||||||
dev: &input_file,
|
dev: &input_file,
|
||||||
async_io: !matches.is_present("SYNC_IO"),
|
async_io: !matches.is_present("SYNC_IO"),
|
||||||
|
report
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(reason) = check(&opts) {
|
if let Err(reason) = check(&opts) {
|
||||||
|
@ -257,9 +257,11 @@ const MAX_CONCURRENT_IO: u32 = 1024;
|
|||||||
pub struct ThinCheckOptions<'a> {
|
pub struct ThinCheckOptions<'a> {
|
||||||
pub dev: &'a Path,
|
pub dev: &'a Path,
|
||||||
pub async_io: bool,
|
pub async_io: bool,
|
||||||
|
pub report: Arc<Report>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||||
|
let report = opts.report.clone();
|
||||||
let engine: Arc<dyn IoEngine + Send + Sync>;
|
let engine: Arc<dyn IoEngine + Send + Sync>;
|
||||||
|
|
||||||
let nr_threads;
|
let nr_threads;
|
||||||
@ -286,9 +288,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
|||||||
let devs = btree_to_map::<DeviceDetail>(engine.clone(), false, sb.details_root)?;
|
let devs = btree_to_map::<DeviceDetail>(engine.clone(), false, sb.details_root)?;
|
||||||
let nr_devs = devs.len();
|
let nr_devs = devs.len();
|
||||||
let metadata_sm = core_sm(engine.get_nr_blocks(), nr_devs as u32);
|
let metadata_sm = core_sm(engine.get_nr_blocks(), nr_devs as u32);
|
||||||
let report = Arc::new(mk_progress_bar_report());
|
|
||||||
//let report = Arc::new(mk_simple_report());
|
|
||||||
//let report = Arc::new(mk_quiet_report());
|
|
||||||
report.set_title("Checking thin metadata");
|
report.set_title("Checking thin metadata");
|
||||||
|
|
||||||
let tid;
|
let tid;
|
||||||
|
Loading…
Reference in New Issue
Block a user