[functional-tests] Fix clippy warnings
This commit is contained in:
parent
fa4ea3e2d9
commit
8f76371bb2
@ -190,7 +190,7 @@ impl IoEngine for AsyncIoEngine {
|
||||
let count = blocks.len();
|
||||
let fd = types::Target::Fd(inner.input.as_raw_fd());
|
||||
|
||||
for b in blocks.into_iter() {
|
||||
for b in blocks.iter_mut() {
|
||||
let read_e = opcode::Read::new(fd, b.data, BLOCK_SIZE as u32)
|
||||
.offset(b.loc as i64 * BLOCK_SIZE as i64);
|
||||
|
||||
|
@ -416,7 +416,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_u64s_match(ns: &Vec<u64>, bytes: &[u8]) -> bool {
|
||||
fn check_u64s_match(ns: &[u64], bytes: &[u8]) -> bool {
|
||||
let mut packed = Vec::with_capacity(ns.len() * 8);
|
||||
let mut w = Cursor::new(&mut packed);
|
||||
for n in ns {
|
||||
@ -425,7 +425,7 @@ mod tests {
|
||||
packed == bytes
|
||||
}
|
||||
|
||||
fn check_pack_u64s(ns: &Vec<u64>) -> bool {
|
||||
fn check_pack_u64s(ns: &[u64]) -> bool {
|
||||
println!("packing {:?}", &ns);
|
||||
let mut bs = Vec::with_capacity(4096);
|
||||
|
||||
@ -461,7 +461,7 @@ mod tests {
|
||||
check_pack_u64s(&ns)
|
||||
}
|
||||
|
||||
fn check_pack_shifted_u64s(ns: &Vec<(u64, u64)>) -> bool {
|
||||
fn check_pack_shifted_u64s(ns: &[(u64, u64)]) -> bool {
|
||||
let shifted: Vec<u64> = ns
|
||||
.iter()
|
||||
.map(|(h, l)| (h << 24) | (l & ((1 << 24) - 1)))
|
||||
|
@ -31,7 +31,6 @@ const NODE_HEADER_SIZE: usize = 32;
|
||||
|
||||
pub struct NodeHeader {
|
||||
is_leaf: bool,
|
||||
block: u64,
|
||||
nr_entries: u32,
|
||||
max_entries: u32,
|
||||
value_size: u32,
|
||||
@ -44,7 +43,7 @@ const LEAF_NODE: u32 = 2;
|
||||
pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
|
||||
let (i, _csum) = le_u32(data)?;
|
||||
let (i, flags) = le_u32(i)?;
|
||||
let (i, block) = le_u64(i)?;
|
||||
let (i, _block) = le_u64(i)?;
|
||||
let (i, nr_entries) = le_u32(i)?;
|
||||
let (i, max_entries) = le_u32(i)?;
|
||||
let (i, value_size) = le_u32(i)?;
|
||||
@ -54,7 +53,6 @@ pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
|
||||
i,
|
||||
NodeHeader {
|
||||
is_leaf: flags == LEAF_NODE,
|
||||
block,
|
||||
nr_entries,
|
||||
max_entries,
|
||||
value_size,
|
||||
@ -111,18 +109,18 @@ pub fn unpack_node<V: Unpack>(
|
||||
}
|
||||
|
||||
if header.nr_entries > header.max_entries {
|
||||
return node_err(format!("nr_entries > max_entries"));
|
||||
return node_err("nr_entries > max_entries".to_string());
|
||||
}
|
||||
|
||||
if !ignore_non_fatal {
|
||||
if header.max_entries % 3 != 0 {
|
||||
return node_err(format!("max_entries is not divisible by 3"));
|
||||
return node_err("max_entries is not divisible by 3".to_string());
|
||||
}
|
||||
|
||||
if !is_root {
|
||||
let min = header.max_entries / 3;
|
||||
if header.nr_entries < min {
|
||||
return node_err(format!("too few entries"));
|
||||
return node_err("too few entries".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,7 +131,7 @@ pub fn unpack_node<V: Unpack>(
|
||||
for k in &keys {
|
||||
if let Some(l) = last {
|
||||
if k <= l {
|
||||
return node_err(format!("keys out of order"));
|
||||
return node_err("keys out of order".to_string());
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +184,7 @@ impl Unpack for u32 {
|
||||
//------------------------------------------
|
||||
|
||||
pub trait NodeVisitor<V: Unpack> {
|
||||
fn visit<'a>(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>;
|
||||
fn visit(&mut self, w: &BTreeWalker, b: &Block, node: &Node<V>) -> Result<()>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -200,7 +198,7 @@ impl BTreeWalker {
|
||||
pub fn new(engine: Arc<AsyncIoEngine>, ignore_non_fatal: bool) -> BTreeWalker {
|
||||
let nr_blocks = engine.get_nr_blocks() as usize;
|
||||
let r: BTreeWalker = BTreeWalker {
|
||||
engine: engine,
|
||||
engine,
|
||||
seen: Arc::new(Mutex::new(FixedBitSet::with_capacity(nr_blocks))),
|
||||
ignore_non_fatal,
|
||||
};
|
||||
@ -224,7 +222,7 @@ impl BTreeWalker {
|
||||
}
|
||||
}
|
||||
|
||||
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &Vec<u64>) -> Result<()>
|
||||
fn walk_nodes<NV, V>(&mut self, visitor: &mut NV, bs: &[u64]) -> Result<()>
|
||||
where
|
||||
NV: NodeVisitor<V>,
|
||||
V: Unpack,
|
||||
|
@ -116,7 +116,7 @@ impl Unpack for Bitmap {
|
||||
|
||||
for _b in 0..32 {
|
||||
let val = word & 0x3;
|
||||
word = word >> 2;
|
||||
word >>= 2;
|
||||
|
||||
if val < 3 {
|
||||
entries.push(BitmapEntry::Small(val as u8));
|
||||
|
@ -148,12 +148,12 @@ impl NodeVisitor<IndexEntry> for IndexVisitor {
|
||||
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<IndexEntry>) -> Result<()> {
|
||||
if let Node::Leaf {
|
||||
header: _h,
|
||||
keys,
|
||||
keys: _k,
|
||||
values,
|
||||
} = node {
|
||||
for n in 0..keys.len() {
|
||||
for v in values {
|
||||
// FIXME: check keys are in incremental order
|
||||
let v = values[n].clone();
|
||||
let v = v.clone();
|
||||
self.entries.push(v);
|
||||
}
|
||||
}
|
||||
|
@ -359,13 +359,7 @@ where
|
||||
reader.trim_text(true);
|
||||
let mut buf = Vec::new();
|
||||
|
||||
loop {
|
||||
match handle_event(&mut reader, &mut buf, visitor)? {
|
||||
Visit::Continue => {}
|
||||
Visit::Stop => break,
|
||||
}
|
||||
}
|
||||
|
||||
while let Visit::Continue = handle_event(&mut reader, &mut buf, visitor)? {}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -380,7 +374,7 @@ impl MetadataVisitor for SBVisitor {
|
||||
self.superblock = Some(sb.clone());
|
||||
Ok(Visit::Stop)
|
||||
}
|
||||
|
||||
|
||||
fn superblock_e(&mut self) -> Result<Visit> {
|
||||
Ok(Visit::Continue)
|
||||
}
|
||||
@ -405,7 +399,7 @@ pub fn read_superblock<R>(input: R) -> Result<Superblock>
|
||||
where
|
||||
R: Read,
|
||||
{
|
||||
let mut v = SBVisitor {superblock: None};
|
||||
let mut v = SBVisitor { superblock: None };
|
||||
read(input, &mut v)?;
|
||||
Ok(v.superblock.unwrap())
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use thinp::file_utils;
|
||||
use thinp::version::TOOLS_VERSION;
|
||||
use duct::cmd;
|
||||
|
||||
@ -7,7 +6,6 @@ mod common;
|
||||
|
||||
use common::*;
|
||||
use common::test_dir::*;
|
||||
use common::cache_xml_generator::{write_xml, XmlGen};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
|
@ -136,7 +136,7 @@ fn mk_runs(thin_id: u32, total_len: u64, run_len: std::ops::Range<u64>) -> Vec<T
|
||||
thread_rng().gen_range(run_len.start, run_len.end),
|
||||
);
|
||||
runs.push(ThinRun {
|
||||
thin_id: thin_id,
|
||||
thin_id,
|
||||
thin_begin: b,
|
||||
len,
|
||||
});
|
||||
@ -171,9 +171,9 @@ impl XmlGen for FragmentedS {
|
||||
|
||||
// drop half the mappings, which leaves us free runs
|
||||
let mut dropped = Vec::new();
|
||||
for i in 0..maps.len() {
|
||||
for (i, m) in maps.iter().enumerate() {
|
||||
if i % 2 == 0 {
|
||||
dropped.push(maps[i].clone());
|
||||
dropped.push(*m);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ impl Allocator {
|
||||
}
|
||||
|
||||
runs.shuffle(&mut thread_rng());
|
||||
let runs: VecDeque<Range<u64>> = runs.iter().map(|r| r.clone()).collect();
|
||||
let runs: VecDeque<Range<u64>> = runs.iter().cloned().collect();
|
||||
Allocator { runs }
|
||||
}
|
||||
|
||||
@ -297,27 +297,25 @@ impl Run {
|
||||
|
||||
fn split(&self, n: u64) -> (Option<Run>, Option<Run>) {
|
||||
if n == 0 {
|
||||
return (None, Some(self.clone()));
|
||||
(None, Some(self.clone()))
|
||||
} else if self.len() <= n {
|
||||
(Some(self.clone()), None)
|
||||
} else {
|
||||
if self.len() <= n {
|
||||
return (Some(self.clone()), None);
|
||||
} else {
|
||||
match self {
|
||||
Run::Mapped { data_begin, len } => (
|
||||
Some(Run::Mapped {
|
||||
data_begin: *data_begin,
|
||||
len: n,
|
||||
}),
|
||||
Some(Run::Mapped {
|
||||
data_begin: data_begin + n,
|
||||
len: len - n,
|
||||
}),
|
||||
),
|
||||
Run::UnMapped { len } => (
|
||||
Some(Run::UnMapped { len: n }),
|
||||
Some(Run::UnMapped { len: len - n }),
|
||||
),
|
||||
}
|
||||
match self {
|
||||
Run::Mapped { data_begin, len } => (
|
||||
Some(Run::Mapped {
|
||||
data_begin: *data_begin,
|
||||
len: n,
|
||||
}),
|
||||
Some(Run::Mapped {
|
||||
data_begin: data_begin + n,
|
||||
len: len - n,
|
||||
}),
|
||||
),
|
||||
Run::UnMapped { len } => (
|
||||
Some(Run::UnMapped { len: n }),
|
||||
Some(Run::UnMapped { len: len - n }),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -437,7 +435,7 @@ fn mk_snap_mapping(
|
||||
runs
|
||||
}
|
||||
|
||||
fn split_runs(mut n: u64, runs: &Vec<Run>) -> (Vec<Run>, Vec<Run>) {
|
||||
fn split_runs(mut n: u64, runs: &[Run]) -> (Vec<Run>, Vec<Run>) {
|
||||
let mut before = Vec::new();
|
||||
let mut after = Vec::new();
|
||||
|
||||
@ -462,11 +460,11 @@ fn split_runs(mut n: u64, runs: &Vec<Run>) -> (Vec<Run>, Vec<Run>) {
|
||||
}
|
||||
|
||||
fn apply_snap_runs(
|
||||
origin: &Vec<Run>,
|
||||
snap: &Vec<SnapRun>,
|
||||
origin: &[Run],
|
||||
snap: &[SnapRun],
|
||||
allocator: &mut Allocator,
|
||||
) -> Result<Vec<Run>> {
|
||||
let mut origin = origin.clone();
|
||||
let mut origin = origin.to_owned();
|
||||
let mut runs = Vec::new();
|
||||
|
||||
for SnapRun(st, slen) in snap {
|
||||
|
@ -23,7 +23,7 @@ fn accepts_version() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const USAGE: &'static str = "Usage: thin_restore [options]\nOptions:\n {-h|--help}\n {-i|--input} <input xml file>\n {-o|--output} <output device or file>\n {--transaction-id} <natural>\n {--data-block-size} <natural>\n {--nr-data-blocks} <natural>\n {-q|--quiet}\n {-V|--version}";
|
||||
const USAGE: &str = "Usage: thin_restore [options]\nOptions:\n {-h|--help}\n {-i|--input} <input xml file>\n {-o|--output} <output device or file>\n {--transaction-id} <natural>\n {--data-block-size} <natural>\n {--nr-data-blocks} <natural>\n {-q|--quiet}\n {-V|--version}";
|
||||
|
||||
#[test]
|
||||
fn accepts_h() -> Result<()> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user