From bc058f8baf970eba793439b673fa71575ec5f7cb Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 18 Sep 2020 10:06:33 +0100 Subject: [PATCH] [thin_check (rust)] BTree values must now implement Copy --- src/bin/thin_explore.rs | 4 +++- src/pdata/btree.rs | 29 +++++++++++++++++++++++++---- src/pdata/space_map.rs | 2 +- src/thin/check.rs | 29 ++--------------------------- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/bin/thin_explore.rs b/src/bin/thin_explore.rs index 58edfe5..058c065 100644 --- a/src/bin/thin_explore.rs +++ b/src/bin/thin_explore.rs @@ -634,7 +634,9 @@ fn explore(path: &Path) -> Result<()> { panels.push(Box::new(BottomLevelPanel::new(thin_id, node))); } Some(Action::PopPanel) => { - panels.pop(); + if panels.len() > 2 { + panels.pop(); + } } _ => {} }, diff --git a/src/pdata/btree.rs b/src/pdata/btree.rs index c33bdc5..11fde20 100644 --- a/src/pdata/btree.rs +++ b/src/pdata/btree.rs @@ -313,7 +313,7 @@ pub type Result = std::result::Result; //------------------------------------------ -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct NodeHeader { pub block: u64, pub is_leaf: bool, @@ -824,7 +824,8 @@ impl ValueCollector { } } -impl NodeVisitor for ValueCollector { +// FIXME: should we be using Copy rather than clone? (Yes) +impl NodeVisitor for ValueCollector { fn visit(&self, _kr: &KeyRange, _h: &NodeHeader, keys: &[u64], values: &[V]) -> Result<()> { let mut vals = self.values.lock().unwrap(); for n in 0..keys.len() { @@ -835,7 +836,7 @@ impl NodeVisitor for ValueCollector { } } -pub fn btree_to_map( +pub fn btree_to_map( engine: Arc, ignore_non_fatal: bool, root: u64, @@ -846,7 +847,7 @@ pub fn btree_to_map( Ok(visitor.values.into_inner().unwrap()) } -pub fn btree_to_map_with_sm( +pub fn btree_to_map_with_sm( engine: Arc, sm: Arc>, ignore_non_fatal: bool, @@ -860,3 +861,23 @@ pub fn btree_to_map_with_sm( } //------------------------------------------ + +/* +struct ValuePathCollector { + values: Mutex, V)>> +} + +impl ValuePathCollector { + fn new() -> ValuePathCollector { + ValuePathCollector { + values: Mutex::new(BTreeMap::new()), + } + } +} + +impl NodeVisitor for ValueCollector { + +} +*/ + +//------------------------------------------ diff --git a/src/pdata/space_map.rs b/src/pdata/space_map.rs index 40c60ef..6fd52fd 100644 --- a/src/pdata/space_map.rs +++ b/src/pdata/space_map.rs @@ -49,7 +49,7 @@ impl Unpack for SMRoot { //------------------------------------------ -#[derive(Clone, Debug)] +#[derive(Clone, Copy, Debug)] pub struct IndexEntry { pub blocknr: u64, pub nr_free: u32, diff --git a/src/thin/check.rs b/src/thin/check.rs index 5548375..2cac626 100644 --- a/src/thin/check.rs +++ b/src/thin/check.rs @@ -14,35 +14,10 @@ use crate::pdata::space_map::*; use crate::pdata::unpack::*; use crate::report::*; use crate::thin::superblock::*; +use crate::thin::block_time::*; //------------------------------------------ -#[allow(dead_code)] -struct BlockTime { - block: u64, - time: u32, -} - -impl Unpack for BlockTime { - fn disk_size() -> u32 { - 8 - } - - fn unpack(i: &[u8]) -> IResult<&[u8], BlockTime> { - let (i, n) = le_u64(i)?; - let block = n >> 24; - let time = n & ((1 << 24) - 1); - - Ok(( - i, - BlockTime { - block, - time: time as u32, - }, - )) - } -} - struct BottomLevelVisitor { data_sm: ASpaceMap, } @@ -80,7 +55,7 @@ impl NodeVisitor for BottomLevelVisitor { //------------------------------------------ -#[derive(Clone)] +#[derive(Clone, Copy)] struct DeviceDetail { mapped_blocks: u64, transaction_id: u64,