[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 count = blocks.len();
|
||||||
let fd = types::Target::Fd(inner.input.as_raw_fd());
|
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)
|
let read_e = opcode::Read::new(fd, b.data, BLOCK_SIZE as u32)
|
||||||
.offset(b.loc as i64 * BLOCK_SIZE as i64);
|
.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 packed = Vec::with_capacity(ns.len() * 8);
|
||||||
let mut w = Cursor::new(&mut packed);
|
let mut w = Cursor::new(&mut packed);
|
||||||
for n in ns {
|
for n in ns {
|
||||||
@ -425,7 +425,7 @@ mod tests {
|
|||||||
packed == bytes
|
packed == bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_pack_u64s(ns: &Vec<u64>) -> bool {
|
fn check_pack_u64s(ns: &[u64]) -> bool {
|
||||||
println!("packing {:?}", &ns);
|
println!("packing {:?}", &ns);
|
||||||
let mut bs = Vec::with_capacity(4096);
|
let mut bs = Vec::with_capacity(4096);
|
||||||
|
|
||||||
@ -461,7 +461,7 @@ mod tests {
|
|||||||
check_pack_u64s(&ns)
|
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
|
let shifted: Vec<u64> = ns
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(h, l)| (h << 24) | (l & ((1 << 24) - 1)))
|
.map(|(h, l)| (h << 24) | (l & ((1 << 24) - 1)))
|
||||||
|
@ -31,7 +31,6 @@ const NODE_HEADER_SIZE: usize = 32;
|
|||||||
|
|
||||||
pub struct NodeHeader {
|
pub struct NodeHeader {
|
||||||
is_leaf: bool,
|
is_leaf: bool,
|
||||||
block: u64,
|
|
||||||
nr_entries: u32,
|
nr_entries: u32,
|
||||||
max_entries: u32,
|
max_entries: u32,
|
||||||
value_size: u32,
|
value_size: u32,
|
||||||
@ -44,7 +43,7 @@ const LEAF_NODE: u32 = 2;
|
|||||||
pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
|
pub fn unpack_node_header(data: &[u8]) -> IResult<&[u8], NodeHeader> {
|
||||||
let (i, _csum) = le_u32(data)?;
|
let (i, _csum) = le_u32(data)?;
|
||||||
let (i, flags) = le_u32(i)?;
|
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, nr_entries) = le_u32(i)?;
|
||||||
let (i, max_entries) = le_u32(i)?;
|
let (i, max_entries) = le_u32(i)?;
|
||||||
let (i, value_size) = 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,
|
i,
|
||||||
NodeHeader {
|
NodeHeader {
|
||||||
is_leaf: flags == LEAF_NODE,
|
is_leaf: flags == LEAF_NODE,
|
||||||
block,
|
|
||||||
nr_entries,
|
nr_entries,
|
||||||
max_entries,
|
max_entries,
|
||||||
value_size,
|
value_size,
|
||||||
@ -111,18 +109,18 @@ pub fn unpack_node<V: Unpack>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if header.nr_entries > header.max_entries {
|
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 !ignore_non_fatal {
|
||||||
if header.max_entries % 3 != 0 {
|
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 {
|
if !is_root {
|
||||||
let min = header.max_entries / 3;
|
let min = header.max_entries / 3;
|
||||||
if header.nr_entries < min {
|
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 {
|
for k in &keys {
|
||||||
if let Some(l) = last {
|
if let Some(l) = last {
|
||||||
if k <= l {
|
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> {
|
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)]
|
#[derive(Clone)]
|
||||||
@ -200,7 +198,7 @@ impl BTreeWalker {
|
|||||||
pub fn new(engine: Arc<AsyncIoEngine>, ignore_non_fatal: bool) -> BTreeWalker {
|
pub fn new(engine: Arc<AsyncIoEngine>, ignore_non_fatal: bool) -> BTreeWalker {
|
||||||
let nr_blocks = engine.get_nr_blocks() as usize;
|
let nr_blocks = engine.get_nr_blocks() as usize;
|
||||||
let r: BTreeWalker = BTreeWalker {
|
let r: BTreeWalker = BTreeWalker {
|
||||||
engine: engine,
|
engine,
|
||||||
seen: Arc::new(Mutex::new(FixedBitSet::with_capacity(nr_blocks))),
|
seen: Arc::new(Mutex::new(FixedBitSet::with_capacity(nr_blocks))),
|
||||||
ignore_non_fatal,
|
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
|
where
|
||||||
NV: NodeVisitor<V>,
|
NV: NodeVisitor<V>,
|
||||||
V: Unpack,
|
V: Unpack,
|
||||||
|
@ -116,7 +116,7 @@ impl Unpack for Bitmap {
|
|||||||
|
|
||||||
for _b in 0..32 {
|
for _b in 0..32 {
|
||||||
let val = word & 0x3;
|
let val = word & 0x3;
|
||||||
word = word >> 2;
|
word >>= 2;
|
||||||
|
|
||||||
if val < 3 {
|
if val < 3 {
|
||||||
entries.push(BitmapEntry::Small(val as u8));
|
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<()> {
|
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<IndexEntry>) -> Result<()> {
|
||||||
if let Node::Leaf {
|
if let Node::Leaf {
|
||||||
header: _h,
|
header: _h,
|
||||||
keys,
|
keys: _k,
|
||||||
values,
|
values,
|
||||||
} = node {
|
} = node {
|
||||||
for n in 0..keys.len() {
|
for v in values {
|
||||||
// FIXME: check keys are in incremental order
|
// FIXME: check keys are in incremental order
|
||||||
let v = values[n].clone();
|
let v = v.clone();
|
||||||
self.entries.push(v);
|
self.entries.push(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,13 +359,7 @@ where
|
|||||||
reader.trim_text(true);
|
reader.trim_text(true);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
loop {
|
while let Visit::Continue = handle_event(&mut reader, &mut buf, visitor)? {}
|
||||||
match handle_event(&mut reader, &mut buf, visitor)? {
|
|
||||||
Visit::Continue => {}
|
|
||||||
Visit::Stop => break,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +374,7 @@ impl MetadataVisitor for SBVisitor {
|
|||||||
self.superblock = Some(sb.clone());
|
self.superblock = Some(sb.clone());
|
||||||
Ok(Visit::Stop)
|
Ok(Visit::Stop)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn superblock_e(&mut self) -> Result<Visit> {
|
fn superblock_e(&mut self) -> Result<Visit> {
|
||||||
Ok(Visit::Continue)
|
Ok(Visit::Continue)
|
||||||
}
|
}
|
||||||
@ -405,7 +399,7 @@ pub fn read_superblock<R>(input: R) -> Result<Superblock>
|
|||||||
where
|
where
|
||||||
R: Read,
|
R: Read,
|
||||||
{
|
{
|
||||||
let mut v = SBVisitor {superblock: None};
|
let mut v = SBVisitor { superblock: None };
|
||||||
read(input, &mut v)?;
|
read(input, &mut v)?;
|
||||||
Ok(v.superblock.unwrap())
|
Ok(v.superblock.unwrap())
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use thinp::file_utils;
|
|
||||||
use thinp::version::TOOLS_VERSION;
|
use thinp::version::TOOLS_VERSION;
|
||||||
use duct::cmd;
|
use duct::cmd;
|
||||||
|
|
||||||
@ -7,7 +6,6 @@ mod common;
|
|||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use common::test_dir::*;
|
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),
|
thread_rng().gen_range(run_len.start, run_len.end),
|
||||||
);
|
);
|
||||||
runs.push(ThinRun {
|
runs.push(ThinRun {
|
||||||
thin_id: thin_id,
|
thin_id,
|
||||||
thin_begin: b,
|
thin_begin: b,
|
||||||
len,
|
len,
|
||||||
});
|
});
|
||||||
@ -171,9 +171,9 @@ impl XmlGen for FragmentedS {
|
|||||||
|
|
||||||
// drop half the mappings, which leaves us free runs
|
// drop half the mappings, which leaves us free runs
|
||||||
let mut dropped = Vec::new();
|
let mut dropped = Vec::new();
|
||||||
for i in 0..maps.len() {
|
for (i, m) in maps.iter().enumerate() {
|
||||||
if i % 2 == 0 {
|
if i % 2 == 0 {
|
||||||
dropped.push(maps[i].clone());
|
dropped.push(*m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,7 +237,7 @@ impl Allocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runs.shuffle(&mut thread_rng());
|
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 }
|
Allocator { runs }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,27 +297,25 @@ impl Run {
|
|||||||
|
|
||||||
fn split(&self, n: u64) -> (Option<Run>, Option<Run>) {
|
fn split(&self, n: u64) -> (Option<Run>, Option<Run>) {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return (None, Some(self.clone()));
|
(None, Some(self.clone()))
|
||||||
|
} else if self.len() <= n {
|
||||||
|
(Some(self.clone()), None)
|
||||||
} else {
|
} else {
|
||||||
if self.len() <= n {
|
match self {
|
||||||
return (Some(self.clone()), None);
|
Run::Mapped { data_begin, len } => (
|
||||||
} else {
|
Some(Run::Mapped {
|
||||||
match self {
|
data_begin: *data_begin,
|
||||||
Run::Mapped { data_begin, len } => (
|
len: n,
|
||||||
Some(Run::Mapped {
|
}),
|
||||||
data_begin: *data_begin,
|
Some(Run::Mapped {
|
||||||
len: n,
|
data_begin: data_begin + n,
|
||||||
}),
|
len: 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 }),
|
||||||
Run::UnMapped { len } => (
|
),
|
||||||
Some(Run::UnMapped { len: n }),
|
|
||||||
Some(Run::UnMapped { len: len - n }),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,7 +435,7 @@ fn mk_snap_mapping(
|
|||||||
runs
|
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 before = Vec::new();
|
||||||
let mut after = 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(
|
fn apply_snap_runs(
|
||||||
origin: &Vec<Run>,
|
origin: &[Run],
|
||||||
snap: &Vec<SnapRun>,
|
snap: &[SnapRun],
|
||||||
allocator: &mut Allocator,
|
allocator: &mut Allocator,
|
||||||
) -> Result<Vec<Run>> {
|
) -> Result<Vec<Run>> {
|
||||||
let mut origin = origin.clone();
|
let mut origin = origin.to_owned();
|
||||||
let mut runs = Vec::new();
|
let mut runs = Vec::new();
|
||||||
|
|
||||||
for SnapRun(st, slen) in snap {
|
for SnapRun(st, slen) in snap {
|
||||||
|
@ -23,7 +23,7 @@ fn accepts_version() -> Result<()> {
|
|||||||
Ok(())
|
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]
|
#[test]
|
||||||
fn accepts_h() -> Result<()> {
|
fn accepts_h() -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user