From a88ae3ca188b6e21a93ba0c0d092bede63301eb7 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 25 Sep 2020 09:59:16 +0100 Subject: [PATCH] [thin_check (rust)] factor out device detail --- src/pdata/btree.rs | 14 +++++++++++++- src/thin/check.rs | 39 +++++++-------------------------------- src/thin/device_detail.rs | 37 +++++++++++++++++++++++++++++++++++++ src/thin/mod.rs | 1 + 4 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 src/thin/device_detail.rs diff --git a/src/pdata/btree.rs b/src/pdata/btree.rs index f455dd1..f491a66 100644 --- a/src/pdata/btree.rs +++ b/src/pdata/btree.rs @@ -549,6 +549,8 @@ pub trait NodeVisitor { keys: &[u64], values: &[V], ) -> Result<()>; + + fn end_walk(&self) -> Result<()>; } #[derive(Clone)] @@ -758,6 +760,7 @@ impl BTreeWalker { path.push(b.loc); let r = self.walk_node_(path, visitor, kr, b, is_root); path.pop(); + visitor.end_walk()?; r } @@ -843,8 +846,9 @@ where V: Unpack, { path.push(b.loc); - let r = walk_node_threaded_(w, path, pool, visitor, kr, b, is_root); + let r = walk_node_threaded_(w, path, pool, visitor.clone(), kr, b, is_root); path.pop(); + visitor.end_walk()?; r } @@ -992,6 +996,10 @@ impl NodeVisitor for ValueCollector { Ok(()) } + + fn end_walk(&self) -> Result<()> { + Ok(()) + } } pub fn btree_to_map( @@ -1051,6 +1059,10 @@ impl NodeVisitor for ValuePathCollector { Ok(()) } + + fn end_walk(&self) -> Result<()> { + Ok(()) + } } pub fn btree_to_map_with_path( diff --git a/src/thin/check.rs b/src/thin/check.rs index 9557fc3..71ce195 100644 --- a/src/thin/check.rs +++ b/src/thin/check.rs @@ -1,5 +1,4 @@ use anyhow::{anyhow, Result}; -use nom::{number::complete::*, IResult}; use std::collections::BTreeMap; use std::io::Cursor; use std::path::Path; @@ -14,6 +13,7 @@ use crate::pdata::space_map::*; use crate::pdata::unpack::*; use crate::report::*; use crate::thin::block_time::*; +use crate::thin::device_detail::*; use crate::thin::superblock::*; //------------------------------------------ @@ -58,38 +58,9 @@ impl NodeVisitor for BottomLevelVisitor { data_sm.inc(start, len).unwrap(); Ok(()) } -} -//------------------------------------------ - -#[derive(Clone, Copy)] -pub struct DeviceDetail { - pub mapped_blocks: u64, - pub transaction_id: u64, - pub creation_time: u32, - pub snapshotted_time: u32, -} - -impl Unpack for DeviceDetail { - fn disk_size() -> u32 { - 24 - } - - fn unpack(i: &[u8]) -> IResult<&[u8], DeviceDetail> { - let (i, mapped_blocks) = le_u64(i)?; - let (i, transaction_id) = le_u64(i)?; - let (i, creation_time) = le_u32(i)?; - let (i, snapshotted_time) = le_u32(i)?; - - Ok(( - i, - DeviceDetail { - mapped_blocks, - transaction_id, - creation_time, - snapshotted_time, - }, - )) + fn end_walk(&self) -> btree::Result<()> { + Ok(()) } } @@ -126,6 +97,10 @@ impl<'a> NodeVisitor for OverflowChecker<'a> { Ok(()) } + + fn end_walk(&self) -> btree::Result<()> { + Ok(()) + } } //------------------------------------------ diff --git a/src/thin/device_detail.rs b/src/thin/device_detail.rs new file mode 100644 index 0000000..332fbf7 --- /dev/null +++ b/src/thin/device_detail.rs @@ -0,0 +1,37 @@ +use crate::pdata::unpack::*; +use nom::{number::complete::*, IResult}; + +//------------------------------------------ + +#[derive(Clone, Copy)] +pub struct DeviceDetail { + pub mapped_blocks: u64, + pub transaction_id: u64, + pub creation_time: u32, + pub snapshotted_time: u32, +} + +impl Unpack for DeviceDetail { + fn disk_size() -> u32 { + 24 + } + + fn unpack(i: &[u8]) -> IResult<&[u8], DeviceDetail> { + let (i, mapped_blocks) = le_u64(i)?; + let (i, transaction_id) = le_u64(i)?; + let (i, creation_time) = le_u32(i)?; + let (i, snapshotted_time) = le_u32(i)?; + + Ok(( + i, + DeviceDetail { + mapped_blocks, + transaction_id, + creation_time, + snapshotted_time, + }, + )) + } +} + +//------------------------------------------ diff --git a/src/thin/mod.rs b/src/thin/mod.rs index 6506a0e..f5a4024 100644 --- a/src/thin/mod.rs +++ b/src/thin/mod.rs @@ -1,4 +1,5 @@ pub mod block_time; +pub mod device_detail; pub mod superblock; pub mod check; pub mod xml;