[thin_check (rust)] Get SyncIoEngine working again.

This commit is contained in:
Joe Thornber 2020-08-10 08:59:02 +01:00
parent 08e3ea948e
commit f0df17af9e
4 changed files with 20 additions and 17 deletions

View File

@ -4,7 +4,7 @@ use io_uring::IoUring;
use std::alloc::{alloc, dealloc, Layout};
use std::fs::File;
use std::fs::OpenOptions;
use std::io;
use std::io::{self, Seek, Read};
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::Path;
@ -60,10 +60,9 @@ fn get_nr_blocks(path: &Path) -> io::Result<u64> {
//------------------------------------------
/*
pub struct SyncIoEngine {
nr_blocks: u64,
input: File,
input: Mutex<File>,
}
impl SyncIoEngine {
@ -76,7 +75,7 @@ impl SyncIoEngine {
Ok(SyncIoEngine {
nr_blocks: get_nr_blocks(path)?,
input,
input: Mutex::new(input),
})
}
}
@ -86,23 +85,26 @@ impl IoEngine for SyncIoEngine {
self.nr_blocks
}
fn read(&mut self, b: &mut Block) -> Result<()> {
self.input
.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
self.input.read_exact(&mut b.get_data())?;
fn read(&self, b: &mut Block) -> Result<()> {
let mut input = self.input.lock().unwrap();
input.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
input.read_exact(&mut b.get_data())?;
Ok(())
}
fn read_many(&mut self, blocks: &mut Vec<Block>) -> Result<()> {
fn read_many(&self, blocks: &mut Vec<Block>) -> Result<()> {
let mut input = self.input.lock().unwrap();
for b in blocks {
self.read(b);
input.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
input.read_exact(&mut b.get_data())?;
}
Ok(())
}
}
*/
//------------------------------------------
pub struct AsyncIoEngine_ {

View File

@ -189,13 +189,13 @@ pub trait NodeVisitor<V: Unpack> {
#[derive(Clone)]
pub struct BTreeWalker {
pub engine: Arc<AsyncIoEngine>,
pub engine: Arc<dyn IoEngine + Send + Sync>,
pub seen: Arc<Mutex<FixedBitSet>>,
ignore_non_fatal: bool,
}
impl BTreeWalker {
pub fn new(engine: Arc<AsyncIoEngine>, ignore_non_fatal: bool) -> BTreeWalker {
pub fn new(engine: Arc<dyn IoEngine + Send + Sync>, ignore_non_fatal: bool) -> BTreeWalker {
let nr_blocks = engine.get_nr_blocks() as usize;
let r: BTreeWalker = BTreeWalker {
engine,
@ -206,7 +206,7 @@ impl BTreeWalker {
}
pub fn new_with_seen(
engine: Arc<AsyncIoEngine>,
engine: Arc<dyn IoEngine + Send + Sync>,
seen: Arc<Mutex<FixedBitSet>>,
ignore_non_fatal: bool,
) -> BTreeWalker {

View File

@ -7,7 +7,7 @@ use std::sync::{Arc, Mutex};
use std::time::Instant;
use threadpool::ThreadPool;
use crate::io_engine::{AsyncIoEngine, Block, IoEngine};
use crate::io_engine::{AsyncIoEngine, SyncIoEngine, Block, IoEngine};
use crate::checksum;
use crate::pdata::btree::{unpack, BTreeWalker, Node, NodeVisitor, Unpack};
use crate::pdata::space_map::*;
@ -265,7 +265,8 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
const MAX_CONCURRENT_IO: u32 = 1024;
pub fn check(dev: &Path) -> Result<()> {
let engine = Arc::new(AsyncIoEngine::new(dev, MAX_CONCURRENT_IO)?);
//let engine = Arc::new(AsyncIoEngine::new(dev, MAX_CONCURRENT_IO)?);
let engine: Arc<dyn IoEngine + Send + Sync> = Arc::new(SyncIoEngine::new(dev)?);
let now = Instant::now();
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;

View File

@ -85,7 +85,7 @@ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
))
}
pub fn read_superblock<E: IoEngine>(engine: &E, loc: u64) -> Result<Superblock> {
pub fn read_superblock(engine: &dyn IoEngine, loc: u64) -> Result<Superblock> {
let mut b = Block::new(loc);
engine.read(&mut b)?;