[all] Apply cargo fmt, and fix clippy warnings

This commit is contained in:
Ming-Hung Tsai 2021-10-19 22:35:06 +08:00
parent 13aeefcdeb
commit c8a1da1df9
39 changed files with 125 additions and 151 deletions

View File

@ -23,7 +23,7 @@ fn main_() -> Result<()> {
let mut new_args = vec![OsString::from(&name)];
for a in args.into_iter() {
new_args.push(OsString::from(a));
new_args.push(a);
}
if name_eq(name, "cache_check") {

View File

@ -266,7 +266,7 @@ impl<'a> Widget for HeaderWidget<'a> {
fn read_node<V: Unpack>(engine: &dyn IoEngine, loc: u64) -> Result<btree::Node<V>> {
let b = engine.read(loc)?;
let path = Vec::new();
btree::unpack_node(&path, &b.get_data(), true, false)
btree::unpack_node(&path, b.get_data(), true, false)
.map_err(|_| anyhow!("couldn't unpack btree node"))
}
@ -765,7 +765,7 @@ fn perform_action(
}
fn explore(path: &Path, node_path: Option<Vec<u64>>) -> Result<()> {
let engine = SyncIoEngine::new(&path, 1, false)?;
let engine = SyncIoEngine::new(path, 1, false)?;
let mut panels: Vec<Box<dyn Panel>> = Vec::new();
@ -861,7 +861,7 @@ fn main() -> Result<()> {
.map(|text| btree::decode_node_path(text).unwrap());
let input_file = Path::new(matches.value_of("INPUT").unwrap());
explore(&input_file, node_path)
explore(input_file, node_path)
}
//------------------------------------

10
src/cache/check.rs vendored
View File

@ -92,10 +92,10 @@ mod format1 {
let mut errs: Vec<ArrayError> = Vec::new();
for m in b.values.iter() {
if let Err(e) = self.check_flags(&m) {
if let Err(e) = self.check_flags(m) {
errs.push(e);
}
if let Err(e) = self.check_oblock(&m) {
if let Err(e) = self.check_oblock(m) {
errs.push(e);
}
}
@ -182,10 +182,10 @@ mod format2 {
let cbegin = index as u32 * b.header.max_entries;
let cend = cbegin + b.header.nr_entries;
for (m, cblock) in b.values.iter().zip(cbegin..cend) {
if let Err(e) = self.check_flags(&m, inner.dirty_bits.contains(cblock as usize)) {
if let Err(e) = self.check_flags(m, inner.dirty_bits.contains(cblock as usize)) {
errs.push(e);
}
if let Err(e) = self.check_oblock(&m, &mut inner.seen_oblocks) {
if let Err(e) = self.check_oblock(m, &mut inner.seen_oblocks) {
errs.push(e);
}
}
@ -271,7 +271,7 @@ pub fn check(opts: CacheCheckOptions) -> anyhow::Result<()> {
let sb = match read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION) {
Ok(sb) => sb,
Err(e) => {
check_not_xml(&opts.dev, &opts.report);
check_not_xml(opts.dev, &opts.report);
return Err(e);
}
};

View File

@ -96,7 +96,7 @@ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
if version >= 2 {
let (m, root) = le_u64(i)?;
dirty_root = Some(root);
i = &m;
i = m;
}
Ok((

View File

@ -7,8 +7,8 @@ use std::process;
use std::sync::Arc;
use crate::cache::check::{check, CacheCheckOptions};
use crate::report::*;
use crate::commands::utils::*;
use crate::report::*;
//------------------------------------------
@ -76,7 +76,7 @@ pub fn run(args: &[std::ffi::OsString]) {
check_file_not_tiny(input_file, &report);
let opts = CacheCheckOptions {
dev: &input_file,
dev: input_file,
async_io: matches.is_present("ASYNC_IO"),
sb_only: matches.is_present("SB_ONLY"),
skip_mappings: matches.is_present("SKIP_MAPPINGS"),

View File

@ -60,8 +60,8 @@ pub fn run(args: &[std::ffi::OsString]) {
check_input_file(input_file, &report);
let opts = CacheRepairOptions {
input: &input_file,
output: &output_file,
input: input_file,
output: output_file,
async_io: matches.is_present("ASYNC_IO"),
report: report.clone(),
};

View File

@ -51,8 +51,8 @@ pub fn run(args: &[std::ffi::OsString]) {
check_output_file(output_file, &report);
let opts = CacheRestoreOptions {
input: &input_file,
output: &output_file,
input: input_file,
output: output_file,
async_io: matches.is_present("ASYNC_IO"),
report: report.clone(),
};

View File

@ -5,9 +5,9 @@ use std::path::Path;
use std::process;
use std::sync::Arc;
use crate::commands::utils::*;
use crate::io_engine::*;
use crate::thin::check::{check, ThinCheckOptions, MAX_CONCURRENT_IO};
use crate::commands::utils::*;
pub fn run(args: &[std::ffi::OsString]) {
let parser = App::new("thin_check")
@ -88,7 +88,7 @@ pub fn run(args: &[std::ffi::OsString]) {
.index(1),
);
let matches = parser.get_matches_from(args.into_iter());
let matches = parser.get_matches_from(args.iter());
let input_file = Path::new(matches.value_of("INPUT").unwrap());
let report = mk_report(matches.is_present("QUIET"));
@ -101,14 +101,13 @@ pub fn run(args: &[std::ffi::OsString]) {
if matches.is_present("ASYNC_IO") {
engine = Arc::new(
AsyncIoEngine::new(&input_file, MAX_CONCURRENT_IO, writable)
AsyncIoEngine::new(input_file, MAX_CONCURRENT_IO, writable)
.expect("unable to open input file"),
);
} else {
let nr_threads = std::cmp::max(8, num_cpus::get() * 2);
engine = Arc::new(
SyncIoEngine::new(&input_file, nr_threads, writable)
.expect("unable to open input file"),
SyncIoEngine::new(input_file, nr_threads, writable).expect("unable to open input file"),
);
}

View File

@ -31,7 +31,7 @@ pub fn run(args: &[std::ffi::OsString]) {
let report = std::sync::Arc::new(mk_simple_report());
check_input_file(input_file, &report);
if let Err(reason) = crate::pack::toplevel::pack(&input_file, &output_file) {
if let Err(reason) = crate::pack::toplevel::pack(input_file, output_file) {
report.fatal(&format!("Application error: {}\n", reason));
exit(1);
}

View File

@ -1,9 +1,9 @@
extern crate clap;
use crate::file_utils;
use clap::{App, Arg};
use std::path::Path;
use std::process;
use crate::file_utils;
use std::process::exit;
@ -37,7 +37,7 @@ pub fn run(args: &[std::ffi::OsString]) {
exit(1);
}
if let Err(reason) = crate::pack::toplevel::unpack(&input_file, &output_file) {
if let Err(reason) = crate::pack::toplevel::unpack(input_file, output_file) {
eprintln!("Application error: {}", reason);
process::exit(1);
}

View File

@ -91,8 +91,8 @@ pub fn run(args: &[std::ffi::OsString]) {
});
let opts = ThinRepairOptions {
input: &input_file,
output: &output_file,
input: input_file,
output: output_file,
async_io: matches.is_present("ASYNC_IO"),
report: report.clone(),
overrides: SuperblockOverrides {

View File

@ -51,8 +51,8 @@ pub fn run(args: &[std::ffi::OsString]) {
check_output_file(output_file, &report);
let opts = ThinRestoreOptions {
input: &input_file,
output: &output_file,
input: input_file,
output: output_file,
async_io: matches.is_present("ASYNC_IO"),
report: report.clone(),
};

View File

@ -70,7 +70,7 @@ pub fn run(args: &[std::ffi::OsString]) {
check_input_file(input_file, &report);
if let Err(reason) =
crate::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size, do_copy)
crate::shrink::toplevel::shrink(input_file, output_file, data_file, size, do_copy)
{
eprintln!("Application error: {}\n", reason);
exit(1);

View File

@ -10,10 +10,7 @@ use crate::report::*;
pub fn check_input_file(input_file: &Path, report: &Report) {
if !file_utils::file_exists(input_file) {
report.fatal(&format!(
"Couldn't find input file '{:?}'.",
&input_file
));
report.fatal(&format!("Couldn't find input file '{:?}'.", &input_file));
exit(1);
}
@ -62,15 +59,11 @@ pub fn mk_report(quiet: bool) -> std::sync::Arc<Report> {
}
fn is_xml(line: &[u8]) -> bool {
line.starts_with(b"<superblock") ||
line.starts_with(b"?xml") ||
line.starts_with(b"<!DOCTYPE")
line.starts_with(b"<superblock") || line.starts_with(b"?xml") || line.starts_with(b"<!DOCTYPE")
}
pub fn check_not_xml_(input_file: &Path, report: &Report) -> Result<()> {
let mut file = OpenOptions::new()
.read(true)
.open(input_file)?;
let mut file = OpenOptions::new().read(true).open(input_file)?;
let mut data = vec![0; 16];
file.read_exact(&mut data)?;

View File

@ -18,28 +18,19 @@ pub fn is_file_or_blk_(info: FileStat) -> bool {
}
pub fn file_exists(path: &Path) -> bool {
match stat::stat(path) {
Ok(_) => true,
_ => false,
}
matches!(stat::stat(path), Ok(_))
}
pub fn is_file_or_blk(path: &Path) -> bool {
match stat::stat(path) {
Ok(info) =>is_file_or_blk_(info),
Ok(info) => is_file_or_blk_(info),
_ => false,
}
}
pub fn is_file(path: &Path) -> bool {
match stat::stat(path) {
Ok(info) => {
if test_bit(info.st_mode, SFlag::S_IFREG) {
true
} else {
false
}
}
Ok(info) => test_bit(info.st_mode, SFlag::S_IFREG),
_ => false,
}
}
@ -113,5 +104,3 @@ pub fn create_sized_file(path: &Path, nr_bytes: u64) -> io::Result<std::fs::File
}
//---------------------------------------

View File

@ -109,7 +109,7 @@ impl<'a> Deref for FileGuard<'a> {
type Target = File;
fn deref(&self) -> &File {
&self.file.as_ref().expect("empty file guard")
self.file.as_ref().expect("empty file guard")
}
}
@ -180,7 +180,7 @@ impl SyncIoEngine {
fn write_(output: &mut File, b: &Block) -> Result<()> {
output.seek(io::SeekFrom::Start(b.loc * BLOCK_SIZE as u64))?;
output.write_all(&b.get_data())?;
output.write_all(b.get_data())?;
Ok(())
}
}

View File

@ -66,7 +66,7 @@ fn mk_chunk_vecs(nr_blocks: u64, nr_jobs: u64) -> Vec<Vec<(u64, u64)>> {
}
pub fn pack(input_file: &Path, output_file: &Path) -> Result<(), Box<dyn Error>> {
let nr_blocks = get_nr_blocks(&input_file)?;
let nr_blocks = get_nr_blocks(input_file)?;
let nr_jobs = std::cmp::max(1, std::cmp::min(num_cpus::get() as u64, nr_blocks / 128));
let chunk_vecs = mk_chunk_vecs(nr_blocks, nr_jobs);
@ -122,7 +122,7 @@ where
let kind = metadata_block_type(data);
if kind != BT::UNKNOWN {
z.write_u64::<LittleEndian>(b)?;
pack_block(&mut z, kind, &data)?;
pack_block(&mut z, kind, data)?;
written += 1;
if written == 1024 {

View File

@ -442,7 +442,7 @@ mod tests {
let mut r = Cursor::new(&mut bs);
let unpacked = unpack(&mut r, ns.len() * 8).unwrap();
check_u64s_match(&ns, &unpacked[0..])
check_u64s_match(ns, &unpacked[0..])
}
#[test]
@ -457,7 +457,7 @@ mod tests {
];
for t in &cases {
assert!(check_pack_u64s(&t));
assert!(check_pack_u64s(t));
}
}

View File

@ -77,7 +77,7 @@ impl<'a, V: Unpack + Copy> NodeVisitor<u64> for BlockValueVisitor<'a, V> {
for (i, b) in values.iter().enumerate() {
// TODO: report indices of array entries based on the type size
let mut array_errs = self.array_errs.lock().unwrap();
array_errs.push(array::io_err(&path, *b).index_context(keys[i]));
array_errs.push(array::io_err(path, *b).index_context(keys[i]));
}
}
Ok(rblocks) => {
@ -85,7 +85,7 @@ impl<'a, V: Unpack + Copy> NodeVisitor<u64> for BlockValueVisitor<'a, V> {
match rb {
Err(_) => {
let mut array_errs = self.array_errs.lock().unwrap();
array_errs.push(array::io_err(&path, values[i]).index_context(keys[i]));
array_errs.push(array::io_err(path, values[i]).index_context(keys[i]));
}
Ok(b) => {
let mut path = path.to_vec();

View File

@ -561,7 +561,7 @@ pub fn unpack_node<V: Unpack>(
if let Some(l) = last {
if k <= l {
return Err(node_err(
&path,
path,
&format!("keys out of order: {} <= {}", k, l),
));
}
@ -582,7 +582,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,

View File

@ -132,10 +132,10 @@ impl<'a> LeafWalker<'a> {
.keys_context(kr));
}
let node = unpack_node::<V>(path, &b.get_data(), self.ignore_non_fatal, is_root)?;
let node = unpack_node::<V>(path, b.get_data(), self.ignore_non_fatal, is_root)?;
if let Internal { keys, values, .. } = node {
let krs = split_key_ranges(path, &kr, &keys)?;
let krs = split_key_ranges(path, kr, &keys)?;
if depth == 0 {
// it is the lowest internal
for i in 0..krs.len() {
@ -187,7 +187,7 @@ impl<'a> LeafWalker<'a> {
));
}
let node = unpack_node::<V>(path, &b.get_data(), self.ignore_non_fatal, is_root)?;
let node = unpack_node::<V>(path, b.get_data(), self.ignore_non_fatal, is_root)?;
match node {
Internal { values, .. } => {

View File

@ -195,11 +195,11 @@ impl BTreeWalker {
.keys_context(kr));
}
let node = unpack_node::<V>(path, &b.get_data(), self.ignore_non_fatal, is_root)?;
let node = unpack_node::<V>(path, b.get_data(), self.ignore_non_fatal, is_root)?;
match node {
Internal { keys, values, .. } => {
let krs = split_key_ranges(path, &kr, &keys)?;
let krs = split_key_ranges(path, kr, &keys)?;
let errs = self.walk_nodes(path, visitor, &krs, &values);
return self.build_aggregate(b.loc, errs);
}
@ -208,7 +208,7 @@ impl BTreeWalker {
keys,
values,
} => {
if let Err(e) = visitor.visit(path, &kr, &header, &keys, &values) {
if let Err(e) = visitor.visit(path, kr, &header, &keys, &values) {
let e = BTreeError::Path(path.clone(), Box::new(e));
self.set_fail(b.loc, e.clone());
return Err(e);
@ -286,11 +286,11 @@ where
.keys_context(kr));
}
let node = unpack_node::<V>(path, &b.get_data(), w.ignore_non_fatal, is_root)?;
let node = unpack_node::<V>(path, b.get_data(), w.ignore_non_fatal, is_root)?;
match node {
Internal { keys, values, .. } => {
let krs = split_key_ranges(path, &kr, &keys)?;
let krs = split_key_ranges(path, kr, &keys)?;
let errs = walk_nodes_threaded(w.clone(), path, pool, visitor, &krs, &values);
return w.build_aggregate(b.loc, errs);
}

View File

@ -109,7 +109,7 @@ fn check_low_ref_counts(
return Err(anyhow!("Unable to read bitmap block"));
}
Ok(b) => {
if checksum::metadata_block_type(&b.get_data()) != checksum::BT::BITMAP {
if checksum::metadata_block_type(b.get_data()) != checksum::BT::BITMAP {
report.fatal(&format!(
"Index entry points to block ({}) that isn't a bitmap",
b.loc

View File

@ -117,7 +117,7 @@ impl ReportInner for PBInner {
fn set_sub_title(&mut self, txt: &str) {
//let mut fmt = "".to_string(); //Checking thin metadata".to_string(); //self.title.clone();
let mut fmt = "Checking thin metadata [{bar:40}] Remaining {eta}, ".to_string();
fmt.push_str(&txt);
fmt.push_str(txt);
self.bar.set_style(
ProgressStyle::default_bar()
.template(&fmt)

View File

@ -343,16 +343,16 @@ fn find_first(r: &BlockRange, remaps: &[(BlockRange, BlockRange)]) -> Option<usi
Err(n) => {
if n == 0 {
let (from, _) = &remaps[n];
overlaps(&r, &from, n)
overlaps(r, from, n)
} else if n == remaps.len() {
let (from, _) = &remaps[n - 1];
overlaps(&r, from, n - 1)
overlaps(r, from, n - 1)
} else {
// Need to check the previous entry
let (from, _) = &remaps[n - 1];
overlaps(&r, &from, n - 1).or_else(|| {
overlaps(r, from, n - 1).or_else(|| {
let (from, _) = &remaps[n];
overlaps(&r, &from, n)
overlaps(r, from, n)
})
}
}
@ -368,7 +368,7 @@ fn remap(r: &BlockRange, remaps: &[(BlockRange, BlockRange)]) -> Vec<BlockRange>
let mut remap = Vec::new();
let mut r = r.start..r.end;
if let Some(index) = find_first(&r, &remaps) {
if let Some(index) = find_first(&r, remaps) {
let mut index = index;
loop {
let (from, to) = &remaps[index];
@ -487,7 +487,7 @@ fn build_copy_regions(remaps: &[(BlockRange, BlockRange)], block_size: u64) -> V
rs.push(Region {
src: from.start * block_size,
dest: to.start * block_size,
len: range_len(&from) * block_size,
len: range_len(from) * block_size,
});
}

View File

@ -188,7 +188,7 @@ fn emit_leaf(v: &mut MappingVisitor, b: &Block) -> Result<()> {
)));
}
let node = unpack_node::<BlockTime>(&path, &b.get_data(), true, true)?;
let node = unpack_node::<BlockTime>(&path, b.get_data(), true, true)?;
match node {
Internal { .. } => {

View File

@ -153,7 +153,7 @@ impl<'a> Restorer<'a> {
};
for (_, leaves) in self.sub_trees.iter() {
release_leaves(self.w, &leaves, &mut value_rc)?;
release_leaves(self.w, leaves, &mut value_rc)?;
}
Ok(())

View File

@ -125,7 +125,7 @@ impl Gatherer {
// Now we need to mark entries that follow a tail as heads.
let mut heads = mem::take(&mut self.heads);
for t in &self.tails {
if let Some(e) = self.entries.get(&t) {
if let Some(e) = self.entries.get(t) {
for n in &e.neighbours {
heads.insert(*n);
}

View File

@ -13,8 +13,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_check 0.9.0
const USAGE: &str = "cache_check 0.9.0
USAGE:
cache_check [FLAGS] <INPUT>
@ -105,7 +104,10 @@ fn failing_q() -> Result<()> {
let md = mk_zeroed_md(&mut td)?;
let output = run_fail_raw(cache_check_cmd(args!["-q", &md]))?;
assert_eq!(output.stdout.len(), 0);
eprintln!("stderr = '{}'", std::str::from_utf8(&output.stderr).unwrap());
eprintln!(
"stderr = '{}'",
std::str::from_utf8(&output.stderr).unwrap()
);
assert_eq!(output.stderr.len(), 0);
Ok(())
}
@ -128,7 +130,6 @@ fn valid_metadata_passes() -> Result<()> {
Ok(())
}
// FIXME: put back in, I don't want to add the --debug- arg to the
// tool again, so we should have a little library function for tweaking
// metadata version.

View File

@ -12,8 +12,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_repair 0.9.0
const USAGE: &str = "cache_repair 0.9.0
Repair binary cache metadata, and write it to a different device or file
USAGE:

View File

@ -14,8 +14,7 @@ use common::test_dir::*;
//------------------------------------------
const USAGE: &str =
"cache_restore 0.9.0
const USAGE: &str = "cache_restore 0.9.0
Convert XML format metadata to binary.
USAGE:

View File

@ -64,7 +64,7 @@ impl XmlGen for CacheGen {
let mut cblocks = (0..self.nr_cache_blocks).collect::<Vec<u32>>();
cblocks.shuffle(&mut rand::thread_rng());
cblocks.truncate(nr_resident as usize);
cblocks.sort();
cblocks.sort_unstable();
v.mappings_b()?;
{

View File

@ -222,9 +222,8 @@ where
let wrapper = build_args_fn(P::arg_type())?;
wrapper(&mut td, input.as_ref(), &|args: &[&OsStr]| {
let stderr = run_fail(P::cmd(args))?;
let msg = format!(
"This looks like XML. This tool only checks the binary metadata format.",
);
let msg =
"This looks like XML. This tool only checks the binary metadata format.".to_string();
assert!(stderr.contains(&msg));
Ok(())
})

View File

@ -57,10 +57,10 @@ impl fmt::Display for Command {
fn log_output(output: &process::Output) {
use std::str::from_utf8;
if output.stdout.len() > 0 {
if !output.stdout.is_empty() {
eprintln!("stdout: \n{}<<END>>", from_utf8(&output.stdout).unwrap());
}
if output.stderr.len() > 0 {
if !output.stderr.is_empty() {
eprintln!("stderr: \n{}<<END>>", from_utf8(&output.stderr).unwrap());
}
}

View File

@ -118,7 +118,7 @@ pub fn generate_metadata_leaks(
pub fn get_needs_check(md: &PathBuf) -> Result<bool> {
use thinp::thin::superblock::*;
let engine = SyncIoEngine::new(&md, 1, false)?;
let engine = SyncIoEngine::new(md, 1, false)?;
let sb = read_superblock(&engine, SUPERBLOCK_LOCATION)?;
Ok(sb.flags.needs_check)
}

View File

@ -145,11 +145,11 @@ fn accepts_quiet() -> Result<()> {
let md = mk_valid_md(&mut td)?;
let output = run_ok_raw(thin_check_cmd(args!["--quiet", &md]))?;
if output.stdout.len() > 0 {
if !output.stdout.is_empty() {
eprintln!("stdout: {:?}", &std::str::from_utf8(&output.stdout));
}
if output.stderr.len() > 0 {
if !output.stderr.is_empty() {
eprintln!("stderr: {:?}", &std::str::from_utf8(&output.stderr));
}
assert_eq!(output.stdout.len(), 0);

View File

@ -15,8 +15,7 @@ use common::thin::*;
//------------------------------------------
const USAGE: &str =
"thin_dump 0.9.0
const USAGE: &str = "thin_dump 0.9.0
Dump thin-provisioning metadata to stdout in XML format
USAGE:
@ -178,15 +177,13 @@ fn repair_superblock() -> Result<()> {
let before = run_ok_raw(thin_dump_cmd(args![&md]))?;
damage_superblock(&md)?;
let after = run_ok_raw(thin_dump_cmd(
args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
],
))?;
let after = run_ok_raw(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
]))?;
if !cfg!(feature = "rust_tests") {
assert_eq!(after.stderr.len(), 0);
}
@ -204,15 +201,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_cmd(
args![
"--repair",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--data-block-size=128",
"--nr-data-blocks=20480",
&md
]))?;
assert!(stderr.contains("transaction id"));
Ok(())
}
@ -222,15 +216,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_cmd(
args![
"--repair",
"--transaction-id=1",
"--nr-data-blocks=20480",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--nr-data-blocks=20480",
&md
]))?;
assert!(stderr.contains("data block size"));
Ok(())
}
@ -240,15 +231,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_cmd(
args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
&md
],
))?;
let stderr = run_fail(thin_dump_cmd(args![
"--repair",
"--transaction-id=1",
"--data-block-size=128",
&md
]))?;
assert!(stderr.contains("nr data blocks"));
Ok(())
}

View File

@ -106,8 +106,18 @@ fn end_to_end() -> Result<()> {
let mut td = TestDir::new()?;
let md_in = mk_valid_md(&mut td)?;
let md_out = mk_zeroed_md(&mut td)?;
run_ok(thin_metadata_pack_cmd(args!["-i", &md_in, "-o", "meta.pack"]))?;
run_ok(thin_metadata_unpack_cmd(args!["-i", "meta.pack", "-o", &md_out]))?;
run_ok(thin_metadata_pack_cmd(args![
"-i",
&md_in,
"-o",
"meta.pack"
]))?;
run_ok(thin_metadata_unpack_cmd(args![
"-i",
"meta.pack",
"-o",
&md_out
]))?;
let dump1 = run_ok(thin_dump_cmd(args![&md_in]))?;
let dump2 = run_ok(thin_dump_cmd(args![&md_out]))?;

View File

@ -161,18 +161,15 @@ fn superblock_succeeds() -> Result<()> {
}
damage_superblock(&md1)?;
let md2 = mk_zeroed_md(&mut td)?;
run_ok(
thin_repair_cmd(
args![
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
"-i",
&md1,
"-o",
&md2
],
))?;
run_ok(thin_repair_cmd(args![
"--transaction-id=1",
"--data-block-size=128",
"--nr-data-blocks=20480",
"-i",
&md1,
"-o",
&md2
]))?;
let repaired = run_ok_raw(thin_dump_cmd(args![&md2]))?;
if !cfg!(feature = "rust_tests") {
assert_eq!(repaired.stderr.len(), 0);