2020-09-22 16:31:17 +05:30
|
|
|
// This work is based on the implementation by Nikhil Kshirsagar which
|
|
|
|
// can be found here:
|
|
|
|
// https://github.com/nkshirsagar/thinpool_shrink/blob/split_ranges/thin_shrink.py
|
|
|
|
|
2020-06-24 18:02:47 +05:30
|
|
|
extern crate clap;
|
|
|
|
extern crate thinp;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
2020-06-29 15:19:40 +05:30
|
|
|
use std::path::Path;
|
2020-06-24 18:02:47 +05:30
|
|
|
use std::process::exit;
|
|
|
|
use thinp::file_utils;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let parser = App::new("thin_shrink")
|
2021-05-11 23:42:11 +05:30
|
|
|
.version(thinp::version::tools_version())
|
2020-06-24 18:02:47 +05:30
|
|
|
.about("Rewrite xml metadata and move data in an inactive pool.")
|
2020-06-25 15:14:57 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("INPUT")
|
|
|
|
.help("Specify thinp metadata xml file")
|
|
|
|
.required(true)
|
|
|
|
.long("input")
|
|
|
|
.value_name("INPUT")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("OUTPUT")
|
|
|
|
.help("Specify output xml file")
|
|
|
|
.required(true)
|
|
|
|
.long("output")
|
|
|
|
.value_name("OUTPUT")
|
|
|
|
.takes_value(true),
|
|
|
|
)
|
2020-06-25 19:58:45 +05:30
|
|
|
.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),
|
|
|
|
)
|
2020-06-26 13:27:26 +05:30
|
|
|
.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),
|
|
|
|
)
|
2020-06-25 15:14:57 +05:30
|
|
|
.arg(
|
|
|
|
Arg::with_name("SIZE")
|
|
|
|
.help("Specify new size for the pool (in data blocks)")
|
|
|
|
.required(true)
|
|
|
|
.long("nr-blocks")
|
|
|
|
.value_name("SIZE")
|
|
|
|
.takes_value(true),
|
|
|
|
);
|
2020-06-24 18:02:47 +05:30
|
|
|
|
|
|
|
let matches = parser.get_matches();
|
|
|
|
|
|
|
|
// FIXME: check these look like xml
|
2020-06-29 15:19:40 +05:30
|
|
|
let input_file = Path::new(matches.value_of("INPUT").unwrap());
|
|
|
|
let output_file = Path::new(matches.value_of("OUTPUT").unwrap());
|
2020-06-25 15:14:57 +05:30
|
|
|
let size = matches.value_of("SIZE").unwrap().parse::<u64>().unwrap();
|
2020-06-29 15:19:40 +05:30
|
|
|
let data_file = Path::new(matches.value_of("DATA").unwrap());
|
2020-06-26 13:27:26 +05:30
|
|
|
let do_copy = !matches.is_present("NOCOPY");
|
2020-06-24 18:02:47 +05:30
|
|
|
|
|
|
|
if !file_utils::file_exists(input_file) {
|
2020-06-29 15:19:40 +05:30
|
|
|
eprintln!("Couldn't find input file '{}'.", input_file.display());
|
2020-06-24 18:02:47 +05:30
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-06-29 15:19:40 +05:30
|
|
|
if let Err(reason) =
|
|
|
|
thinp::shrink::toplevel::shrink(&input_file, &output_file, &data_file, size, do_copy)
|
|
|
|
{
|
2020-06-24 18:02:47 +05:30
|
|
|
println!("Application error: {}\n", reason);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|