[thin_shrink] add --no-copy

This commit is contained in:
Joe Thornber 2020-06-26 08:57:26 +01:00
parent abf06236b1
commit 07da5704d5
2 changed files with 17 additions and 4 deletions

View File

@ -33,6 +33,14 @@ fn main() {
.value_name("DATA") .value_name("DATA")
.takes_value(true), .takes_value(true),
) )
.arg(
Arg::with_name("NOCOPY")
.help("Skip the copying of data, useful for benchmarking")
.required(false)
.long("no-copy")
.value_name("NOCOPY")
.takes_value(false),
)
.arg( .arg(
Arg::with_name("SIZE") Arg::with_name("SIZE")
.help("Specify new size for the pool (in data blocks)") .help("Specify new size for the pool (in data blocks)")
@ -49,13 +57,14 @@ fn main() {
let output_file = matches.value_of("OUTPUT").unwrap(); let output_file = matches.value_of("OUTPUT").unwrap();
let size = matches.value_of("SIZE").unwrap().parse::<u64>().unwrap(); let size = matches.value_of("SIZE").unwrap().parse::<u64>().unwrap();
let data_file = matches.value_of("DATA").unwrap(); let data_file = matches.value_of("DATA").unwrap();
let do_copy = !matches.is_present("NOCOPY");
if !file_utils::file_exists(input_file) { if !file_utils::file_exists(input_file) {
eprintln!("Couldn't find input file '{}'.", &input_file); eprintln!("Couldn't find input file '{}'.", &input_file);
exit(1); exit(1);
} }
if let Err(reason) = thinp::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size) { if let Err(reason) = thinp::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size, do_copy) {
println!("Application error: {}\n", reason); println!("Application error: {}\n", reason);
exit(1); exit(1);
} }

View File

@ -433,7 +433,7 @@ fn process_xml<MV: xml::MetadataVisitor>(input_path: &str, pass: &mut MV) -> Res
Ok(()) Ok(())
} }
pub fn shrink(input_path: &str, output_path: &str, data_path: &str, nr_blocks: u64) -> Result<()> { pub fn shrink(input_path: &str, output_path: &str, data_path: &str, nr_blocks: u64, do_copy: bool) -> Result<()> {
let mut pass1 = Pass1::new(nr_blocks); let mut pass1 = Pass1::new(nr_blocks);
eprint!("Reading xml..."); eprint!("Reading xml...");
process_xml(input_path, &mut pass1)?; process_xml(input_path, &mut pass1)?;
@ -454,8 +454,12 @@ pub fn shrink(input_path: &str, output_path: &str, data_path: &str, nr_blocks: u
let remaps = build_remaps(above, free); let remaps = build_remaps(above, free);
let regions = build_copy_regions(&remaps, pass1.block_size.unwrap() as u64); if do_copy {
copier::copy(data_path, &regions)?; let regions = build_copy_regions(&remaps, pass1.block_size.unwrap() as u64);
copier::copy(data_path, &regions)?;
} else {
eprintln!("skipping copy");
}
let output = OpenOptions::new() let output = OpenOptions::new()
.read(false) .read(false)