[thin_shrink] Stub the copier

This commit is contained in:
Joe Thornber 2020-06-25 15:28:45 +01:00
parent d8957e3d86
commit 31abc468be
4 changed files with 41 additions and 7 deletions

View File

@ -25,7 +25,14 @@ fn main() {
.value_name("OUTPUT") .value_name("OUTPUT")
.takes_value(true), .takes_value(true),
) )
// FIXME: support various disk units .arg(
Arg::with_name("DATA")
.help("Specify pool data device where data will be moved")
.required(true)
.long("data")
.value_name("DATA")
.takes_value(true),
)
.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)")
@ -41,13 +48,14 @@ fn main() {
let input_file = matches.value_of("INPUT").unwrap(); let input_file = matches.value_of("INPUT").unwrap();
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();
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, size) { if let Err(reason) = thinp::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size) {
println!("Application error: {}\n", reason); println!("Application error: {}\n", reason);
exit(1); exit(1);
} }

14
src/shrink/copier.rs Normal file
View File

@ -0,0 +1,14 @@
use anyhow::Result;
pub type Sector = u64;
pub struct Region {
src: Sector,
dest: Sector,
len: Sector,
}
// FIXME: pass in
pub fn copy(path: &str, regions: &Vec<Region>) -> Result<()> {
Ok(())
}

View File

@ -1,3 +1,4 @@
pub mod toplevel; pub mod toplevel;
mod copier;
mod xml; mod xml;

View File

@ -5,6 +5,7 @@ use std::io::Write;
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
use crate::shrink::xml; use crate::shrink::xml;
use crate::shrink::copier::{self, Region};
//--------------------------------------- //---------------------------------------
@ -268,7 +269,7 @@ fn overlaps(r1: &BlockRange, r2: &BlockRange, index: usize) -> Option<usize> {
// Finds the index of the first entry that overlaps r. // Finds the index of the first entry that overlaps r.
fn find_first(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Option<usize> { fn find_first(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Option<usize> {
if remaps.len() == 0 { if remaps.len() == 0 {
return None return None;
} }
match remaps.binary_search_by_key(&r.start, |(from, _)| from.start) { match remaps.binary_search_by_key(&r.start, |(from, _)| from.start) {
@ -319,9 +320,9 @@ fn remap(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Vec<BlockRan
} }
} }
let to = (to.start + (r.start - from.start))..to.end; let to = (to.start + (r.start - from.start))..to.end;
let from = r.start..from.end; let from = r.start..from.end;
println!("to = {:?}", to); println!("to = {:?}", to);
let rlen = range_len(&r); let rlen = range_len(&r);
let flen = range_len(&from); let flen = range_len(&from);
@ -417,6 +418,11 @@ mod tests {
} }
} }
fn build_copy_regions(remaps: &Vec<(BlockRange, BlockRange)>) -> Vec<Region> {
let rs = Vec::new();
rs
}
fn process_xml<MV: xml::MetadataVisitor>(input_path: &str, pass: &mut MV) -> Result<()> { fn process_xml<MV: xml::MetadataVisitor>(input_path: &str, pass: &mut MV) -> Result<()> {
let input = OpenOptions::new() let input = OpenOptions::new()
.read(true) .read(true)
@ -428,7 +434,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, nr_blocks: u64) -> Result<()> { pub fn shrink(input_path: &str, output_path: &str, data_path: &str, nr_blocks: u64) -> Result<()> {
let mut pass1 = Pass1::new(nr_blocks); let mut pass1 = Pass1::new(nr_blocks);
process_xml(input_path, &mut pass1); process_xml(input_path, &mut pass1);
eprintln!("{} blocks need moving", pass1.nr_high_blocks); eprintln!("{} blocks need moving", pass1.nr_high_blocks);
@ -465,6 +471,11 @@ pub fn shrink(input_path: &str, output_path: &str, nr_blocks: u64) -> Result<()>
let remaps = build_remaps(above, free); let remaps = build_remaps(above, free);
eprintln!("remappings {:?}.", remaps); eprintln!("remappings {:?}.", remaps);
let regions = build_copy_regions(&remaps);
eprint!("Copying data...");
copier::copy(data_path, &regions);
eprintln!("done.");
let output = OpenOptions::new() let output = OpenOptions::new()
.read(false) .read(false)
.write(true) .write(true)