[thin_check (rust)] Rename ValueType trait to Unpack

This commit is contained in:
Joe Thornber 2020-08-05 08:01:02 +01:00
parent 1d44025584
commit 197e4ffbfd
3 changed files with 17 additions and 17 deletions

View File

@ -141,7 +141,8 @@ impl Clone for AsyncIoEngine {
fn clone(&self) -> AsyncIoEngine { fn clone(&self) -> AsyncIoEngine {
let inner = self.inner.lock().unwrap(); let inner = self.inner.lock().unwrap();
eprintln!("in clone, queue_len = {}", inner.queue_len); eprintln!("in clone, queue_len = {}", inner.queue_len);
AsyncIoEngine {inner: Mutex::new(AsyncIoEngine_ { AsyncIoEngine {
inner: Mutex::new(AsyncIoEngine_ {
queue_len: inner.queue_len, queue_len: inner.queue_len,
ring: IoUring::new(inner.queue_len).expect("couldn't create uring"), ring: IoUring::new(inner.queue_len).expect("couldn't create uring"),
nr_blocks: inner.nr_blocks, nr_blocks: inner.nr_blocks,

View File

@ -10,7 +10,7 @@ use crate::checksum;
//------------------------------------------ //------------------------------------------
pub trait ValueType { pub trait Unpack {
// The size of the value when on disk. // The size of the value when on disk.
fn disk_size() -> u32; fn disk_size() -> u32;
fn unpack(data: &[u8]) -> IResult<&[u8], Self> fn unpack(data: &[u8]) -> IResult<&[u8], Self>
@ -53,7 +53,7 @@ pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
)) ))
} }
pub enum Node<V: ValueType> { pub enum Node<V: Unpack> {
Internal { Internal {
header: NodeHeader, header: NodeHeader,
keys: Vec<u64>, keys: Vec<u64>,
@ -79,7 +79,7 @@ pub fn to_any<'a, V>(r: IResult<&'a [u8], V>) -> Result<(&'a [u8], V)> {
} }
} }
pub fn unpack_node<V: ValueType>( pub fn unpack_node<V: Unpack>(
data: &[u8], data: &[u8],
ignore_non_fatal: bool, ignore_non_fatal: bool,
is_root: bool, is_root: bool,
@ -154,7 +154,7 @@ pub fn unpack_node<V: ValueType>(
//------------------------------------------ //------------------------------------------
impl ValueType for u64 { impl Unpack for u64 {
fn disk_size() -> u32 { fn disk_size() -> u32 {
8 8
} }
@ -166,7 +166,7 @@ impl ValueType for u64 {
//------------------------------------------ //------------------------------------------
pub trait NodeVisitor<V: ValueType> { pub trait NodeVisitor<V: Unpack> {
fn visit<'a>(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>; fn visit<'a>(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>;
} }
@ -208,7 +208,7 @@ impl BTreeWalker {
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()> fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()>
where where
NV: NodeVisitor<V>, NV: NodeVisitor<V>,
V: ValueType, V: Unpack,
{ {
let mut blocks = Vec::new(); let mut blocks = Vec::new();
let seen = self.seen.lock().unwrap(); let seen = self.seen.lock().unwrap();
@ -231,7 +231,7 @@ impl BTreeWalker {
fn walk_node<NV, V>(&mut self, visitor: &mut NV, b: &Block, is_root: bool) -> Result<()> fn walk_node<NV, V>(&mut self, visitor: &mut NV, b: &Block, is_root: bool) -> Result<()>
where where
NV: NodeVisitor<V>, NV: NodeVisitor<V>,
V: ValueType, V: Unpack,
{ {
let mut seen = self.seen.lock().unwrap(); let mut seen = self.seen.lock().unwrap();
seen.insert(b.loc as usize); seen.insert(b.loc as usize);
@ -260,7 +260,7 @@ impl BTreeWalker {
pub fn walk_b<NV, V>(&mut self, visitor: &mut NV, root: &Block) -> Result<()> pub fn walk_b<NV, V>(&mut self, visitor: &mut NV, root: &Block) -> Result<()>
where where
NV: NodeVisitor<V>, NV: NodeVisitor<V>,
V: ValueType, V: Unpack,
{ {
self.walk_node(visitor, &root, true) self.walk_node(visitor, &root, true)
} }
@ -268,7 +268,7 @@ impl BTreeWalker {
pub fn walk<NV, V>(&mut self, visitor: &mut NV, root: u64) -> Result<()> pub fn walk<NV, V>(&mut self, visitor: &mut NV, root: u64) -> Result<()>
where where
NV: NodeVisitor<V>, NV: NodeVisitor<V>,
V: ValueType, V: Unpack,
{ {
let mut root = Block::new(root); let mut root = Block::new(root);
self.engine.read(&mut root)?; self.engine.read(&mut root)?;

View File

@ -8,7 +8,7 @@ use std::time::Instant;
use threadpool::ThreadPool; use threadpool::ThreadPool;
use crate::block_manager::{AsyncIoEngine, Block, IoEngine}; use crate::block_manager::{AsyncIoEngine, Block, IoEngine};
use crate::pdata::btree::{BTreeWalker, Node, NodeVisitor, ValueType}; use crate::pdata::btree::{BTreeWalker, Node, NodeVisitor, Unpack};
use crate::thin::superblock::*; use crate::thin::superblock::*;
//------------------------------------------ //------------------------------------------
@ -18,7 +18,7 @@ struct TopLevelVisitor<'a> {
} }
impl<'a> NodeVisitor<u64> for TopLevelVisitor<'a> { impl<'a> NodeVisitor<u64> for TopLevelVisitor<'a> {
fn visit(&mut self, w: &BTreeWalker, _b: &Block, node: &Node<u64>) -> Result<()> { fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<u64>) -> Result<()> {
if let Node::Leaf { if let Node::Leaf {
header: _h, header: _h,
keys, keys,
@ -44,7 +44,7 @@ struct BlockTime {
time: u32, time: u32,
} }
impl ValueType for BlockTime { impl Unpack for BlockTime {
fn disk_size() -> u32 { fn disk_size() -> u32 {
8 8
} }
@ -82,7 +82,7 @@ struct DeviceDetail {
snapshotted_time: u32, snapshotted_time: u32,
} }
impl ValueType for DeviceDetail { impl Unpack for DeviceDetail {
fn disk_size() -> u32 { fn disk_size() -> u32 {
24 24
} }
@ -139,8 +139,7 @@ impl NodeVisitor<DeviceDetail> for DeviceVisitor {
//------------------------------------------ //------------------------------------------
pub fn check(dev: &Path) -> Result<()> { pub fn check(dev: &Path) -> Result<()> {
//let mut engine = SyncIoEngine::new(dev)?; let engine = Arc::new(AsyncIoEngine::new(dev, 256)?);
let mut engine = Arc::new(AsyncIoEngine::new(dev, 256)?);
let now = Instant::now(); let now = Instant::now();
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?; let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;
@ -165,7 +164,7 @@ pub fn check(dev: &Path) -> Result<()> {
{ {
let nr_workers = 4; let nr_workers = 4;
let pool = ThreadPool::new(nr_workers); let pool = ThreadPool::new(nr_workers);
let mut seen = Arc::new(Mutex::new(FixedBitSet::with_capacity( let seen = Arc::new(Mutex::new(FixedBitSet::with_capacity(
engine.get_nr_blocks() as usize, engine.get_nr_blocks() as usize,
))); )));