[thin_shrink] Stub the copier
This commit is contained in:
parent
d8957e3d86
commit
31abc468be
@ -25,7 +25,14 @@ fn main() {
|
||||
.value_name("OUTPUT")
|
||||
.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::with_name("SIZE")
|
||||
.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 output_file = matches.value_of("OUTPUT").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) {
|
||||
eprintln!("Couldn't find input file '{}'.", &input_file);
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
14
src/shrink/copier.rs
Normal file
14
src/shrink/copier.rs
Normal 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(())
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod toplevel;
|
||||
|
||||
mod copier;
|
||||
mod xml;
|
||||
|
@ -5,6 +5,7 @@ use std::io::Write;
|
||||
use std::os::unix::fs::OpenOptionsExt;
|
||||
|
||||
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.
|
||||
fn find_first(r: &BlockRange, remaps: &Vec<(BlockRange, BlockRange)>) -> Option<usize> {
|
||||
if remaps.len() == 0 {
|
||||
return None
|
||||
return None;
|
||||
}
|
||||
|
||||
match remaps.binary_search_by_key(&r.start, |(from, _)| from.start) {
|
||||
@ -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<()> {
|
||||
let input = OpenOptions::new()
|
||||
.read(true)
|
||||
@ -428,7 +434,7 @@ fn process_xml<MV: xml::MetadataVisitor>(input_path: &str, pass: &mut MV) -> Res
|
||||
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);
|
||||
process_xml(input_path, &mut pass1);
|
||||
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);
|
||||
eprintln!("remappings {:?}.", remaps);
|
||||
|
||||
let regions = build_copy_regions(&remaps);
|
||||
eprint!("Copying data...");
|
||||
copier::copy(data_path, ®ions);
|
||||
eprintln!("done.");
|
||||
|
||||
let output = OpenOptions::new()
|
||||
.read(false)
|
||||
.write(true)
|
||||
|
Loading…
Reference in New Issue
Block a user