[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());
}
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);
}

16
src/cache/check.rs vendored
View File

@ -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<Context> {
let engine: Arc<dyn IoEngine + Send + Sync>;
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
}
}

2
src/cache/hint.rs vendored
View File

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

View File

@ -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

23
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> {
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<W: Write> MetadataVisitor for XmlWriter<W> {
}
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)
}
fn mapping(&mut self, m: &Map) -> Result<Visit> {
let tag = b"map";
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
@ -132,12 +134,13 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
self.w.write_event(Event::Start(elem))?;
Ok(Visit::Continue)
}
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)
}
fn hint(&mut self, h: &Hint) -> Result<Visit> {
let tag = b"hint";
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
@ -153,12 +156,13 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
self.w.write_event(Event::Start(elem))?;
Ok(Visit::Continue)
}
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)
}
fn discard(&mut self, d: &Discard) -> Result<Visit> {
let tag = b"discard";
let mut elem = BytesStart::owned(tag.to_vec(), tag.len());
@ -172,4 +176,3 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
Ok(Visit::Continue)
}
}

View File

@ -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::<LittleEndian>(csum)?;

View File

@ -12,7 +12,7 @@ use Delta::*;
pub fn to_delta(ns: &[u64]) -> Vec<Delta> {
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<Delta> {
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<Delta> {
count += 1;
}
count -= 1;
ds.push(Pos {
delta,
count,
});
ds.push(Pos { delta, count });
base += delta * count;
}
}

View File

@ -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 }))
}
}

View File

@ -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<V: Unpack>(
data: &[u8],
) -> Result<ArrayBlock<V>> {
pub fn unpack_array_block<V: Unpack>(data: &[u8]) -> Result<ArrayBlock<V>> {
// 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 })
}
//------------------------------------------

View File

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

View File

@ -24,9 +24,15 @@ pub trait RefCounter<Value> {
pub struct NoopRC {}
impl<Value> RefCounter<Value> for NoopRC {
fn get(&self, _v: &Value) -> Result<u32> {Ok(0)}
fn inc(&mut self, _v: &Value) -> Result<()> {Ok(())}
fn dec(&mut self, _v: &Value) -> Result<()> {Ok(())}
fn get(&self, _v: &Value) -> Result<u32> {
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_<V: Unpack + Pack>(w: &mut WriteBatcher, mut node: Node<V>) -> Res
/// decide if it produces internal or leaf nodes.
pub trait NodeIO<V: Unpack + Pack> {
fn write(&self, w: &mut WriteBatcher, keys: Vec<u64>, values: Vec<V>) -> Result<WriteResult>;
fn read(
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<V>)>;
fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<V>)>;
}
pub struct LeafIO {}
@ -178,11 +180,7 @@ impl<V: Unpack + Pack> NodeIO<V> for LeafIO {
write_node_(w, node)
}
fn read(
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<V>)> {
fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<V>)> {
let b = w.read(block)?;
let path = Vec::new();
match unpack_node::<V>(&path, b.get_data(), true, true)? {
@ -215,11 +213,7 @@ impl NodeIO<u64> for InternalIO {
write_node_(w, node)
}
fn read(
&self,
w: &mut WriteBatcher,
block: u64,
) -> Result<(Vec<u64>, Vec<u64>)> {
fn read(&self, w: &mut WriteBatcher, block: u64) -> Result<(Vec<u64>, Vec<u64>)> {
let b = w.read(block)?;
let path = Vec::new();
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> {
/// Create a new NodeBuilder
pub fn new(
nio: Box<dyn NodeIO<V>>,
value_rc: Box<dyn RefCounter<V>>,
) -> Self {
pub fn new(nio: Box<dyn NodeIO<V>>, value_rc: Box<dyn RefCounter<V>>) -> Self {
NodeBuilder {
nio,
value_rc,
@ -356,7 +347,7 @@ impl<'a, V: Pack + Unpack + Clone> NodeBuilder<V> {
if self.nodes.len() == 0 {
self.emit_empty_leaf(w)?
}
Ok(self.nodes)
}
@ -460,14 +451,9 @@ pub struct Builder<V: Unpack + Pack> {
}
impl<V: Unpack + Pack + Clone> Builder<V> {
pub fn new(
value_rc: Box<dyn RefCounter<V>>,
) -> Builder<V> {
pub fn new(value_rc: Box<dyn RefCounter<V>>) -> Builder<V> {
Builder {
leaf_builder: NodeBuilder::new(
Box::new(LeafIO {}),
value_rc,
),
leaf_builder: NodeBuilder::new(Box::new(LeafIO {}), value_rc),
}
}
@ -487,9 +473,7 @@ impl<V: Unpack + Pack + Clone> Builder<V> {
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<V: Unpack + Pack + Clone> Builder<V> {
}
//------------------------------------------

View File

@ -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;

View File

@ -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<Inde
pub fn write_disk_sm(w: &mut WriteBatcher, sm: &dyn SpaceMap) -> Result<SMRoot> {
let (index_entries, ref_count_root) = write_common(w, sm)?;
let mut index_builder: Builder<IndexEntry> = 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<SMRo
// Write out the metadata index
let metadata_index = MetadataIndex {
blocknr: bitmap_root.loc,
indexes
indexes,
};
let mut cur = Cursor::new(bitmap_root.get_data());
metadata_index.pack(&mut cur)?;

View File

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

View File

@ -59,7 +59,7 @@ impl Report {
let mut inner = self.inner.lock().unwrap();
inner.set_sub_title(txt)
}
pub fn progress(&self, percent: u8) {
let mut inner = self.inner.lock().unwrap();
inner.progress(percent)
@ -133,7 +133,7 @@ impl ReportInner for PBInner {
pub fn mk_progress_bar_report() -> Report {
Report::new(Box::new(PBInner {
title: "".to_string(),
title: "".to_string(),
bar: ProgressBar::new(100),
}))
}

View File

@ -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<W>(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(())

View File

@ -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)?;

View File

@ -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<W: WriteBytesExt>(sb: &Superblock, w: &mut W) -> Result<()> {
w.write_u32::<LittleEndian>(sb.time)?;
w.write_u64::<LittleEndian>(sb.transaction_id)?;
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])?; // 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::<LittleEndian>(sb.mapping_root)?;
w.write_u64::<LittleEndian>(sb.details_root)?;
w.write_u32::<LittleEndian>(sb.data_block_size)?;
w.write_u32::<LittleEndian>(BLOCK_SIZE as u32)?;
w.write_u64::<LittleEndian>(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(())

View File

@ -262,16 +262,14 @@ fn parse_superblock(e: &BytesStart) -> Result<Superblock> {
fn parse_def(e: &BytesStart, tag: &str) -> Result<String> {
let mut name: Option<String> = 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),
}
}

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<()> {

View File

@ -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()?;

View File

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

View File

@ -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(())
}

View File

@ -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(())
}

View File

@ -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(())
}

View File

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

View File

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

View File

@ -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",
)
}

View File

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

View File

@ -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)?;

View File

@ -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};
//------------------------------------