From de172147d36b00c1314f77771a6a94b5a0ccdada Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Thu, 30 Jul 2020 10:12:51 +0100 Subject: [PATCH] [thin_check (rust)] squash a lot of warnings --- src/block_manager.rs | 4 +--- src/checksum.rs | 1 + src/thin/check.rs | 39 ++++++++------------------------------- src/thin/superblock.rs | 6 +++--- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/block_manager.rs b/src/block_manager.rs index ba8bf81..5abef18 100644 --- a/src/block_manager.rs +++ b/src/block_manager.rs @@ -1,12 +1,10 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use io_uring::opcode::{self, types}; use io_uring::IoUring; use std::alloc::{alloc, dealloc, Layout}; -use std::collections::HashMap; use std::fs::File; use std::fs::OpenOptions; use std::io; -use std::io::{Read, Seek}; use std::os::unix::fs::OpenOptionsExt; use std::os::unix::io::{AsRawFd, RawFd}; use std::path::Path; diff --git a/src/checksum.rs b/src/checksum.rs index 25d7205..9cb3b89 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -4,6 +4,7 @@ use crc32c::crc32c; use std::io::Cursor; const BLOCK_SIZE: u64 = 4096; +#[allow(dead_code)] const MAGIC: u64 = 0xa537a0aa6309ef77; const SUPERBLOCK_CSUM_XOR: u32 = 160774; const BITMAP_CSUM_XOR: u32 = 240779; diff --git a/src/thin/check.rs b/src/thin/check.rs index 58c5ee3..98b343d 100644 --- a/src/thin/check.rs +++ b/src/thin/check.rs @@ -1,16 +1,12 @@ use anyhow::{anyhow, Result}; use fixedbitset::FixedBitSet; -use futures::executor; -use nom::{bytes::complete::*, number::complete::*, IResult}; -use std::collections::HashSet; -use std::error::Error; +use nom::{number::complete::*, IResult}; use std::path::Path; use std::sync::{Arc, Mutex}; -use std::thread::{self, spawn}; -use std::time::{Duration, Instant}; +use std::time::Instant; use threadpool::ThreadPool; -use crate::block_manager::{AsyncIoEngine, Block, IoEngine, BLOCK_SIZE}; +use crate::block_manager::{AsyncIoEngine, Block, IoEngine}; use crate::checksum; use crate::thin::superblock::*; @@ -21,6 +17,7 @@ trait ValueType { fn unpack(data: &[u8]) -> IResult<&[u8], Self::Value>; } +#[allow(dead_code)] struct NodeHeader { is_leaf: bool, block: u64, @@ -29,6 +26,7 @@ struct NodeHeader { value_size: u32, } +#[allow(dead_code)] const INTERNAL_NODE: u32 = 1; const LEAF_NODE: u32 = 2; @@ -66,27 +64,6 @@ enum Node { }, } -impl Node { - fn get_header(&self) -> &NodeHeader { - match self { - Node::Internal { - header, - keys: _k, - values: _v, - } => &header, - Node::Leaf { - header, - keys: _k, - values: _v, - } => &header, - } - } - - fn is_leaf(&self) -> bool { - self.get_header().is_leaf - } -} - fn unpack_node_(data: &[u8]) -> IResult<&[u8], Node> { use nom::multi::count; @@ -215,6 +192,7 @@ impl BTreeWalker { //------------------------------------------ +#[allow(dead_code)] struct BlockTime { block: u64, time: u32, @@ -275,7 +253,7 @@ impl NodeVisitor for TopLevelVisitor { let mut w = w.clone(); pool.execute(move || { let mut v = BottomLevelVisitor {}; - w.walk_node(&mut v, &b); + w.walk_node(&mut v, &b).expect("walk failed"); // FIXME: return error eprintln!("checked thin_dev {}", thin_id); }); } @@ -308,10 +286,9 @@ pub fn check(dev: &Path) -> Result<()> { let mut root = Block::new(sb.mapping_root); engine.read(&mut root)?; - let mut seen = FixedBitSet::with_capacity(engine.get_nr_blocks() as usize); let mut w = BTreeWalker::new(engine); let mut visitor = TopLevelVisitor {}; - let result = w.walk_node(&mut visitor, &root)?; + let _result = w.walk_node(&mut visitor, &root)?; println!("read mapping tree in {} ms", now.elapsed().as_millis()); Ok(()) diff --git a/src/thin/superblock.rs b/src/thin/superblock.rs index f7c3546..e52d7f2 100644 --- a/src/thin/superblock.rs +++ b/src/thin/superblock.rs @@ -1,11 +1,9 @@ use crate::block_manager::*; -use crate::block_manager::*; -use crate::checksum::*; use anyhow::{anyhow, Result}; use nom::{bytes::complete::*, number::complete::*, IResult}; pub const SUPERBLOCK_LOCATION: u64 = 0; -const UUID_SIZE: usize = 16; +//const UUID_SIZE: usize = 16; const SPACE_MAP_ROOT_SIZE: usize = 128; #[derive(Debug)] @@ -23,6 +21,7 @@ pub struct Superblock { pub data_block_size: u32, } +/* pub enum CheckSeverity { Fatal, NonFatal, @@ -48,6 +47,7 @@ struct SuperblockError { severity: CheckSeverity, kind: ErrorType, } +*/ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> { let (i, _csum) = le_u32(data)?;