[all] Apply cargo fmt
This commit is contained in:
parent
4b4584c830
commit
43e433149b
@ -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);
|
||||
}
|
||||
|
14
src/cache/check.rs
vendored
14
src/cache/check.rs
vendored
@ -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<()> {
|
||||
|
2
src/cache/hint.rs
vendored
2
src/cache/hint.rs
vendored
@ -1,6 +1,6 @@
|
||||
use nom::IResult;
|
||||
use std::marker::PhantomData;
|
||||
use std::convert::TryInto;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use crate::pdata::unpack::*;
|
||||
|
||||
|
3
src/cache/mapping.rs
vendored
3
src/cache/mapping.rs
vendored
@ -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
|
||||
|
13
src/cache/xml.rs
vendored
13
src/cache/xml.rs
vendored
@ -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,7 +113,8 @@ 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)
|
||||
}
|
||||
|
||||
@ -134,7 +136,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -155,7 +158,8 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@ -172,4 +176,3 @@ impl<W: Write> MetadataVisitor for XmlWriter<W> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,9 @@ 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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 }))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 })
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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> {
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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::*;
|
||||
@ -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)?;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use anyhow::{anyhow, Result};
|
||||
use nom::{number::complete::*, IResult};
|
||||
use byteorder::{LittleEndian, WriteBytesExt};
|
||||
use nom::{number::complete::*, IResult};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -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(())
|
||||
|
@ -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)?;
|
||||
|
@ -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::*;
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
|
@ -268,10 +268,8 @@ fn parse_def(e: &BytesStart, tag: &str) -> Result<String> {
|
||||
match kv.key {
|
||||
b"name" => {
|
||||
name = Some(string_val(&kv));
|
||||
},
|
||||
_ => {
|
||||
return bad_attr(tag, kv.key)
|
||||
}
|
||||
_ => return bad_attr(tag, kv.key),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<()> {
|
||||
|
@ -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::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use anyhow::{Result};
|
||||
use anyhow::Result;
|
||||
use rand::prelude::*;
|
||||
use std::collections::HashSet;
|
||||
use std::fs::OpenOptions;
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
@ -80,10 +84,23 @@ 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);
|
||||
|
||||
@ -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(())
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ use anyhow::Result;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
|
||||
mod common;
|
||||
use common::*;
|
||||
use common::test_dir::*;
|
||||
use common::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -2,8 +2,8 @@ use anyhow::Result;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
|
||||
mod common;
|
||||
use common::*;
|
||||
use common::test_dir::*;
|
||||
use common::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -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",
|
||||
)
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ use thinp::file_utils;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
|
||||
mod common;
|
||||
use common::*;
|
||||
use common::test_dir::*;
|
||||
use common::*;
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -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)?;
|
||||
|
@ -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};
|
||||
|
||||
//------------------------------------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user