diff --git a/src/bin/thin_check.rs b/src/bin/thin_check.rs index b7fbad9..f353f86 100644 --- a/src/bin/thin_check.rs +++ b/src/bin/thin_check.rs @@ -97,8 +97,7 @@ fn main() { report = Arc::new(mk_simple_report()); } - if matches.is_present("SYNC_IO") && - matches.is_present("ASYNC_IO") { + if matches.is_present("SYNC_IO") && matches.is_present("ASYNC_IO") { eprintln!("--sync-io and --async-io may not be used at the same time."); process::exit(1); } diff --git a/src/cache/check.rs b/src/cache/check.rs index 92895e1..265b505 100644 --- a/src/cache/check.rs +++ b/src/cache/check.rs @@ -1,13 +1,13 @@ use anyhow::anyhow; +use std::collections::*; use std::marker::PhantomData; use std::path::Path; use std::sync::{Arc, Mutex}; -use std::collections::*; -use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine}; use crate::cache::hint::*; use crate::cache::mapping::*; use crate::cache::superblock::*; +use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine}; use crate::pdata::array_walker::*; //------------------------------------------ @@ -112,19 +112,13 @@ fn mk_context(opts: &CacheCheckOptions) -> anyhow::Result { let engine: Arc; if opts.async_io { - engine = Arc::new(AsyncIoEngine::new( - opts.dev, - MAX_CONCURRENT_IO, - false, - )?); + engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO, false)?); } else { let nr_threads = std::cmp::max(8, num_cpus::get() * 2); engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads, false)?); } - Ok(Context { - engine, - }) + Ok(Context { engine }) } pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> { @@ -145,7 +139,7 @@ pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> { w.walk(c, sb.mapping_root)?; if sb.version >= 2 { - // TODO: check dirty bitset + // TODO: check dirty bitset } } diff --git a/src/cache/hint.rs b/src/cache/hint.rs index ef0d83f..ea7f2d3 100644 --- a/src/cache/hint.rs +++ b/src/cache/hint.rs @@ -1,6 +1,6 @@ use nom::IResult; -use std::marker::PhantomData; use std::convert::TryInto; +use std::marker::PhantomData; use crate::pdata::unpack::*; diff --git a/src/cache/mapping.rs b/src/cache/mapping.rs index c18325a..4370937 100644 --- a/src/cache/mapping.rs +++ b/src/cache/mapping.rs @@ -1,5 +1,5 @@ -use nom::IResult; use nom::number::complete::*; +use nom::IResult; use crate::pdata::unpack::*; @@ -26,7 +26,6 @@ impl Mapping { } } - impl Unpack for Mapping { fn disk_size() -> u32 { 8 diff --git a/src/cache/xml.rs b/src/cache/xml.rs index d39b057..e811b67 100644 --- a/src/cache/xml.rs +++ b/src/cache/xml.rs @@ -100,7 +100,8 @@ impl MetadataVisitor for XmlWriter { } fn superblock_e(&mut self) -> Result { - self.w.write_event(Event::End(BytesEnd::borrowed(b"superblock")))?; + self.w + .write_event(Event::End(BytesEnd::borrowed(b"superblock")))?; Ok(Visit::Continue) } @@ -112,10 +113,11 @@ impl MetadataVisitor for XmlWriter { } fn mappings_e(&mut self) -> Result { - self.w.write_event(Event::End(BytesEnd::borrowed(b"mappings")))?; + self.w + .write_event(Event::End(BytesEnd::borrowed(b"mappings")))?; Ok(Visit::Continue) } - + fn mapping(&mut self, m: &Map) -> Result { let tag = b"map"; let mut elem = BytesStart::owned(tag.to_vec(), tag.len()); @@ -132,12 +134,13 @@ impl MetadataVisitor for XmlWriter { self.w.write_event(Event::Start(elem))?; Ok(Visit::Continue) } - + fn hints_e(&mut self) -> Result { - self.w.write_event(Event::End(BytesEnd::borrowed(b"hints")))?; + self.w + .write_event(Event::End(BytesEnd::borrowed(b"hints")))?; Ok(Visit::Continue) } - + fn hint(&mut self, h: &Hint) -> Result { let tag = b"hint"; let mut elem = BytesStart::owned(tag.to_vec(), tag.len()); @@ -153,12 +156,13 @@ impl MetadataVisitor for XmlWriter { self.w.write_event(Event::Start(elem))?; Ok(Visit::Continue) } - + fn discards_e(&mut self) -> Result { - self.w.write_event(Event::End(BytesEnd::borrowed(b"discards")))?; + self.w + .write_event(Event::End(BytesEnd::borrowed(b"discards")))?; Ok(Visit::Continue) } - + fn discard(&mut self, d: &Discard) -> Result { let tag = b"discard"; let mut elem = BytesStart::owned(tag.to_vec(), tag.len()); @@ -172,4 +176,3 @@ impl MetadataVisitor for XmlWriter { Ok(Visit::Continue) } } - diff --git a/src/checksum.rs b/src/checksum.rs index edb5e0a..675e6da 100644 --- a/src/checksum.rs +++ b/src/checksum.rs @@ -55,9 +55,11 @@ pub fn write_checksum(buf: &mut [u8], kind: BT) -> Result<()> { NODE => BTREE_CSUM_XOR, BITMAP => BITMAP_CSUM_XOR, INDEX => INDEX_CSUM_XOR, - UNKNOWN => {return Err(anyhow!("Invalid block type"));} + UNKNOWN => { + return Err(anyhow!("Invalid block type")); + } }; - + let csum = checksum(buf) ^ salt; let mut out = std::io::Cursor::new(buf); out.write_u32::(csum)?; diff --git a/src/pack/delta_list.rs b/src/pack/delta_list.rs index bd14330..882e57d 100644 --- a/src/pack/delta_list.rs +++ b/src/pack/delta_list.rs @@ -12,7 +12,7 @@ use Delta::*; pub fn to_delta(ns: &[u64]) -> Vec { use std::cmp::Ordering::*; - + let mut ds = Vec::with_capacity(ns.len()); if !ns.is_empty() { @@ -31,10 +31,7 @@ pub fn to_delta(ns: &[u64]) -> Vec { count += 1; } count -= 1; - ds.push(Neg { - delta, - count, - }); + ds.push(Neg { delta, count }); base -= delta * count; } Equal => { @@ -54,10 +51,7 @@ pub fn to_delta(ns: &[u64]) -> Vec { count += 1; } count -= 1; - ds.push(Pos { - delta, - count, - }); + ds.push(Pos { delta, count }); base += delta * count; } } diff --git a/src/pdata/array.rs b/src/pdata/array.rs index d8299c2..b9e109d 100644 --- a/src/pdata/array.rs +++ b/src/pdata/array.rs @@ -21,12 +21,7 @@ impl Unpack for ArrayBlockEntry { let (i, n) = le_u64(i)?; let block = n; - Ok(( - i, - ArrayBlockEntry { - block, - } - )) + Ok((i, ArrayBlockEntry { block })) } } diff --git a/src/pdata/array_block.rs b/src/pdata/array_block.rs index 0cf7069..50da5dd 100644 --- a/src/pdata/array_block.rs +++ b/src/pdata/array_block.rs @@ -33,7 +33,7 @@ impl Unpack for ArrayBlockHeader { max_entries, nr_entries, value_size, - blocknr + blocknr, }, )) } @@ -54,17 +54,13 @@ fn convert_result<'a, V>(r: IResult<&'a [u8], V>) -> Result<(&'a [u8], V)> { r.map_err(|_| anyhow!("parse error")) } -pub fn unpack_array_block( - data: &[u8], -) -> Result> { +pub fn unpack_array_block(data: &[u8]) -> Result> { // TODO: collect errors - let (i, header) = ArrayBlockHeader::unpack(data).map_err(|_e| anyhow!("Couldn't parse header"))?; + let (i, header) = + ArrayBlockHeader::unpack(data).map_err(|_e| anyhow!("Couldn't parse header"))?; let (_i, values) = convert_result(count(V::unpack, header.nr_entries as usize)(i))?; - Ok(ArrayBlock { - header, - values, - }) + Ok(ArrayBlock { header, values }) } //------------------------------------------ diff --git a/src/pdata/array_walker.rs b/src/pdata/array_walker.rs index e8287b1..6aabc82 100644 --- a/src/pdata/array_walker.rs +++ b/src/pdata/array_walker.rs @@ -11,16 +11,12 @@ use crate::pdata::unpack::*; pub struct ArrayWalker { engine: Arc, - ignore_non_fatal: bool + ignore_non_fatal: bool, } // FIXME: define another Result type for array visiting? pub trait ArrayBlockVisitor { - fn visit( - &self, - index: u64, - v: V, - ) -> anyhow::Result<()>; + fn visit(&self, index: u64, v: V) -> anyhow::Result<()>; } struct BlockValueVisitor { @@ -39,14 +35,12 @@ impl BlockValueVisitor { } } - pub fn visit_array_block( - &self, - index: u64, - array_block: ArrayBlock, - ) { + pub fn visit_array_block(&self, index: u64, array_block: ArrayBlock) { let begin = index * u64::from(array_block.header.nr_entries); for i in 0..array_block.header.nr_entries { - self.array_block_visitor.visit(begin + u64::from(i), array_block.values[i as usize]).unwrap(); + self.array_block_visitor + .visit(begin + u64::from(i), array_block.values[i as usize]) + .unwrap(); } } } @@ -63,7 +57,10 @@ impl NodeVisitor for BlockValueVisitor { ) -> Result<()> { for n in 0..keys.len() { let index = keys[n]; - let b = self.engine.read(values[n].block).map_err(|_| io_err(path))?; + let b = self + .engine + .read(values[n].block) + .map_err(|_| io_err(path))?; let array_block = unpack_array_block::(b.get_data()).map_err(|_| io_err(path))?; self.visit_array_block(index, array_block); } diff --git a/src/pdata/btree_builder.rs b/src/pdata/btree_builder.rs index d11e9f4..93242bc 100644 --- a/src/pdata/btree_builder.rs +++ b/src/pdata/btree_builder.rs @@ -24,9 +24,15 @@ pub trait RefCounter { pub struct NoopRC {} impl RefCounter for NoopRC { - fn get(&self, _v: &Value) -> Result {Ok(0)} - fn inc(&mut self, _v: &Value) -> Result<()> {Ok(())} - fn dec(&mut self, _v: &Value) -> Result<()> {Ok(())} + fn get(&self, _v: &Value) -> Result { + Ok(0) + } + fn inc(&mut self, _v: &Value) -> Result<()> { + Ok(()) + } + fn dec(&mut self, _v: &Value) -> Result<()> { + Ok(()) + } } /// Wraps a space map up to become a RefCounter. @@ -150,11 +156,7 @@ fn write_node_(w: &mut WriteBatcher, mut node: Node) -> Res /// decide if it produces internal or leaf nodes. pub trait NodeIO { fn write(&self, w: &mut WriteBatcher, keys: Vec, values: Vec) -> Result; - fn read( - &self, - w: &mut WriteBatcher, - block: u64, - ) -> Result<(Vec, Vec)>; + fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec, Vec)>; } pub struct LeafIO {} @@ -178,11 +180,7 @@ impl NodeIO for LeafIO { write_node_(w, node) } - fn read( - &self, - w: &mut WriteBatcher, - block: u64, - ) -> Result<(Vec, Vec)> { + fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec, Vec)> { let b = w.read(block)?; let path = Vec::new(); match unpack_node::(&path, b.get_data(), true, true)? { @@ -215,11 +213,7 @@ impl NodeIO for InternalIO { write_node_(w, node) } - fn read( - &self, - w: &mut WriteBatcher, - block: u64, - ) -> Result<(Vec, Vec)> { + fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec, Vec)> { let b = w.read(block)?; let path = Vec::new(); match unpack_node::(&path, b.get_data(), true, true)? { @@ -261,10 +255,7 @@ pub struct NodeSummary { impl<'a, V: Pack + Unpack + Clone> NodeBuilder { /// Create a new NodeBuilder - pub fn new( - nio: Box>, - value_rc: Box>, - ) -> Self { + pub fn new(nio: Box>, value_rc: Box>) -> Self { NodeBuilder { nio, value_rc, @@ -356,7 +347,7 @@ impl<'a, V: Pack + Unpack + Clone> NodeBuilder { if self.nodes.len() == 0 { self.emit_empty_leaf(w)? } - + Ok(self.nodes) } @@ -460,14 +451,9 @@ pub struct Builder { } impl Builder { - pub fn new( - value_rc: Box>, - ) -> Builder { + pub fn new(value_rc: Box>) -> Builder { Builder { - leaf_builder: NodeBuilder::new( - Box::new(LeafIO {}), - value_rc, - ), + leaf_builder: NodeBuilder::new(Box::new(LeafIO {}), value_rc), } } @@ -487,9 +473,7 @@ impl Builder { while nodes.len() > 1 { let mut builder = NodeBuilder::new( Box::new(InternalIO {}), - Box::new(SMRefCounter { - sm: w.sm.clone(), - }), + Box::new(SMRefCounter { sm: w.sm.clone() }), ); for n in nodes { @@ -505,4 +489,3 @@ impl Builder { } //------------------------------------------ - diff --git a/src/pdata/mod.rs b/src/pdata/mod.rs index 70d5d39..d277f7d 100644 --- a/src/pdata/mod.rs +++ b/src/pdata/mod.rs @@ -3,10 +3,9 @@ pub mod array_block; pub mod array_walker; pub mod btree; pub mod btree_builder; -pub mod btree_merge; pub mod btree_leaf_walker; +pub mod btree_merge; pub mod btree_walker; pub mod space_map; pub mod space_map_disk; pub mod unpack; - diff --git a/src/pdata/space_map_disk.rs b/src/pdata/space_map_disk.rs index b89de29..da2301e 100644 --- a/src/pdata/space_map_disk.rs +++ b/src/pdata/space_map_disk.rs @@ -1,8 +1,8 @@ use anyhow::{anyhow, Result}; use byteorder::{LittleEndian, WriteBytesExt}; use nom::{number::complete::*, IResult}; -use std::io::Cursor; use std::collections::BTreeMap; +use std::io::Cursor; use crate::checksum; use crate::io_engine::*; @@ -299,7 +299,7 @@ pub fn write_common(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<(Vec Result { let (index_entries, ref_count_root) = write_common(w, sm)?; - + let mut index_builder: Builder = Builder::new(Box::new(NoopRC {})); for (i, ie) in index_entries.iter().enumerate() { index_builder.push_value(w, i as u64, *ie)?; @@ -340,7 +340,7 @@ fn adjust_counts(w: &mut WriteBatcher, ie: &IndexEntry, allocs: &[u64]) -> Resul if bitmap.entries[*a as usize] == Small(0) { nr_free -= 1; } - + bitmap.entries[*a as usize] = Small(1); } @@ -350,7 +350,7 @@ fn adjust_counts(w: &mut WriteBatcher, ie: &IndexEntry, allocs: &[u64]) -> Resul w.write(bitmap_block, checksum::BT::BITMAP)?; // Return the adjusted index entry - Ok (IndexEntry { + Ok(IndexEntry { blocknr: ie.blocknr, nr_free, none_free_before: first_free, @@ -381,7 +381,7 @@ pub fn write_metadata_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result Report { Report::new(Box::new(PBInner { - title: "".to_string(), + title: "".to_string(), bar: ProgressBar::new(100), })) } diff --git a/src/shrink/copier.rs b/src/shrink/copier.rs index 1be1f2a..7e29181 100644 --- a/src/shrink/copier.rs +++ b/src/shrink/copier.rs @@ -1,7 +1,7 @@ use anyhow::Result; use std::fs::OpenOptions; +use std::io::{Read, Seek, SeekFrom, Write}; use std::path::Path; -use std::io::{Seek, SeekFrom, Write, Read}; //use std::os::unix::fs::OpenOptionsExt; pub type Sector = u64; @@ -13,7 +13,6 @@ pub struct Region { pub len: Sector, } - fn copy_step(file: &mut W, src_byte: u64, dest_byte: u64, len: usize) -> Result<()> where W: Write + Seek + Read, @@ -38,7 +37,12 @@ where let mut written = 0; while written != len_bytes { let step = u64::min(len_bytes - written, MAX_BYTES); - copy_step(file, src_bytes + written, dest_bytes + written, step as usize)?; + copy_step( + file, + src_bytes + written, + dest_bytes + written, + step as usize, + )?; written += step; } Ok(()) diff --git a/src/thin/dump.rs b/src/thin/dump.rs index f12a57a..db89b6e 100644 --- a/src/thin/dump.rs +++ b/src/thin/dump.rs @@ -298,7 +298,7 @@ fn find_shared_nodes( } } -/* + /* // FIXME: why?!! // we're not interested in leaves (roots will get re-added later). { @@ -620,7 +620,7 @@ pub fn dump(opts: ThinDumpOptions) -> Result<()> { let sb = read_superblock(ctx.engine.as_ref(), SUPERBLOCK_LOCATION)?; let md = build_metadata(&ctx, &sb)?; -/* + /* ctx.report .set_title("Optimising metadata to improve leaf packing"); let md = optimise_metadata(md)?; diff --git a/src/thin/superblock.rs b/src/thin/superblock.rs index 3b29b5c..db7074c 100644 --- a/src/thin/superblock.rs +++ b/src/thin/superblock.rs @@ -4,8 +4,8 @@ use nom::{bytes::complete::*, number::complete::*, IResult}; use std::fmt; use std::io::Cursor; -use crate::io_engine::*; use crate::checksum::*; +use crate::io_engine::*; //---------------------------------------- @@ -116,14 +116,14 @@ fn pack_superblock(sb: &Superblock, w: &mut W) -> Result<()> { w.write_u32::(sb.time)?; w.write_u64::(sb.transaction_id)?; w.write_u64::(sb.metadata_snap)?; - w.write_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // data sm root - w.write_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // metadata sm root + w.write_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // data sm root + w.write_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // metadata sm root w.write_u64::(sb.mapping_root)?; w.write_u64::(sb.details_root)?; w.write_u32::(sb.data_block_size)?; w.write_u32::(BLOCK_SIZE as u32)?; w.write_u64::(sb.nr_metadata_blocks)?; - + Ok(()) } @@ -138,7 +138,7 @@ pub fn write_superblock(engine: &dyn IoEngine, _loc: u64, sb: &Superblock) -> Re // calculate the checksum write_checksum(b.get_data(), BT::SUPERBLOCK)?; - + // write engine.write(&b)?; Ok(()) diff --git a/src/thin/xml.rs b/src/thin/xml.rs index a15df16..0cdf7b4 100644 --- a/src/thin/xml.rs +++ b/src/thin/xml.rs @@ -262,16 +262,14 @@ fn parse_superblock(e: &BytesStart) -> Result { fn parse_def(e: &BytesStart, tag: &str) -> Result { let mut name: Option = None; - + for a in e.attributes() { let kv = a.unwrap(); match kv.key { b"name" => { name = Some(string_val(&kv)); - }, - _ => { - return bad_attr(tag, kv.key) } + _ => return bad_attr(tag, kv.key), } } diff --git a/src/write_batcher.rs b/src/write_batcher.rs index 3256b91..b911be5 100644 --- a/src/write_batcher.rs +++ b/src/write_batcher.rs @@ -74,7 +74,9 @@ impl WriteBatcher { } } - self.engine.read(blocknr).map_err(|_| anyhow!("read block error")) + self.engine + .read(blocknr) + .map_err(|_| anyhow!("read block error")) } pub fn flush_(&mut self, queue: Vec) -> Result<()> { diff --git a/tests/cache_check.rs b/tests/cache_check.rs index 3fb9668..8d92e5d 100644 --- a/tests/cache_check.rs +++ b/tests/cache_check.rs @@ -1,11 +1,11 @@ use anyhow::Result; -use thinp::version::TOOLS_VERSION; use duct::cmd; +use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ @@ -88,7 +88,7 @@ fn failing_q() -> Result<()> { assert_eq!(output.stderr.len(), 0); Ok(()) } - + #[test] fn failing_quiet() -> Result<()> { let mut td = TestDir::new()?; diff --git a/tests/common/cache_xml_generator.rs b/tests/common/cache_xml_generator.rs index d9e558e..f7ebcdb 100644 --- a/tests/common/cache_xml_generator.rs +++ b/tests/common/cache_xml_generator.rs @@ -1,4 +1,4 @@ -use anyhow::{Result}; +use anyhow::Result; use rand::prelude::*; use std::collections::HashSet; use std::fs::OpenOptions; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b139090..f9caffd 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -4,14 +4,14 @@ use anyhow::Result; use duct::{cmd, Expression}; use std::fs::OpenOptions; use std::io::{Read, Write}; -use std::path::{PathBuf}; +use std::path::PathBuf; use std::str::from_utf8; use thinp::file_utils; use thinp::io_engine::*; -pub mod thin_xml_generator; pub mod cache_xml_generator; pub mod test_dir; +pub mod thin_xml_generator; use crate::common::thin_xml_generator::{write_xml, SingleThinS}; use test_dir::TestDir; @@ -273,7 +273,12 @@ pub fn set_needs_check(md: &PathBuf) -> Result<()> { Ok(()) } -pub fn generate_metadata_leaks(md: &PathBuf, nr_blocks: u64, expected: u32, actual: u32) -> Result<()> { +pub fn generate_metadata_leaks( + md: &PathBuf, + nr_blocks: u64, + expected: u32, + actual: u32, +) -> Result<()> { let output = thin_generate_damage!( "-o", &md, @@ -318,4 +323,3 @@ where assert_eq!(csum, md5(p)?); Ok(()) } - diff --git a/tests/thin_delta.rs b/tests/thin_delta.rs index 2bc840c..458a307 100644 --- a/tests/thin_delta.rs +++ b/tests/thin_delta.rs @@ -2,8 +2,8 @@ use anyhow::Result; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ @@ -68,4 +68,3 @@ fn dev_unspecified() -> Result<()> { assert!(stderr.contains("No input device provided")); Ok(()) } - diff --git a/tests/thin_dump.rs b/tests/thin_dump.rs index d2e58a9..90b4298 100644 --- a/tests/thin_dump.rs +++ b/tests/thin_dump.rs @@ -1,12 +1,12 @@ use anyhow::Result; -use thinp::file_utils; use std::fs::OpenOptions; -use std::io::{Write}; +use std::io::Write; use std::str::from_utf8; +use thinp::file_utils; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ @@ -27,7 +27,11 @@ fn dump_restore_cycle() -> Result<()> { let output = thin_dump!(&md).run()?; let xml = td.mk_path("meta.xml"); - let mut file = OpenOptions::new().read(false).write(true).create(true).open(&xml)?; + let mut file = OpenOptions::new() + .read(false) + .write(true) + .create(true) + .open(&xml)?; file.write_all(&output.stdout[0..])?; drop(file); @@ -63,7 +67,7 @@ fn override_something(flag: &str, value: &str, pattern: &str) -> Result<()> { #[test] fn override_transaction_id() -> Result<()> { - override_something("--transaction-id", "2345", "transaction=\"2345\"") + override_something("--transaction-id", "2345", "transaction=\"2345\"") } #[test] @@ -80,13 +84,26 @@ fn override_nr_data_blocks() -> Result<()> { fn repair_superblock() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; - let before = thin_dump!("--transaction-id=5", "--data-block-size=128", "--nr-data-blocks=4096000", &md).run()?; + let before = thin_dump!( + "--transaction-id=5", + "--data-block-size=128", + "--nr-data-blocks=4096000", + &md + ) + .run()?; damage_superblock(&md)?; - let after = thin_dump!("--repair", "--transaction-id=5", "--data-block-size=128", "--nr-data-blocks=4096000", &md).run()?; + let after = thin_dump!( + "--repair", + "--transaction-id=5", + "--data-block-size=128", + "--nr-data-blocks=4096000", + &md + ) + .run()?; assert_eq!(after.stderr.len(), 0); assert_eq!(before.stdout, after.stdout); - + Ok(()) } @@ -95,7 +112,12 @@ fn missing_transaction_id() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail(thin_dump!("--repair", "--data-block-size=128", "--nr-data-blocks=4096000", &md))?; + let stderr = run_fail(thin_dump!( + "--repair", + "--data-block-size=128", + "--nr-data-blocks=4096000", + &md + ))?; assert!(stderr.contains("transaction id")); Ok(()) } @@ -105,7 +127,12 @@ fn missing_data_block_size() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail(thin_dump!("--repair", "--transaction-id=5", "--nr-data-blocks=4096000", &md))?; + let stderr = run_fail(thin_dump!( + "--repair", + "--transaction-id=5", + "--nr-data-blocks=4096000", + &md + ))?; assert!(stderr.contains("data block size")); Ok(()) } @@ -115,7 +142,12 @@ fn missing_nr_data_blocks() -> Result<()> { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; damage_superblock(&md)?; - let stderr = run_fail(thin_dump!("--repair", "--transaction-id=5", "--data-block-size=128", &md))?; + let stderr = run_fail(thin_dump!( + "--repair", + "--transaction-id=5", + "--data-block-size=128", + &md + ))?; assert!(stderr.contains("nr data blocks")); Ok(()) } diff --git a/tests/thin_metadata_pack.rs b/tests/thin_metadata_pack.rs index 4abd045..131cc95 100644 --- a/tests/thin_metadata_pack.rs +++ b/tests/thin_metadata_pack.rs @@ -2,8 +2,8 @@ use anyhow::Result; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ diff --git a/tests/thin_metadata_unpack.rs b/tests/thin_metadata_unpack.rs index 26ddfce..33d3f0c 100644 --- a/tests/thin_metadata_unpack.rs +++ b/tests/thin_metadata_unpack.rs @@ -2,8 +2,8 @@ use anyhow::Result; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ diff --git a/tests/thin_repair.rs b/tests/thin_repair.rs index 98ded1f..19f7969 100644 --- a/tests/thin_repair.rs +++ b/tests/thin_repair.rs @@ -3,8 +3,8 @@ use std::str::from_utf8; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ @@ -132,8 +132,7 @@ fn superblock_succeeds() -> Result<()> { Ok(()) } -fn missing_thing(flag1: &str, flag2: &str, pattern: &str) -> Result<()> -{ +fn missing_thing(flag1: &str, flag2: &str, pattern: &str) -> Result<()> { let mut td = TestDir::new()?; let md1 = mk_valid_md(&mut td)?; damage_superblock(&md1)?; @@ -145,15 +144,27 @@ fn missing_thing(flag1: &str, flag2: &str, pattern: &str) -> Result<()> #[test] fn missing_transaction_id() -> Result<()> { - missing_thing("--data-block-size=128", "--nr-data-blocks=4096000", "transaction id") + missing_thing( + "--data-block-size=128", + "--nr-data-blocks=4096000", + "transaction id", + ) } #[test] fn missing_data_block_size() -> Result<()> { - missing_thing("--transaction-id=5", "--nr-data-blocks=4096000", "data block size") + missing_thing( + "--transaction-id=5", + "--nr-data-blocks=4096000", + "data block size", + ) } #[test] fn missing_nr_data_blocks() -> Result<()> { - missing_thing("--transaction-id=5", "--data-block-size=128", "nr data blocks") + missing_thing( + "--transaction-id=5", + "--data-block-size=128", + "nr data blocks", + ) } diff --git a/tests/thin_restore.rs b/tests/thin_restore.rs index 62f78dd..c8efa45 100644 --- a/tests/thin_restore.rs +++ b/tests/thin_restore.rs @@ -4,8 +4,8 @@ use thinp::file_utils; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ diff --git a/tests/thin_rmap.rs b/tests/thin_rmap.rs index 1a932a2..3797edf 100644 --- a/tests/thin_rmap.rs +++ b/tests/thin_rmap.rs @@ -2,8 +2,8 @@ use anyhow::Result; use thinp::version::TOOLS_VERSION; mod common; -use common::*; use common::test_dir::*; +use common::*; //------------------------------------------ @@ -54,7 +54,16 @@ fn valid_region_format_should_pass() -> Result<()> { #[test] fn invalid_regions_should_fail() -> Result<()> { - let invalid_regions = ["23,7890", "23..six", "found..7890", "89..88", "89..89", "89..", "", "89...99"]; + let invalid_regions = [ + "23,7890", + "23..six", + "found..7890", + "89..88", + "89..89", + "89..", + "", + "89...99", + ]; for r in &invalid_regions { let mut td = TestDir::new()?; let md = mk_valid_md(&mut td)?; diff --git a/tests/thin_shrink.rs b/tests/thin_shrink.rs index 6bed874..e796dfd 100644 --- a/tests/thin_shrink.rs +++ b/tests/thin_shrink.rs @@ -3,16 +3,14 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use rand::prelude::*; use std::fs::OpenOptions; use std::io::{Cursor, Read, Seek, SeekFrom, Write}; -use std::path::{Path}; +use std::path::Path; use thinp::file_utils; use thinp::thin::xml::{self, Visit}; mod common; use common::test_dir::*; -use common::thin_xml_generator::{ - write_xml, EmptyPoolS, FragmentedS, SingleThinS, SnapS, XmlGen -}; +use common::thin_xml_generator::{write_xml, EmptyPoolS, FragmentedS, SingleThinS, SnapS, XmlGen}; //------------------------------------