Fix a lot of clippy warnings
This commit is contained in:
parent
e62fa3e835
commit
c3c6d37aea
@ -115,7 +115,7 @@ fn main() {
|
||||
|
||||
let opts = ThinCheckOptions {
|
||||
dev: &input_file,
|
||||
async_io: async_io,
|
||||
async_io,
|
||||
sb_only: matches.is_present("SB_ONLY"),
|
||||
skip_mappings: matches.is_present("SKIP_MAPPINGS"),
|
||||
ignore_non_fatal: matches.is_present("IGNORE_NON_FATAL"),
|
||||
|
@ -72,7 +72,6 @@ impl Events {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
let ignore_exit_key = Arc::new(AtomicBool::new(false));
|
||||
let input_handle = {
|
||||
let tx = tx.clone();
|
||||
let ignore_exit_key = ignore_exit_key.clone();
|
||||
thread::spawn(move || {
|
||||
let stdin = io::stdin();
|
||||
@ -110,6 +109,12 @@ impl Events {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Events {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------
|
||||
|
||||
fn ls_next(ls: &mut ListState, max: usize) {
|
||||
@ -158,7 +163,7 @@ impl<'a> StatefulWidget for SBWidget<'a> {
|
||||
let sb = self.sb;
|
||||
let flags = ["flags".to_string(), format!("{}", sb.flags)];
|
||||
let block = ["block".to_string(), format!("{}", sb.block)];
|
||||
let uuid = ["uuid".to_string(), format!("-")];
|
||||
let uuid = ["uuid".to_string(), "-".to_string()];
|
||||
let version = ["version".to_string(), format!("{}", sb.version)];
|
||||
let time = ["time".to_string(), format!("{}", sb.time)];
|
||||
let transaction_id = [
|
||||
@ -208,11 +213,11 @@ impl<'a> StatefulWidget for SBWidget<'a> {
|
||||
|
||||
Widget::render(table, chunks[0], buf);
|
||||
|
||||
let items = vec![
|
||||
ListItem::new(Span::raw(format!("Device tree"))),
|
||||
ListItem::new(Span::raw(format!("Mapping tree")))
|
||||
let items = vec![
|
||||
ListItem::new(Span::raw("Device tree".to_string())),
|
||||
ListItem::new(Span::raw("Mapping tree".to_string())),
|
||||
];
|
||||
|
||||
|
||||
let items = List::new(items)
|
||||
.block(Block::default().borders(Borders::ALL).title("Entries"))
|
||||
.highlight_style(
|
||||
@ -315,7 +320,7 @@ impl<X: Adjacent, Y: Adjacent> Adjacent for (X, Y) {
|
||||
fn adjacent_runs<V: Adjacent + Copy>(mut ns: Vec<V>) -> Vec<(V, usize)> {
|
||||
let mut result = Vec::new();
|
||||
|
||||
if ns.len() == 0 {
|
||||
if ns.is_empty() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -330,13 +335,13 @@ fn adjacent_runs<V: Adjacent + Copy>(mut ns: Vec<V>) -> Vec<(V, usize)> {
|
||||
current = v;
|
||||
len += 1;
|
||||
} else {
|
||||
result.push((base.clone(), len));
|
||||
base = v.clone();
|
||||
current = v.clone();
|
||||
result.push((base, len));
|
||||
base = v;
|
||||
current = v;
|
||||
len = 1;
|
||||
}
|
||||
}
|
||||
result.push((base.clone(), len));
|
||||
result.push((base, len));
|
||||
|
||||
result
|
||||
}
|
||||
@ -344,7 +349,7 @@ fn adjacent_runs<V: Adjacent + Copy>(mut ns: Vec<V>) -> Vec<(V, usize)> {
|
||||
fn mk_runs<V: Adjacent + Sized + Copy>(keys: &[u64], values: &[V]) -> Vec<((u64, V), usize)> {
|
||||
let mut pairs = Vec::new();
|
||||
for (k, v) in keys.iter().zip(values.iter()) {
|
||||
pairs.push((k.clone(), v.clone()));
|
||||
pairs.push((*k, *v));
|
||||
}
|
||||
|
||||
adjacent_runs(pairs)
|
||||
@ -498,7 +503,7 @@ impl Panel for SBPanel {
|
||||
} else {
|
||||
Some(PushTopLevel(self.sb.mapping_root))
|
||||
}
|
||||
},
|
||||
}
|
||||
Key::Char('h') | Key::Left => Some(PopPanel),
|
||||
_ => None,
|
||||
}
|
||||
@ -571,14 +576,14 @@ impl Panel for DeviceDetailPanel {
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for i in 0..values.len() {
|
||||
if values[i] == child {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushDeviceDetail(child));
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { .. } => None,
|
||||
}
|
||||
@ -645,14 +650,14 @@ impl Panel for TopLevelPanel {
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for i in 0..values.len() {
|
||||
if values[i] == child {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushTopLevel(child));
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { keys, values, .. } => {
|
||||
for i in 0..values.len() {
|
||||
@ -662,7 +667,7 @@ impl Panel for TopLevelPanel {
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -726,14 +731,14 @@ impl Panel for BottomLevelPanel {
|
||||
fn path_action(&mut self, child: u64) -> Option<Action> {
|
||||
match &self.node {
|
||||
btree::Node::Internal { values, .. } => {
|
||||
for i in 0..values.len() {
|
||||
if values[i] == child {
|
||||
for (i, v) in values.iter().enumerate() {
|
||||
if *v == child {
|
||||
self.state.select(Some(i));
|
||||
return Some(PushBottomLevel(self.thin_id, child));
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
btree::Node::Leaf { .. } => None,
|
||||
}
|
||||
@ -789,7 +794,7 @@ fn explore(path: &Path, node_path: Option<Vec<u64>>) -> Result<()> {
|
||||
}
|
||||
} else {
|
||||
let sb = read_superblock(&engine, 0)?;
|
||||
panels.push(Box::new(SBPanel::new(sb.clone())));
|
||||
panels.push(Box::new(SBPanel::new(sb)));
|
||||
}
|
||||
|
||||
let events = Events::new();
|
||||
@ -826,12 +831,11 @@ fn explore(path: &Path, node_path: Option<Vec<u64>>) -> Result<()> {
|
||||
if let Event::Input(key) = events.next()? {
|
||||
match key {
|
||||
Key::Char('q') => break 'main,
|
||||
_ => match active_panel.input(key) {
|
||||
Some(action) => {
|
||||
_ => {
|
||||
if let Some(action) = active_panel.input(key) {
|
||||
perform_action(&mut panels, &engine, action)?;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -269,10 +269,8 @@ impl AsyncIoEngine {
|
||||
cqes.sort_by(|a, b| a.user_data().partial_cmp(&b.user_data()).unwrap());
|
||||
|
||||
let mut rs = Vec::new();
|
||||
let mut i = 0;
|
||||
for b in blocks {
|
||||
for (i, b) in blocks.into_iter().enumerate() {
|
||||
let c = &cqes[i];
|
||||
i += 1;
|
||||
|
||||
let r = c.result();
|
||||
if r < 0 {
|
||||
|
@ -173,7 +173,7 @@ pub fn pack_literal<W: Write>(w: &mut W, bs: &[u8]) -> io::Result<()> {
|
||||
use Tag::LitW;
|
||||
|
||||
let len = bs.len() as u64;
|
||||
if len < 16 as u64 {
|
||||
if len < 16 {
|
||||
pack_tag(w, Tag::Lit, len as u8)?;
|
||||
} else if len <= u8::MAX as u64 {
|
||||
pack_tag(w, LitW, 1)?;
|
||||
@ -370,6 +370,12 @@ impl VM {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for VM {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack<R: Read>(r: &mut R, count: usize) -> io::Result<Vec<u8>> {
|
||||
let mut w = Vec::with_capacity(4096);
|
||||
let mut cursor = Cursor::new(&mut w);
|
||||
|
@ -26,6 +26,12 @@ impl KeyRange {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for KeyRange {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for KeyRange {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match (self.start, self.end) {
|
||||
@ -182,22 +188,20 @@ fn test_split_range() {
|
||||
}
|
||||
}
|
||||
|
||||
fn split_one(path: &Vec<u64>, kr: &KeyRange, k: u64) -> Result<(KeyRange, KeyRange)> {
|
||||
fn split_one(path: &[u64], kr: &KeyRange, k: u64) -> Result<(KeyRange, KeyRange)> {
|
||||
match kr.split(k) {
|
||||
None => {
|
||||
return Err(node_err(
|
||||
path,
|
||||
&format!("couldn't split key range {} at {}", kr, k),
|
||||
));
|
||||
}
|
||||
None => Err(node_err(
|
||||
path,
|
||||
&format!("couldn't split key range {} at {}", kr, k),
|
||||
)),
|
||||
Some(pair) => Ok(pair),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn split_key_ranges(path: &Vec<u64>, kr: &KeyRange, keys: &[u64]) -> Result<Vec<KeyRange>> {
|
||||
pub fn split_key_ranges(path: &[u64], kr: &KeyRange, keys: &[u64]) -> Result<Vec<KeyRange>> {
|
||||
let mut krs = Vec::with_capacity(keys.len());
|
||||
|
||||
if keys.len() == 0 {
|
||||
if keys.is_empty() {
|
||||
return Err(node_err(path, "split_key_ranges: no keys present"));
|
||||
}
|
||||
|
||||
@ -207,8 +211,8 @@ pub fn split_key_ranges(path: &Vec<u64>, kr: &KeyRange, keys: &[u64]) -> Result<
|
||||
end: kr.end,
|
||||
};
|
||||
|
||||
for i in 1..keys.len() {
|
||||
let (first, rest) = split_one(path, &kr, keys[i])?;
|
||||
for k in keys.iter().skip(1) {
|
||||
let (first, rest) = split_one(path, &kr, *k)?;
|
||||
krs.push(first);
|
||||
kr = rest;
|
||||
}
|
||||
@ -229,7 +233,7 @@ pub fn encode_node_path(path: &[u64]) -> String {
|
||||
|
||||
// The first entry is normally the superblock (0), so we
|
||||
// special case this.
|
||||
if path.len() > 0 && path[0] == 0 {
|
||||
if !path.is_empty() && path[0] == 0 {
|
||||
let count = ((path.len() as u8) - 1) << 1;
|
||||
cursor.write_u8(count as u8).unwrap();
|
||||
vm::pack_u64s(&mut cursor, &path[1..]).unwrap();
|
||||
@ -349,19 +353,19 @@ impl fmt::Display for BTreeError {
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn node_err(path: &Vec<u64>, msg: &str) -> BTreeError {
|
||||
pub fn node_err(path: &[u64], msg: &str) -> BTreeError {
|
||||
BTreeError::Path(
|
||||
path.clone(),
|
||||
path.to_vec(),
|
||||
Box::new(BTreeError::NodeError(msg.to_string())),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn node_err_s(path: &Vec<u64>, msg: String) -> BTreeError {
|
||||
BTreeError::Path(path.clone(), Box::new(BTreeError::NodeError(msg)))
|
||||
pub fn node_err_s(path: &[u64], msg: String) -> BTreeError {
|
||||
BTreeError::Path(path.to_vec(), Box::new(BTreeError::NodeError(msg)))
|
||||
}
|
||||
|
||||
pub fn io_err(path: &Vec<u64>) -> BTreeError {
|
||||
BTreeError::Path(path.clone(), Box::new(BTreeError::IoError))
|
||||
pub fn io_err(path: &[u64]) -> BTreeError {
|
||||
BTreeError::Path(path.to_vec(), Box::new(BTreeError::IoError))
|
||||
}
|
||||
|
||||
pub fn value_err(msg: String) -> BTreeError {
|
||||
@ -424,22 +428,22 @@ impl Unpack for NodeHeader {
|
||||
|
||||
impl Pack for NodeHeader {
|
||||
fn pack<W: WriteBytesExt>(&self, w: &mut W) -> anyhow::Result<()> {
|
||||
// csum needs to be calculated right for the whole metadata block.
|
||||
w.write_u32::<LittleEndian>(0)?;
|
||||
// csum needs to be calculated right for the whole metadata block.
|
||||
w.write_u32::<LittleEndian>(0)?;
|
||||
|
||||
let flags;
|
||||
if self.is_leaf {
|
||||
flags = LEAF_NODE;
|
||||
} else {
|
||||
flags = INTERNAL_NODE;
|
||||
}
|
||||
w.write_u32::<LittleEndian>(flags)?;
|
||||
w.write_u64::<LittleEndian>(self.block)?;
|
||||
w.write_u32::<LittleEndian>(self.nr_entries)?;
|
||||
w.write_u32::<LittleEndian>(self.max_entries)?;
|
||||
w.write_u32::<LittleEndian>(self.value_size)?;
|
||||
w.write_u32::<LittleEndian>(0)?;
|
||||
Ok(())
|
||||
let flags;
|
||||
if self.is_leaf {
|
||||
flags = LEAF_NODE;
|
||||
} else {
|
||||
flags = INTERNAL_NODE;
|
||||
}
|
||||
w.write_u32::<LittleEndian>(flags)?;
|
||||
w.write_u64::<LittleEndian>(self.block)?;
|
||||
w.write_u32::<LittleEndian>(self.nr_entries)?;
|
||||
w.write_u32::<LittleEndian>(self.max_entries)?;
|
||||
w.write_u32::<LittleEndian>(self.value_size)?;
|
||||
w.write_u32::<LittleEndian>(0)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,7 +477,7 @@ impl<V: Unpack> Node<V> {
|
||||
Leaf { header, .. } => header,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn get_keys(&self) -> &[u64] {
|
||||
use Node::*;
|
||||
match self {
|
||||
@ -487,16 +491,16 @@ impl<V: Unpack> Node<V> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_result<'a, V>(path: &Vec<u64>, r: IResult<&'a [u8], V>) -> Result<(&'a [u8], V)> {
|
||||
pub fn convert_result<'a, V>(path: &[u64], r: IResult<&'a [u8], V>) -> Result<(&'a [u8], V)> {
|
||||
r.map_err(|_e| node_err(path, "parse error"))
|
||||
}
|
||||
|
||||
pub fn convert_io_err<V>(path: &Vec<u64>, r: std::io::Result<V>) -> Result<V> {
|
||||
pub fn convert_io_err<V>(path: &[u64], r: std::io::Result<V>) -> Result<V> {
|
||||
r.map_err(|_| io_err(path))
|
||||
}
|
||||
|
||||
pub fn unpack_node<V: Unpack>(
|
||||
path: &Vec<u64>,
|
||||
path: &[u64],
|
||||
data: &[u8],
|
||||
ignore_non_fatal: bool,
|
||||
is_root: bool,
|
||||
@ -554,7 +558,7 @@ pub fn unpack_node<V: Unpack>(
|
||||
for k in &keys {
|
||||
if let Some(l) = last {
|
||||
if k <= l {
|
||||
return Err(node_err(path, "keys out of order"));
|
||||
return Err(node_err(&path, "keys out of order"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -573,7 +577,7 @@ pub fn unpack_node<V: Unpack>(
|
||||
values,
|
||||
})
|
||||
} else {
|
||||
let (_i, values) = convert_result(path, count(le_u64, header.nr_entries as usize)(i))?;
|
||||
let (_i, values) = convert_result(&path, count(le_u64, header.nr_entries as usize)(i))?;
|
||||
Ok(Node::Internal {
|
||||
header,
|
||||
keys,
|
||||
|
@ -153,7 +153,7 @@ pub struct NodeSummary {
|
||||
|
||||
fn write_node_<V: Unpack + Pack>(w: &mut WriteBatcher, mut node: Node<V>) -> Result<(u64, u64)> {
|
||||
let keys = node.get_keys();
|
||||
let first_key = keys.first().unwrap_or(&0u64).clone();
|
||||
let first_key = *keys.first().unwrap_or(&0u64);
|
||||
|
||||
let loc = w.alloc()?;
|
||||
node.set_block(loc);
|
||||
|
@ -102,8 +102,7 @@ impl<'a> LeafWalker<'a> {
|
||||
.read_many(&blocks[0..])
|
||||
.map_err(|_e| io_err(path))?;
|
||||
|
||||
let mut i = 0;
|
||||
for rb in rblocks {
|
||||
for (i, rb) in rblocks.into_iter().enumerate() {
|
||||
match rb {
|
||||
Err(_) => {
|
||||
return Err(io_err(path).keys_context(&filtered_krs[i]));
|
||||
@ -112,8 +111,6 @@ impl<'a> LeafWalker<'a> {
|
||||
self.walk_node(depth - 1, path, visitor, &filtered_krs[i], &b, false)?;
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@ -225,14 +222,12 @@ impl<'a> LeafWalker<'a> {
|
||||
self.leaves.insert(root as usize);
|
||||
visitor.visit(&kr, root)?;
|
||||
Ok(())
|
||||
} else if self.sm_inc(root) > 0 {
|
||||
visitor.visit_again(root)
|
||||
} else {
|
||||
if self.sm_inc(root) > 0 {
|
||||
visitor.visit_again(root)
|
||||
} else {
|
||||
let root = self.engine.read(root).map_err(|_| io_err(path))?;
|
||||
let root = self.engine.read(root).map_err(|_| io_err(path))?;
|
||||
|
||||
self.walk_node(depth - 1, path, visitor, &kr, &root, true)
|
||||
}
|
||||
self.walk_node(depth - 1, path, visitor, &kr, &root, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,21 +49,21 @@ impl LeafVisitor {
|
||||
impl<V: Unpack> NodeVisitor<V> for LeafVisitor {
|
||||
fn visit(
|
||||
&self,
|
||||
path: &Vec<u64>,
|
||||
path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_header: &NodeHeader,
|
||||
keys: &[u64],
|
||||
_values: &[V],
|
||||
) -> btree::Result<()> {
|
||||
// ignore empty nodes
|
||||
if keys.len() == 0 {
|
||||
if keys.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
|
||||
// Check keys are ordered.
|
||||
if inner.leaves.len() > 0 {
|
||||
if !inner.leaves.is_empty() {
|
||||
let last_key = inner.leaves.last().unwrap().key_high;
|
||||
if keys[0] <= last_key {
|
||||
return Err(BTreeError::NodeError(
|
||||
@ -83,7 +83,7 @@ impl<V: Unpack> NodeVisitor<V> for LeafVisitor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, _b: u64) -> btree::Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], _b: u64) -> btree::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ pub trait NodeVisitor<V: Unpack> {
|
||||
// &self is deliberately non mut to allow the walker to use multiple threads.
|
||||
fn visit(
|
||||
&self,
|
||||
path: &Vec<u64>,
|
||||
path: &[u64],
|
||||
kr: &KeyRange,
|
||||
header: &NodeHeader,
|
||||
keys: &[u64],
|
||||
@ -24,7 +24,7 @@ pub trait NodeVisitor<V: Unpack> {
|
||||
// Nodes may be shared and thus visited multiple times. The walker avoids
|
||||
// doing repeated IO, but it does call this method to keep the visitor up to
|
||||
// date.
|
||||
fn visit_again(&self, path: &Vec<u64>, b: u64) -> Result<()>;
|
||||
fn visit_again(&self, path: &[u64], b: u64) -> Result<()>;
|
||||
|
||||
fn end_walk(&self) -> Result<()>;
|
||||
}
|
||||
@ -154,8 +154,7 @@ impl BTreeWalker {
|
||||
}
|
||||
}
|
||||
Ok(rblocks) => {
|
||||
let mut i = 0;
|
||||
for rb in rblocks {
|
||||
for (i, rb) in rblocks.into_iter().enumerate() {
|
||||
match rb {
|
||||
Err(_) => {
|
||||
let e = io_err(path).keys_context(&filtered_krs[i]);
|
||||
@ -169,8 +168,6 @@ impl BTreeWalker {
|
||||
Ok(()) => {}
|
||||
},
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -215,7 +212,7 @@ impl BTreeWalker {
|
||||
values,
|
||||
} => {
|
||||
if let Err(e) = visitor.visit(path, &kr, &header, &keys, &values) {
|
||||
let e = BTreeError::Path(path.clone(), Box::new(e.clone()));
|
||||
let e = BTreeError::Path(path.clone(), Box::new(e));
|
||||
self.set_fail(b.loc, e.clone());
|
||||
return Err(e);
|
||||
}
|
||||
@ -251,7 +248,7 @@ impl BTreeWalker {
|
||||
{
|
||||
if self.sm_inc(root) > 0 {
|
||||
if let Some(e) = self.failed(root) {
|
||||
Err(e.clone())
|
||||
Err(e)
|
||||
} else {
|
||||
visitor.visit_again(path, root)
|
||||
}
|
||||
@ -382,10 +379,9 @@ where
|
||||
}
|
||||
}
|
||||
Ok(rblocks) => {
|
||||
let mut i = 0;
|
||||
let errs = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
for rb in rblocks {
|
||||
for (i, rb) in rblocks.into_iter().enumerate() {
|
||||
match rb {
|
||||
Err(_) => {
|
||||
let e = io_err(path).keys_context(&filtered_krs[i]);
|
||||
@ -411,8 +407,6 @@ where
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
pool.join();
|
||||
@ -435,7 +429,7 @@ where
|
||||
{
|
||||
if w.sm_inc(root) > 0 {
|
||||
if let Some(e) = w.failed(root) {
|
||||
Err(e.clone())
|
||||
Err(e)
|
||||
} else {
|
||||
visitor.visit_again(path, root)
|
||||
}
|
||||
@ -467,7 +461,7 @@ impl<V> ValueCollector<V> {
|
||||
impl<V: Unpack + Copy> NodeVisitor<V> for ValueCollector<V> {
|
||||
fn visit(
|
||||
&self,
|
||||
_path: &Vec<u64>,
|
||||
_path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_h: &NodeHeader,
|
||||
keys: &[u64],
|
||||
@ -475,13 +469,13 @@ impl<V: Unpack + Copy> NodeVisitor<V> for ValueCollector<V> {
|
||||
) -> Result<()> {
|
||||
let mut vals = self.values.lock().unwrap();
|
||||
for n in 0..keys.len() {
|
||||
vals.insert(keys[n], values[n].clone());
|
||||
vals.insert(keys[n], values[n]);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, _b: u64) -> Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], _b: u64) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -533,7 +527,7 @@ impl<V> ValuePathCollector<V> {
|
||||
impl<V: Unpack + Clone> NodeVisitor<V> for ValuePathCollector<V> {
|
||||
fn visit(
|
||||
&self,
|
||||
path: &Vec<u64>,
|
||||
path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_h: &NodeHeader,
|
||||
keys: &[u64],
|
||||
@ -541,13 +535,13 @@ impl<V: Unpack + Clone> NodeVisitor<V> for ValuePathCollector<V> {
|
||||
) -> Result<()> {
|
||||
let mut vals = self.values.lock().unwrap();
|
||||
for n in 0..keys.len() {
|
||||
vals.insert(keys[n], (path.clone(), values[n].clone()));
|
||||
vals.insert(keys[n], (path.to_vec(), values[n].clone()));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, _b: u64) -> Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], _b: u64) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Cursor;
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread::{self, JoinHandle};
|
||||
use threadpool::ThreadPool;
|
||||
@ -28,7 +29,7 @@ struct BottomLevelVisitor {
|
||||
impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||
fn visit(
|
||||
&self,
|
||||
_path: &Vec<u64>,
|
||||
_path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_h: &NodeHeader,
|
||||
_k: &[u64],
|
||||
@ -36,7 +37,7 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||
) -> btree::Result<()> {
|
||||
// FIXME: do other checks
|
||||
|
||||
if values.len() == 0 {
|
||||
if values.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -45,8 +46,8 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||
let mut start = values[0].block;
|
||||
let mut len = 1;
|
||||
|
||||
for n in 1..values.len() {
|
||||
let block = values[n].block;
|
||||
for b in values.iter().skip(1) {
|
||||
let block = b.block;
|
||||
if block == start + len {
|
||||
len += 1;
|
||||
} else {
|
||||
@ -60,7 +61,7 @@ impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, _b: u64) -> btree::Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], _b: u64) -> btree::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -84,7 +85,7 @@ impl<'a> OverflowChecker<'a> {
|
||||
impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
|
||||
fn visit(
|
||||
&self,
|
||||
_path: &Vec<u64>,
|
||||
_path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_h: &NodeHeader,
|
||||
keys: &[u64],
|
||||
@ -103,7 +104,7 @@ impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, _b: u64) -> btree::Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], _b: u64) -> btree::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -152,13 +153,12 @@ fn check_space_map(
|
||||
}
|
||||
|
||||
// FIXME: we should do this in batches
|
||||
let blocks = engine.read_many(&mut blocks)?;
|
||||
let blocks = engine.read_many(&blocks)?;
|
||||
|
||||
let mut leaks = 0;
|
||||
let mut blocknr = 0;
|
||||
let mut bitmap_leaks = Vec::new();
|
||||
for n in 0..entries.len() {
|
||||
let b = &blocks[n];
|
||||
for b in blocks.iter().take(entries.len()) {
|
||||
match b {
|
||||
Err(_e) => {
|
||||
return Err(anyhow!("Unable to read bitmap block"));
|
||||
@ -233,12 +233,8 @@ fn repair_space_map(ctx: &Context, entries: Vec<BitmapLeak>, sm: ASpaceMap) -> R
|
||||
let rblocks = engine.read_many(&blocks[0..])?;
|
||||
let mut write_blocks = Vec::new();
|
||||
|
||||
let mut i = 0;
|
||||
for rb in rblocks {
|
||||
if rb.is_err() {
|
||||
return Err(anyhow!("Unable to reread bitmap blocks for repair"));
|
||||
} else {
|
||||
let b = rb.unwrap();
|
||||
for (i, rb) in rblocks.into_iter().enumerate() {
|
||||
if let Ok(b) = rb {
|
||||
let be = &entries[i];
|
||||
let mut blocknr = be.blocknr;
|
||||
let mut bitmap = unpack::<Bitmap>(b.get_data())?;
|
||||
@ -262,9 +258,9 @@ fn repair_space_map(ctx: &Context, entries: Vec<BitmapLeak>, sm: ASpaceMap) -> R
|
||||
checksum::write_checksum(b.get_data(), checksum::BT::BITMAP)?;
|
||||
|
||||
write_blocks.push(b);
|
||||
} else {
|
||||
return Err(anyhow!("Unable to reread bitmap blocks for repair"));
|
||||
}
|
||||
|
||||
i += 1;
|
||||
}
|
||||
|
||||
engine.write_many(&write_blocks[0..])?;
|
||||
@ -305,20 +301,17 @@ fn spawn_progress_thread(
|
||||
sm: Arc<Mutex<dyn SpaceMap + Send + Sync>>,
|
||||
nr_allocated_metadata: u64,
|
||||
report: Arc<Report>,
|
||||
) -> Result<(JoinHandle<()>, Arc<Mutex<bool>>)> {
|
||||
) -> Result<(JoinHandle<()>, Arc<AtomicBool>)> {
|
||||
let tid;
|
||||
let stop_progress = Arc::new(Mutex::new(false));
|
||||
let stop_progress = Arc::new(AtomicBool::new(false));
|
||||
|
||||
{
|
||||
let stop_progress = stop_progress.clone();
|
||||
tid = thread::spawn(move || {
|
||||
let interval = std::time::Duration::from_millis(250);
|
||||
loop {
|
||||
{
|
||||
let stop_progress = stop_progress.lock().unwrap();
|
||||
if *stop_progress {
|
||||
break;
|
||||
}
|
||||
if stop_progress.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
let sm = sm.lock().unwrap();
|
||||
@ -364,7 +357,7 @@ fn check_mapping_bottom_level(
|
||||
|
||||
if roots.len() > 64 {
|
||||
let errs = Arc::new(Mutex::new(Vec::new()));
|
||||
for (_thin_id, (path, root)) in roots {
|
||||
for (path, root) in roots.values() {
|
||||
let data_sm = data_sm.clone();
|
||||
let root = *root;
|
||||
let v = BottomLevelVisitor { data_sm };
|
||||
@ -381,12 +374,12 @@ fn check_mapping_bottom_level(
|
||||
}
|
||||
ctx.pool.join();
|
||||
let errs = Arc::try_unwrap(errs).unwrap().into_inner().unwrap();
|
||||
if errs.len() > 0 {
|
||||
if !errs.is_empty() {
|
||||
ctx.report.fatal(&format!("{}", aggregate_error(errs)));
|
||||
failed = true;
|
||||
}
|
||||
} else {
|
||||
for (_thin_id, (path, root)) in roots {
|
||||
for (path, root) in roots.values() {
|
||||
let w = w.clone();
|
||||
let data_sm = data_sm.clone();
|
||||
let root = *root;
|
||||
@ -468,7 +461,12 @@ pub fn check(opts: ThinCheckOptions) -> Result<()> {
|
||||
// Device details. We read this once to get the number of thin devices, and hence the
|
||||
// maximum metadata ref count. Then create metadata space map, and reread to increment
|
||||
// the ref counts for that metadata.
|
||||
let devs = btree_to_map::<DeviceDetail>(&mut path, engine.clone(), opts.ignore_non_fatal, sb.details_root)?;
|
||||
let devs = btree_to_map::<DeviceDetail>(
|
||||
&mut path,
|
||||
engine.clone(),
|
||||
opts.ignore_non_fatal,
|
||||
sb.details_root,
|
||||
)?;
|
||||
let nr_devs = devs.len();
|
||||
let metadata_sm = core_sm(engine.get_nr_blocks(), nr_devs as u32);
|
||||
inc_superblock(&metadata_sm)?;
|
||||
@ -574,21 +572,18 @@ pub fn check(opts: ThinCheckOptions) -> Result<()> {
|
||||
bail_out(&ctx, "metadata space map")?;
|
||||
|
||||
if opts.auto_repair {
|
||||
if data_leaks.len() > 0 {
|
||||
if !data_leaks.is_empty() {
|
||||
ctx.report.info("Repairing data leaks.");
|
||||
repair_space_map(&ctx, data_leaks, data_sm.clone())?;
|
||||
}
|
||||
|
||||
if metadata_leaks.len() > 0 {
|
||||
if !metadata_leaks.is_empty() {
|
||||
ctx.report.info("Repairing metadata leaks.");
|
||||
repair_space_map(&ctx, metadata_leaks, metadata_sm.clone())?;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let mut stop_progress = stop_progress.lock().unwrap();
|
||||
*stop_progress = true;
|
||||
}
|
||||
stop_progress.store(true, Ordering::Relaxed);
|
||||
tid.join().unwrap();
|
||||
|
||||
Ok(())
|
||||
|
@ -38,7 +38,7 @@ impl RunBuilder {
|
||||
self.run = Some(xml::Map {
|
||||
thin_begin: thin_block,
|
||||
data_begin: data_block,
|
||||
time: time,
|
||||
time,
|
||||
len: 1,
|
||||
});
|
||||
None
|
||||
@ -59,7 +59,7 @@ impl RunBuilder {
|
||||
self.run.replace(Map {
|
||||
thin_begin: thin_block,
|
||||
data_begin: data_block,
|
||||
time: time,
|
||||
time,
|
||||
len: 1,
|
||||
})
|
||||
}
|
||||
@ -99,7 +99,7 @@ impl<'a> MappingVisitor<'a> {
|
||||
impl<'a> NodeVisitor<BlockTime> for MappingVisitor<'a> {
|
||||
fn visit(
|
||||
&self,
|
||||
_path: &Vec<u64>,
|
||||
_path: &[u64],
|
||||
_kr: &KeyRange,
|
||||
_h: &NodeHeader,
|
||||
keys: &[u64],
|
||||
@ -118,7 +118,7 @@ impl<'a> NodeVisitor<BlockTime> for MappingVisitor<'a> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_again(&self, _path: &Vec<u64>, b: u64) -> btree::Result<()> {
|
||||
fn visit_again(&self, _path: &[u64], b: u64) -> btree::Result<()> {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner
|
||||
.md_out
|
||||
@ -337,7 +337,7 @@ fn build_metadata(ctx: &Context, sb: &Superblock) -> Result<Metadata> {
|
||||
let (mut shared, sm) = find_shared_nodes(ctx, &roots)?;
|
||||
|
||||
// Add in the roots, because they may not be shared.
|
||||
for (_thin_id, (_path, root)) in &roots {
|
||||
for (_path, root) in roots.values() {
|
||||
shared.insert(*root);
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ fn build_metadata(ctx: &Context, sb: &Superblock) -> Result<Metadata> {
|
||||
let kr = KeyRange::new(); // FIXME: finish
|
||||
devs.push(Device {
|
||||
thin_id: thin_id as u32,
|
||||
detail: detail.clone(),
|
||||
detail: *detail,
|
||||
map: Mapping {
|
||||
kr,
|
||||
entries: es.to_vec(),
|
||||
@ -381,7 +381,7 @@ fn build_metadata(ctx: &Context, sb: &Superblock) -> Result<Metadata> {
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
fn gather_entries(g: &mut Gatherer, es: &Vec<Entry>) {
|
||||
fn gather_entries(g: &mut Gatherer, es: &[Entry]) {
|
||||
g.new_seq();
|
||||
for e in es {
|
||||
match e {
|
||||
@ -395,7 +395,7 @@ fn gather_entries(g: &mut Gatherer, es: &Vec<Entry>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn entries_to_runs(runs: &BTreeMap<u64, Vec<u64>>, es: &Vec<Entry>) -> Vec<Entry> {
|
||||
fn entries_to_runs(runs: &BTreeMap<u64, Vec<u64>>, es: &[Entry]) -> Vec<Entry> {
|
||||
use Entry::*;
|
||||
|
||||
let mut result = Vec::new();
|
||||
@ -542,7 +542,7 @@ fn emit_leaves(ctx: &Context, out: &mut dyn xml::MetadataVisitor, ls: &[u64]) ->
|
||||
fn emit_entries<W: Write>(
|
||||
ctx: &Context,
|
||||
out: &mut xml::XmlWriter<W>,
|
||||
entries: &Vec<Entry>,
|
||||
entries: &[Entry],
|
||||
) -> Result<()> {
|
||||
let mut leaves = Vec::new();
|
||||
|
||||
@ -552,7 +552,7 @@ fn emit_entries<W: Write>(
|
||||
leaves.push(*b);
|
||||
}
|
||||
Entry::Ref(id) => {
|
||||
if leaves.len() > 0 {
|
||||
if !leaves.is_empty() {
|
||||
emit_leaves(&ctx, out, &leaves[0..])?;
|
||||
leaves.clear();
|
||||
}
|
||||
@ -562,7 +562,7 @@ fn emit_entries<W: Write>(
|
||||
}
|
||||
}
|
||||
|
||||
if leaves.len() > 0 {
|
||||
if !leaves.is_empty() {
|
||||
emit_leaves(&ctx, out, &leaves[0..])?;
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,12 @@ impl Gatherer {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Gatherer {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user