[all] Apply cargo fmt

This commit is contained in:
Ming-Hung Tsai 2021-05-04 16:10:20 +08:00
parent 4b4584c830
commit 43e433149b
31 changed files with 178 additions and 160 deletions

View File

@ -97,8 +97,7 @@ fn main() {
report = Arc::new(mk_simple_report()); report = Arc::new(mk_simple_report());
} }
if matches.is_present("SYNC_IO") && if matches.is_present("SYNC_IO") && matches.is_present("ASYNC_IO") {
matches.is_present("ASYNC_IO") {
eprintln!("--sync-io and --async-io may not be used at the same time."); eprintln!("--sync-io and --async-io may not be used at the same time.");
process::exit(1); process::exit(1);
} }

16
src/cache/check.rs vendored
View File

@ -1,13 +1,13 @@
use anyhow::anyhow; use anyhow::anyhow;
use std::collections::*;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::path::Path; use std::path::Path;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::collections::*;
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
use crate::cache::hint::*; use crate::cache::hint::*;
use crate::cache::mapping::*; use crate::cache::mapping::*;
use crate::cache::superblock::*; use crate::cache::superblock::*;
use crate::io_engine::{AsyncIoEngine, IoEngine, SyncIoEngine};
use crate::pdata::array_walker::*; use crate::pdata::array_walker::*;
//------------------------------------------ //------------------------------------------
@ -112,19 +112,13 @@ fn mk_context(opts: &CacheCheckOptions) -> anyhow::Result<Context> {
let engine: Arc<dyn IoEngine + Send + Sync>; let engine: Arc<dyn IoEngine + Send + Sync>;
if opts.async_io { if opts.async_io {
engine = Arc::new(AsyncIoEngine::new( engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO, false)?);
opts.dev,
MAX_CONCURRENT_IO,
false,
)?);
} else { } else {
let nr_threads = std::cmp::max(8, num_cpus::get() * 2); let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads, false)?); engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads, false)?);
} }
Ok(Context { Ok(Context { engine })
engine,
})
} }
pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> { pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> {
@ -145,7 +139,7 @@ pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> {
w.walk(c, sb.mapping_root)?; w.walk(c, sb.mapping_root)?;
if sb.version >= 2 { if sb.version >= 2 {
// TODO: check dirty bitset // TODO: check dirty bitset
} }
} }

2
src/cache/hint.rs vendored
View File

@ -1,6 +1,6 @@
use nom::IResult; use nom::IResult;
use std::marker::PhantomData;
use std::convert::TryInto; use std::convert::TryInto;
use std::marker::PhantomData;
use crate::pdata::unpack::*; use crate::pdata::unpack::*;

View File

@ -1,5 +1,5 @@
use nom::IResult;
use nom::number::complete::*; use nom::number::complete::*;
use nom::IResult;
use crate::pdata::unpack::*; use crate::pdata::unpack::*;
@ -26,7 +26,6 @@ impl Mapping {
} }
} }
impl Unpack for Mapping { impl Unpack for Mapping {
fn disk_size() -> u32 { fn disk_size() -> u32 {
8 8

13
src/cache/xml.rs vendored
View File

@ -100,7 +100,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
} }
fn superblock_e(&mut self) -> Result<Visit> { fn superblock_e(&mut self) -> Result<Visit> {
self.w.write_event(Event::End(BytesEnd::borrowed(b"superblock")))?; self.w
.write_event(Event::End(BytesEnd::borrowed(b"superblock")))?;
Ok(Visit::Continue) Ok(Visit::Continue)
} }
@ -112,7 +113,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
} }
fn mappings_e(&mut self) -> Result<Visit> { fn mappings_e(&mut self) -> Result<Visit> {
self.w.write_event(Event::End(BytesEnd::borrowed(b"mappings")))?; self.w
.write_event(Event::End(BytesEnd::borrowed(b"mappings")))?;
Ok(Visit::Continue) Ok(Visit::Continue)
} }
@ -134,7 +136,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
} }
fn hints_e(&mut self) -> Result<Visit> { fn hints_e(&mut self) -> Result<Visit> {
self.w.write_event(Event::End(BytesEnd::borrowed(b"hints")))?; self.w
.write_event(Event::End(BytesEnd::borrowed(b"hints")))?;
Ok(Visit::Continue) Ok(Visit::Continue)
} }
@ -155,7 +158,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
} }
fn discards_e(&mut self) -> Result<Visit> { fn discards_e(&mut self) -> Result<Visit> {
self.w.write_event(Event::End(BytesEnd::borrowed(b"discards")))?; self.w
.write_event(Event::End(BytesEnd::borrowed(b"discards")))?;
Ok(Visit::Continue) Ok(Visit::Continue)
} }
@ -172,4 +176,3 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
Ok(Visit::Continue) Ok(Visit::Continue)
} }
} }

View File

@ -55,7 +55,9 @@ pub fn write_checksum(buf: &mut [u8], kind: BT) -> Result<()> {
NODE => BTREE_CSUM_XOR, NODE => BTREE_CSUM_XOR,
BITMAP => BITMAP_CSUM_XOR, BITMAP => BITMAP_CSUM_XOR,
INDEX => INDEX_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 csum = checksum(buf) ^ salt;

View File

@ -31,10 +31,7 @@ pub fn to_delta(ns: &[u64]) -> Vec<Delta> {
count += 1; count += 1;
} }
count -= 1; count -= 1;
ds.push(Neg { ds.push(Neg { delta, count });
delta,
count,
});
base -= delta * count; base -= delta * count;
} }
Equal => { Equal => {
@ -54,10 +51,7 @@ pub fn to_delta(ns: &[u64]) -> Vec<Delta> {
count += 1; count += 1;
} }
count -= 1; count -= 1;
ds.push(Pos { ds.push(Pos { delta, count });
delta,
count,
});
base += delta * count; base += delta * count;
} }
} }

View File

@ -21,12 +21,7 @@ impl Unpack for ArrayBlockEntry {
let (i, n) = le_u64(i)?; let (i, n) = le_u64(i)?;
let block = n; let block = n;
Ok(( Ok((i, ArrayBlockEntry { block }))
i,
ArrayBlockEntry {
block,
}
))
} }
} }

View File

@ -33,7 +33,7 @@ impl Unpack for ArrayBlockHeader {
max_entries, max_entries,
nr_entries, nr_entries,
value_size, 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")) r.map_err(|_| anyhow!("parse error"))
} }
pub fn unpack_array_block<V: Unpack>( pub fn unpack_array_block<V: Unpack>(data: &[u8]) -> Result<ArrayBlock<V>> {
data: &[u8],
) -> Result<ArrayBlock<V>> {
// TODO: collect errors // 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))?; let (_i, values) = convert_result(count(V::unpack, header.nr_entries as usize)(i))?;
Ok(ArrayBlock { Ok(ArrayBlock { header, values })
header,
values,
})
} }
//------------------------------------------ //------------------------------------------

View File

@ -11,16 +11,12 @@ use crate::pdata::unpack::*;
pub struct ArrayWalker { pub struct ArrayWalker {
engine: Arc<dyn IoEngine + Send + Sync>, engine: Arc<dyn IoEngine + Send + Sync>,
ignore_non_fatal: bool ignore_non_fatal: bool,
} }
// FIXME: define another Result type for array visiting? // FIXME: define another Result type for array visiting?
pub trait ArrayBlockVisitor<V: Unpack> { pub trait ArrayBlockVisitor<V: Unpack> {
fn visit( fn visit(&self, index: u64, v: V) -> anyhow::Result<()>;
&self,
index: u64,
v: V,
) -> anyhow::Result<()>;
} }
struct BlockValueVisitor<V> { struct BlockValueVisitor<V> {
@ -39,14 +35,12 @@ impl<V: Unpack + Copy> BlockValueVisitor<V> {
} }
} }
pub fn visit_array_block( pub fn visit_array_block(&self, index: u64, array_block: ArrayBlock<V>) {
&self,
index: u64,
array_block: ArrayBlock<V>,
) {
let begin = index * u64::from(array_block.header.nr_entries); let begin = index * u64::from(array_block.header.nr_entries);
for i in 0..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<V: Unpack + Copy> NodeVisitor<ArrayBlockEntry> for BlockValueVisitor<V> {
) -> Result<()> { ) -> Result<()> {
for n in 0..keys.len() { for n in 0..keys.len() {
let index = keys[n]; 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::<V>(b.get_data()).map_err(|_| io_err(path))?; let array_block = unpack_array_block::<V>(b.get_data()).map_err(|_| io_err(path))?;
self.visit_array_block(index, array_block); self.visit_array_block(index, array_block);
} }

View File

@ -24,9 +24,15 @@ pub trait RefCounter<Value> {
pub struct NoopRC {} pub struct NoopRC {}
impl<Value> RefCounter<Value> for NoopRC { impl<Value> RefCounter<Value> for NoopRC {
fn get(&self, _v: &Value) -> Result<u32> {Ok(0)} fn get(&self, _v: &Value) -> Result<u32> {
fn inc(&mut self, _v: &Value) -> Result<()> {Ok(())} Ok(0)
fn dec(&mut self, _v: &Value) -> Result<()> {Ok(())} }
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. /// Wraps a space map up to become a RefCounter.
@ -150,11 +156,7 @@ fn write_node_<V: Unpack + Pack>(w: &mut WriteBatcher, mut node: Node<V>) -> Res
/// decide if it produces internal or leaf nodes. /// decide if it produces internal or leaf nodes.
pub trait NodeIO<V: Unpack + Pack> { pub trait NodeIO<V: Unpack + Pack> {
fn write(&self, w: &mut WriteBatcher, keys: Vec<u64>, values: Vec<V>) -> Result<WriteResult>; fn write(&self, w: &mut WriteBatcher, keys: Vec<u64>, values: Vec<V>) -> Result<WriteResult>;
fn read( fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<V>)>;
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<V>)>;
} }
pub struct LeafIO {} pub struct LeafIO {}
@ -178,11 +180,7 @@ impl<V: Unpack + Pack> NodeIO<V> for LeafIO {
write_node_(w, node) write_node_(w, node)
} }
fn read( fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<V>)> {
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<V>)> {
let b = w.read(block)?; let b = w.read(block)?;
let path = Vec::new(); let path = Vec::new();
match unpack_node::<V>(&path, b.get_data(), true, true)? { match unpack_node::<V>(&path, b.get_data(), true, true)? {
@ -215,11 +213,7 @@ impl NodeIO<u64> for InternalIO {
write_node_(w, node) write_node_(w, node)
} }
fn read( fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<u64>)> {
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<u64>)> {
let b = w.read(block)?; let b = w.read(block)?;
let path = Vec::new(); let path = Vec::new();
match unpack_node::<u64>(&path, b.get_data(), true, true)? { match unpack_node::<u64>(&path, b.get_data(), true, true)? {
@ -261,10 +255,7 @@ pub struct NodeSummary {
impl<'a, V: Pack + Unpack + Clone> NodeBuilder<V> { impl<'a, V: Pack + Unpack + Clone> NodeBuilder<V> {
/// Create a new NodeBuilder /// Create a new NodeBuilder
pub fn new( pub fn new(nio: Box<dyn NodeIO<V>>, value_rc: Box<dyn RefCounter<V>>) -> Self {
nio: Box<dyn NodeIO<V>>,
value_rc: Box<dyn RefCounter<V>>,
) -> Self {
NodeBuilder { NodeBuilder {
nio, nio,
value_rc, value_rc,
@ -460,14 +451,9 @@ pub struct Builder<V: Unpack + Pack> {
} }
impl<V: Unpack + Pack + Clone> Builder<V> { impl<V: Unpack + Pack + Clone> Builder<V> {
pub fn new( pub fn new(value_rc: Box<dyn RefCounter<V>>) -> Builder<V> {
value_rc: Box<dyn RefCounter<V>>,
) -> Builder<V> {
Builder { Builder {
leaf_builder: NodeBuilder::new( leaf_builder: NodeBuilder::new(Box::new(LeafIO {}), value_rc),
Box::new(LeafIO {}),
value_rc,
),
} }
} }
@ -487,9 +473,7 @@ impl<V: Unpack + Pack + Clone> Builder<V> {
while nodes.len() > 1 { while nodes.len() > 1 {
let mut builder = NodeBuilder::new( let mut builder = NodeBuilder::new(
Box::new(InternalIO {}), Box::new(InternalIO {}),
Box::new(SMRefCounter { Box::new(SMRefCounter { sm: w.sm.clone() }),
sm: w.sm.clone(),
}),
); );
for n in nodes { for n in nodes {
@ -505,4 +489,3 @@ impl<V: Unpack + Pack + Clone> Builder<V> {
} }
//------------------------------------------ //------------------------------------------

View File

@ -3,10 +3,9 @@ pub mod array_block;
pub mod array_walker; pub mod array_walker;
pub mod btree; pub mod btree;
pub mod btree_builder; pub mod btree_builder;
pub mod btree_merge;
pub mod btree_leaf_walker; pub mod btree_leaf_walker;
pub mod btree_merge;
pub mod btree_walker; pub mod btree_walker;
pub mod space_map; pub mod space_map;
pub mod space_map_disk; pub mod space_map_disk;
pub mod unpack; pub mod unpack;

View File

@ -1,8 +1,8 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
use nom::{number::complete::*, IResult}; use nom::{number::complete::*, IResult};
use std::io::Cursor;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::io::Cursor;
use crate::checksum; use crate::checksum;
use crate::io_engine::*; use crate::io_engine::*;
@ -350,7 +350,7 @@ fn adjust_counts(w: &mut WriteBatcher, ie: &IndexEntry, allocs: &[u64]) -> Resul
w.write(bitmap_block, checksum::BT::BITMAP)?; w.write(bitmap_block, checksum::BT::BITMAP)?;
// Return the adjusted index entry // Return the adjusted index entry
Ok (IndexEntry { Ok(IndexEntry {
blocknr: ie.blocknr, blocknr: ie.blocknr,
nr_free, nr_free,
none_free_before: first_free, none_free_before: first_free,
@ -381,7 +381,7 @@ pub fn write_metadata_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<SMRo
// Write out the metadata index // Write out the metadata index
let metadata_index = MetadataIndex { let metadata_index = MetadataIndex {
blocknr: bitmap_root.loc, blocknr: bitmap_root.loc,
indexes indexes,
}; };
let mut cur = Cursor::new(bitmap_root.get_data()); let mut cur = Cursor::new(bitmap_root.get_data());
metadata_index.pack(&mut cur)?; metadata_index.pack(&mut cur)?;

View File

@ -1,6 +1,6 @@
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use nom::{number::complete::*, IResult};
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
use nom::{number::complete::*, IResult};
//------------------------------------------ //------------------------------------------

View File

@ -133,7 +133,7 @@ impl ReportInner for PBInner {
pub fn mk_progress_bar_report() -> Report { pub fn mk_progress_bar_report() -> Report {
Report::new(Box::new(PBInner { Report::new(Box::new(PBInner {
title: "".to_string(), title: "".to_string(),
bar: ProgressBar::new(100), bar: ProgressBar::new(100),
})) }))
} }

View File

@ -1,7 +1,7 @@
use anyhow::Result; use anyhow::Result;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{Read, Seek, SeekFrom, Write};
use std::path::Path; use std::path::Path;
use std::io::{Seek, SeekFrom, Write, Read};
//use std::os::unix::fs::OpenOptionsExt; //use std::os::unix::fs::OpenOptionsExt;
pub type Sector = u64; pub type Sector = u64;
@ -13,7 +13,6 @@ pub struct Region {
pub len: Sector, pub len: Sector,
} }
fn copy_step<W>(file: &mut W, src_byte: u64, dest_byte: u64, len: usize) -> Result<()> fn copy_step<W>(file: &mut W, src_byte: u64, dest_byte: u64, len: usize) -> Result<()>
where where
W: Write + Seek + Read, W: Write + Seek + Read,
@ -38,7 +37,12 @@ where
let mut written = 0; let mut written = 0;
while written != len_bytes { while written != len_bytes {
let step = u64::min(len_bytes - written, MAX_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; written += step;
} }
Ok(()) Ok(())

View File

@ -298,7 +298,7 @@ fn find_shared_nodes(
} }
} }
/* /*
// FIXME: why?!! // FIXME: why?!!
// we're not interested in leaves (roots will get re-added later). // 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 sb = read_superblock(ctx.engine.as_ref(), SUPERBLOCK_LOCATION)?;
let md = build_metadata(&ctx, &sb)?; let md = build_metadata(&ctx, &sb)?;
/* /*
ctx.report ctx.report
.set_title("Optimising metadata to improve leaf packing"); .set_title("Optimising metadata to improve leaf packing");
let md = optimise_metadata(md)?; let md = optimise_metadata(md)?;

View File

@ -4,8 +4,8 @@ use nom::{bytes::complete::*, number::complete::*, IResult};
use std::fmt; use std::fmt;
use std::io::Cursor; use std::io::Cursor;
use crate::io_engine::*;
use crate::checksum::*; use crate::checksum::*;
use crate::io_engine::*;
//---------------------------------------- //----------------------------------------
@ -116,8 +116,8 @@ fn pack_superblock<W: WriteBytesExt>(sb: &Superblock, w: &mut W) -> Result<()> {
w.write_u32::<LittleEndian>(sb.time)?; w.write_u32::<LittleEndian>(sb.time)?;
w.write_u64::<LittleEndian>(sb.transaction_id)?; w.write_u64::<LittleEndian>(sb.transaction_id)?;
w.write_u64::<LittleEndian>(sb.metadata_snap)?; w.write_u64::<LittleEndian>(sb.metadata_snap)?;
w.write_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // data 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_all(&vec![0; SPACE_MAP_ROOT_SIZE])?; // metadata sm root
w.write_u64::<LittleEndian>(sb.mapping_root)?; w.write_u64::<LittleEndian>(sb.mapping_root)?;
w.write_u64::<LittleEndian>(sb.details_root)?; w.write_u64::<LittleEndian>(sb.details_root)?;
w.write_u32::<LittleEndian>(sb.data_block_size)?; w.write_u32::<LittleEndian>(sb.data_block_size)?;

View File

@ -268,10 +268,8 @@ fn parse_def(e: &BytesStart, tag: &str) -> Result<String> {
match kv.key { match kv.key {
b"name" => { b"name" => {
name = Some(string_val(&kv)); name = Some(string_val(&kv));
},
_ => {
return bad_attr(tag, kv.key)
} }
_ => return bad_attr(tag, kv.key),
} }
} }

View File

@ -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<Block>) -> Result<()> { pub fn flush_(&mut self, queue: Vec<Block>) -> Result<()> {

View File

@ -1,11 +1,11 @@
use anyhow::Result; use anyhow::Result;
use thinp::version::TOOLS_VERSION;
use duct::cmd; use duct::cmd;
use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------

View File

@ -1,4 +1,4 @@
use anyhow::{Result}; use anyhow::Result;
use rand::prelude::*; use rand::prelude::*;
use std::collections::HashSet; use std::collections::HashSet;
use std::fs::OpenOptions; use std::fs::OpenOptions;

View File

@ -4,14 +4,14 @@ use anyhow::Result;
use duct::{cmd, Expression}; use duct::{cmd, Expression};
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{Read, Write}; use std::io::{Read, Write};
use std::path::{PathBuf}; use std::path::PathBuf;
use std::str::from_utf8; use std::str::from_utf8;
use thinp::file_utils; use thinp::file_utils;
use thinp::io_engine::*; use thinp::io_engine::*;
pub mod thin_xml_generator;
pub mod cache_xml_generator; pub mod cache_xml_generator;
pub mod test_dir; pub mod test_dir;
pub mod thin_xml_generator;
use crate::common::thin_xml_generator::{write_xml, SingleThinS}; use crate::common::thin_xml_generator::{write_xml, SingleThinS};
use test_dir::TestDir; use test_dir::TestDir;
@ -273,7 +273,12 @@ pub fn set_needs_check(md: &PathBuf) -> Result<()> {
Ok(()) 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!( let output = thin_generate_damage!(
"-o", "-o",
&md, &md,
@ -318,4 +323,3 @@ where
assert_eq!(csum, md5(p)?); assert_eq!(csum, md5(p)?);
Ok(()) Ok(())
} }

View File

@ -2,8 +2,8 @@ use anyhow::Result;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------
@ -68,4 +68,3 @@ fn dev_unspecified() -> Result<()> {
assert!(stderr.contains("No input device provided")); assert!(stderr.contains("No input device provided"));
Ok(()) Ok(())
} }

View File

@ -1,12 +1,12 @@
use anyhow::Result; use anyhow::Result;
use thinp::file_utils;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{Write}; use std::io::Write;
use std::str::from_utf8; use std::str::from_utf8;
use thinp::file_utils;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------
@ -27,7 +27,11 @@ fn dump_restore_cycle() -> Result<()> {
let output = thin_dump!(&md).run()?; let output = thin_dump!(&md).run()?;
let xml = td.mk_path("meta.xml"); 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..])?; file.write_all(&output.stdout[0..])?;
drop(file); drop(file);
@ -63,7 +67,7 @@ fn override_something(flag: &str, value: &str, pattern: &str) -> Result<()> {
#[test] #[test]
fn override_transaction_id() -> Result<()> { fn override_transaction_id() -> Result<()> {
override_something("--transaction-id", "2345", "transaction=\"2345\"") override_something("--transaction-id", "2345", "transaction=\"2345\"")
} }
#[test] #[test]
@ -80,10 +84,23 @@ fn override_nr_data_blocks() -> Result<()> {
fn repair_superblock() -> Result<()> { fn repair_superblock() -> Result<()> {
let mut td = TestDir::new()?; let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?; 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)?; 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!(after.stderr.len(), 0);
assert_eq!(before.stdout, after.stdout); assert_eq!(before.stdout, after.stdout);
@ -95,7 +112,12 @@ fn missing_transaction_id() -> Result<()> {
let mut td = TestDir::new()?; let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?; let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?; 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")); assert!(stderr.contains("transaction id"));
Ok(()) Ok(())
} }
@ -105,7 +127,12 @@ fn missing_data_block_size() -> Result<()> {
let mut td = TestDir::new()?; let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?; let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?; 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")); assert!(stderr.contains("data block size"));
Ok(()) Ok(())
} }
@ -115,7 +142,12 @@ fn missing_nr_data_blocks() -> Result<()> {
let mut td = TestDir::new()?; let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?; let md = mk_valid_md(&mut td)?;
damage_superblock(&md)?; 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")); assert!(stderr.contains("nr data blocks"));
Ok(()) Ok(())
} }

View File

@ -2,8 +2,8 @@ use anyhow::Result;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------

View File

@ -2,8 +2,8 @@ use anyhow::Result;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------

View File

@ -3,8 +3,8 @@ use std::str::from_utf8;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------
@ -132,8 +132,7 @@ fn superblock_succeeds() -> Result<()> {
Ok(()) 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 mut td = TestDir::new()?;
let md1 = mk_valid_md(&mut td)?; let md1 = mk_valid_md(&mut td)?;
damage_superblock(&md1)?; damage_superblock(&md1)?;
@ -145,15 +144,27 @@ fn missing_thing(flag1: &str, flag2: &str, pattern: &str) -> Result<()>
#[test] #[test]
fn missing_transaction_id() -> Result<()> { 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] #[test]
fn missing_data_block_size() -> Result<()> { 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] #[test]
fn missing_nr_data_blocks() -> Result<()> { 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",
)
} }

View File

@ -4,8 +4,8 @@ use thinp::file_utils;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------

View File

@ -2,8 +2,8 @@ use anyhow::Result;
use thinp::version::TOOLS_VERSION; use thinp::version::TOOLS_VERSION;
mod common; mod common;
use common::*;
use common::test_dir::*; use common::test_dir::*;
use common::*;
//------------------------------------------ //------------------------------------------
@ -54,7 +54,16 @@ fn valid_region_format_should_pass() -> Result<()> {
#[test] #[test]
fn invalid_regions_should_fail() -> Result<()> { 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 { for r in &invalid_regions {
let mut td = TestDir::new()?; let mut td = TestDir::new()?;
let md = mk_valid_md(&mut td)?; let md = mk_valid_md(&mut td)?;

View File

@ -3,16 +3,14 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use rand::prelude::*; use rand::prelude::*;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::{Cursor, Read, Seek, SeekFrom, Write}; use std::io::{Cursor, Read, Seek, SeekFrom, Write};
use std::path::{Path}; use std::path::Path;
use thinp::file_utils; use thinp::file_utils;
use thinp::thin::xml::{self, Visit}; use thinp::thin::xml::{self, Visit};
mod common; mod common;
use common::test_dir::*; use common::test_dir::*;
use common::thin_xml_generator::{ use common::thin_xml_generator::{write_xml, EmptyPoolS, FragmentedS, SingleThinS, SnapS, XmlGen};
write_xml, EmptyPoolS, FragmentedS, SingleThinS, SnapS, XmlGen
};
//------------------------------------ //------------------------------------