[thin_check (rust)] add --sync-io flag

Makes it easier to switch between engines
This commit is contained in:
Joe Thornber 2020-08-10 11:24:50 +01:00
parent 0f865856ed
commit 4e4b7ca2b1
2 changed files with 31 additions and 5 deletions

View File

@ -5,6 +5,7 @@ use clap::{App, Arg};
use std::path::Path;
use std::process;
use thinp::file_utils;
use thinp::thin::check::{check, ThinCheckOptions};
use std::process::exit;
@ -56,6 +57,13 @@ fn main() {
.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),
);
let matches = parser.get_matches();
@ -66,7 +74,12 @@ fn main() {
exit(1);
}
if let Err(reason) = thinp::thin::check::check(&input_file) {
let opts = ThinCheckOptions {
dev: &input_file,
async_io: !matches.is_present("SYNC_IO"),
};
if let Err(reason) = check(&opts) {
println!("Application error: {}", reason);
process::exit(1);
}

View File

@ -264,10 +264,23 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
const MAX_CONCURRENT_IO: u32 = 1024;
pub fn check(dev: &Path) -> Result<()> {
let nr_threads = 4;
let engine = Arc::new(AsyncIoEngine::new(dev, MAX_CONCURRENT_IO)?);
//let engine: Arc<dyn IoEngine + Send + Sync> = Arc::new(SyncIoEngine::new(dev, nr_threads)?);
pub struct ThinCheckOptions<'a> {
pub dev: &'a Path,
pub async_io: bool,
}
pub fn check(opts: &ThinCheckOptions) -> Result<()> {
let engine: Arc<dyn IoEngine + Send + Sync>;
let nr_threads;
if opts.async_io {
nr_threads = std::cmp::min(4, num_cpus::get());
engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO)?);
} else {
eprintln!("falling back to synchronous io");
nr_threads = num_cpus::get() * 2;
engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads)?);
}
let now = Instant::now();
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;