From 197e4ffbfdf674450a4a582fbbc7121d4679be19 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Wed, 5 Aug 2020 08:01:02 +0100 Subject: [PATCH] [thin_check (rust)] Rename ValueType trait to Unpack --- src/block_manager.rs | 3 ++- src/pdata/btree.rs | 18 +++++++++--------- src/thin/check.rs | 13 ++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/block_manager.rs b/src/block_manager.rs index 5abef18..7aebbaf 100644 --- a/src/block_manager.rs +++ b/src/block_manager.rs @@ -141,7 +141,8 @@ impl Clone for AsyncIoEngine { fn clone(&self) -> AsyncIoEngine { let inner = self.inner.lock().unwrap(); eprintln!("in clone, queue_len = {}", inner.queue_len); - AsyncIoEngine {inner: Mutex::new(AsyncIoEngine_ { + AsyncIoEngine { + inner: Mutex::new(AsyncIoEngine_ { queue_len: inner.queue_len, ring: IoUring::new(inner.queue_len).expect("couldn't create uring"), nr_blocks: inner.nr_blocks, diff --git a/src/pdata/btree.rs b/src/pdata/btree.rs index 3b07c63..00c8620 100644 --- a/src/pdata/btree.rs +++ b/src/pdata/btree.rs @@ -10,7 +10,7 @@ use crate::checksum; //------------------------------------------ -pub trait ValueType { +pub trait Unpack { // The size of the value when on disk. fn disk_size() -> u32; fn unpack(data: &[u8]) -> IResult<&[u8], Self> @@ -53,7 +53,7 @@ pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> { )) } -pub enum Node { +pub enum Node { Internal { header: NodeHeader, keys: Vec, @@ -79,7 +79,7 @@ pub fn to_any<'a, V>(r: IResult<&'a [u8], V>) -> Result<(&'a [u8], V)> { } } -pub fn unpack_node( +pub fn unpack_node( data: &[u8], ignore_non_fatal: bool, is_root: bool, @@ -154,7 +154,7 @@ pub fn unpack_node( //------------------------------------------ -impl ValueType for u64 { +impl Unpack for u64 { fn disk_size() -> u32 { 8 } @@ -166,7 +166,7 @@ impl ValueType for u64 { //------------------------------------------ -pub trait NodeVisitor { +pub trait NodeVisitor { fn visit<'a>(&mut self, w: &BTreeWalker, b: &Block, node: &Node) -> Result<()>; } @@ -208,7 +208,7 @@ impl BTreeWalker { fn walk_nodes(&mut self, visitor: &mut NV, bs: &Vec) -> Result<()> where NV: NodeVisitor, - V: ValueType, + V: Unpack, { let mut blocks = Vec::new(); let seen = self.seen.lock().unwrap(); @@ -231,7 +231,7 @@ impl BTreeWalker { fn walk_node(&mut self, visitor: &mut NV, b: &Block, is_root: bool) -> Result<()> where NV: NodeVisitor, - V: ValueType, + V: Unpack, { let mut seen = self.seen.lock().unwrap(); seen.insert(b.loc as usize); @@ -260,7 +260,7 @@ impl BTreeWalker { pub fn walk_b(&mut self, visitor: &mut NV, root: &Block) -> Result<()> where NV: NodeVisitor, - V: ValueType, + V: Unpack, { self.walk_node(visitor, &root, true) } @@ -268,7 +268,7 @@ impl BTreeWalker { pub fn walk(&mut self, visitor: &mut NV, root: u64) -> Result<()> where NV: NodeVisitor, - V: ValueType, + V: Unpack, { let mut root = Block::new(root); self.engine.read(&mut root)?; diff --git a/src/thin/check.rs b/src/thin/check.rs index 207b69f..3611248 100644 --- a/src/thin/check.rs +++ b/src/thin/check.rs @@ -8,7 +8,7 @@ use std::time::Instant; use threadpool::ThreadPool; 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::*; //------------------------------------------ @@ -18,7 +18,7 @@ struct TopLevelVisitor<'a> { } impl<'a> NodeVisitor for TopLevelVisitor<'a> { - fn visit(&mut self, w: &BTreeWalker, _b: &Block, node: &Node) -> Result<()> { + fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node) -> Result<()> { if let Node::Leaf { header: _h, keys, @@ -44,7 +44,7 @@ struct BlockTime { time: u32, } -impl ValueType for BlockTime { +impl Unpack for BlockTime { fn disk_size() -> u32 { 8 } @@ -82,7 +82,7 @@ struct DeviceDetail { snapshotted_time: u32, } -impl ValueType for DeviceDetail { +impl Unpack for DeviceDetail { fn disk_size() -> u32 { 24 } @@ -139,8 +139,7 @@ impl NodeVisitor for DeviceVisitor { //------------------------------------------ pub fn check(dev: &Path) -> Result<()> { - //let mut engine = SyncIoEngine::new(dev)?; - let mut engine = Arc::new(AsyncIoEngine::new(dev, 256)?); + let engine = Arc::new(AsyncIoEngine::new(dev, 256)?); let now = Instant::now(); let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?; @@ -165,7 +164,7 @@ pub fn check(dev: &Path) -> Result<()> { { let nr_workers = 4; 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, )));