[thin_check (rust)] Add title method to reports
This commit is contained in:
parent
9995751dde
commit
5743e3e9ba
@ -1,4 +1,3 @@
|
||||
use anyhow::Result;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use std::sync::Mutex;
|
||||
|
||||
@ -31,10 +30,11 @@ pub struct Report {
|
||||
}
|
||||
|
||||
trait ReportInner {
|
||||
fn set_title(&mut self, txt: &str) -> Result<()>;
|
||||
fn progress(&mut self, percent: u8) -> Result<()>;
|
||||
fn log(&mut self, txt: &str) -> Result<()>;
|
||||
fn complete(&mut self) -> Result<()>;
|
||||
fn set_title(&mut self, txt: &str);
|
||||
fn set_sub_title(&mut self, txt: &str);
|
||||
fn progress(&mut self, percent: u8);
|
||||
fn log(&mut self, txt: &str);
|
||||
fn complete(&mut self);
|
||||
}
|
||||
|
||||
impl Report {
|
||||
@ -50,48 +50,58 @@ impl Report {
|
||||
*lhs = ReportOutcome::combine(&lhs, &rhs);
|
||||
}
|
||||
|
||||
pub fn set_title(&self, txt: &str) -> Result<()> {
|
||||
pub fn set_title(&self, txt: &str) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.set_title(txt)
|
||||
}
|
||||
|
||||
pub fn progress(&self, percent: u8) -> Result<()> {
|
||||
pub fn set_sub_title(&self, txt: &str) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.set_sub_title(txt)
|
||||
}
|
||||
|
||||
pub fn progress(&self, percent: u8) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.progress(percent)
|
||||
}
|
||||
|
||||
pub fn info(&self, txt: &str) -> Result<()> {
|
||||
pub fn info(&self, txt: &str) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.log(txt)
|
||||
}
|
||||
|
||||
pub fn non_fatal(&self, txt: &str) -> Result<()> {
|
||||
pub fn non_fatal(&self, txt: &str) {
|
||||
self.update_outcome(NonFatal);
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.log(txt)
|
||||
}
|
||||
|
||||
pub fn fatal(&self, txt: &str) -> Result<()> {
|
||||
pub fn fatal(&self, txt: &str) {
|
||||
self.update_outcome(Fatal);
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.log(txt)
|
||||
}
|
||||
|
||||
pub fn complete(&mut self) -> Result<()> {
|
||||
pub fn complete(&mut self) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.complete()?;
|
||||
Ok(())
|
||||
inner.complete();
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct PBInner {
|
||||
title: String,
|
||||
bar: ProgressBar,
|
||||
}
|
||||
|
||||
impl ReportInner for PBInner {
|
||||
fn set_title(&mut self, txt: &str) -> Result<()> {
|
||||
fn set_title(&mut self, txt: &str) {
|
||||
self.title = txt.to_string();
|
||||
}
|
||||
|
||||
fn set_sub_title(&mut self, txt: &str) {
|
||||
//let mut fmt = "".to_string(); //Checking thin metadata".to_string(); //self.title.clone();
|
||||
let mut fmt = "Checking thin metadata [{bar:40}] Remaining {eta}, ".to_string();
|
||||
fmt.push_str(&txt);
|
||||
self.bar.set_style(
|
||||
@ -99,28 +109,25 @@ impl ReportInner for PBInner {
|
||||
.template(&fmt)
|
||||
.progress_chars("=> "),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn progress(&mut self, percent: u8) -> Result<()> {
|
||||
fn progress(&mut self, percent: u8) {
|
||||
self.bar.set_position(percent as u64);
|
||||
self.bar.tick();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn log(&mut self, txt: &str) -> Result<()> {
|
||||
fn log(&mut self, txt: &str) {
|
||||
self.bar.println(txt);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn complete(&mut self) -> Result<()> {
|
||||
fn complete(&mut self) {
|
||||
self.bar.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_progress_bar_report() -> Report {
|
||||
Report::new(Box::new(PBInner {
|
||||
title: "".to_string(),
|
||||
bar: ProgressBar::new(100),
|
||||
}))
|
||||
}
|
||||
@ -140,28 +147,27 @@ impl SimpleInner {
|
||||
}
|
||||
|
||||
impl ReportInner for SimpleInner {
|
||||
fn set_title(&mut self, txt: &str) -> Result<()> {
|
||||
fn set_title(&mut self, txt: &str) {
|
||||
println!("{}", txt);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn progress(&mut self, percent: u8) -> Result<()> {
|
||||
fn set_sub_title(&mut self, txt: &str) {
|
||||
println!("{}", txt);
|
||||
}
|
||||
|
||||
fn progress(&mut self, percent: u8) {
|
||||
let elapsed = self.last_progress.elapsed().unwrap();
|
||||
if elapsed > std::time::Duration::from_secs(5) {
|
||||
println!("Progress: {}%", percent);
|
||||
self.last_progress = std::time::SystemTime::now();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn log(&mut self, txt: &str) -> Result<()> {
|
||||
fn log(&mut self, txt: &str) {
|
||||
eprintln!("{}", txt);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn complete(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn complete(&mut self) {}
|
||||
}
|
||||
|
||||
pub fn mk_simple_report() -> Report {
|
||||
@ -170,25 +176,18 @@ pub fn mk_simple_report() -> Report {
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
struct QuietInner {
|
||||
}
|
||||
struct QuietInner {}
|
||||
|
||||
impl ReportInner for QuietInner {
|
||||
fn set_title(&mut self, _txt: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn set_title(&mut self, _txt: &str) {}
|
||||
|
||||
fn progress(&mut self, _percent: u8) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn set_sub_title(&mut self, _txt: &str) {}
|
||||
|
||||
fn log(&mut self, _txt: &str) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn progress(&mut self, _percent: u8) {}
|
||||
|
||||
fn complete(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn log(&mut self, _txt: &str) {}
|
||||
|
||||
fn complete(&mut self) {}
|
||||
}
|
||||
|
||||
pub fn mk_quiet_report() -> Report {
|
||||
|
@ -210,7 +210,7 @@ fn check_space_map(
|
||||
leaks += 1;
|
||||
} else if actual != expected as u8 {
|
||||
report.fatal(&format!("Bad reference count for {} block {}. Expected {}, but space map contains {}.",
|
||||
kind, blocknr, expected, actual))?;
|
||||
kind, blocknr, expected, actual));
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
@ -218,7 +218,7 @@ fn check_space_map(
|
||||
let expected = sm.get(blocknr)?;
|
||||
if expected < 3 {
|
||||
report.fatal(&format!("Bad reference count for {} block {}. Expected {}, but space map says it's >= 3.",
|
||||
kind, blocknr, expected))?;
|
||||
kind, blocknr, expected));
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
@ -231,7 +231,7 @@ fn check_space_map(
|
||||
report.non_fatal(&format!(
|
||||
"{} {} blocks have leaked. Use --auto-repair to fix.",
|
||||
leaks, kind
|
||||
))?;
|
||||
));
|
||||
}
|
||||
|
||||
if fail {
|
||||
@ -286,9 +286,10 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||
let devs = btree_to_map::<DeviceDetail>(engine.clone(), false, sb.details_root)?;
|
||||
let nr_devs = devs.len();
|
||||
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_progress_bar_report());
|
||||
//let report = Arc::new(mk_simple_report());
|
||||
let report = Arc::new(mk_quiet_report());
|
||||
//let report = Arc::new(mk_quiet_report());
|
||||
report.set_title("Checking thin metadata");
|
||||
|
||||
let tid;
|
||||
let stop_progress = Arc::new(Mutex::new(false));
|
||||
@ -320,7 +321,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||
});
|
||||
}
|
||||
|
||||
report.set_title("device details tree")?;
|
||||
report.set_sub_title("device details tree");
|
||||
let _devs = btree_to_map_with_sm::<DeviceDetail>(
|
||||
engine.clone(),
|
||||
metadata_sm.clone(),
|
||||
@ -339,7 +340,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||
btree_to_map_with_sm::<u64>(engine.clone(), metadata_sm.clone(), false, sb.mapping_root)?;
|
||||
|
||||
// Check the mappings filling in the data_sm as we go.
|
||||
report.set_title("mapping tree")?;
|
||||
report.set_sub_title("mapping tree");
|
||||
let data_sm;
|
||||
{
|
||||
// FIXME: with a thread pool we need to return errors another way.
|
||||
@ -371,7 +372,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||
pool.join();
|
||||
}
|
||||
|
||||
report.set_title("data space map")?;
|
||||
report.set_sub_title("data space map");
|
||||
let root = unpack::<SMRoot>(&sb.data_sm_root[0..])?;
|
||||
|
||||
let entries = btree_to_map_with_sm::<IndexEntry>(
|
||||
@ -393,7 +394,7 @@ pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
||||
root,
|
||||
)?;
|
||||
|
||||
report.set_title("metadata space map")?;
|
||||
report.set_sub_title("metadata space map");
|
||||
let root = unpack::<SMRoot>(&sb.metadata_sm_root[0..])?;
|
||||
let mut b = Block::new(root.bitmap_root);
|
||||
engine.read(&mut b)?;
|
||||
|
Loading…
Reference in New Issue
Block a user