2021-07-20 15:07:55 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use thinp::file_utils;
|
|
|
|
use thinp::io_engine::*;
|
|
|
|
|
2021-07-20 23:41:46 +05:30
|
|
|
use crate::args;
|
2021-07-20 15:07:55 +05:30
|
|
|
use crate::common::fixture::*;
|
|
|
|
use crate::common::process::*;
|
|
|
|
use crate::common::target::*;
|
|
|
|
use crate::common::test_dir::TestDir;
|
|
|
|
use crate::common::thin_xml_generator::{write_xml, SingleThinS};
|
|
|
|
|
|
|
|
//-----------------------------------------------
|
|
|
|
|
|
|
|
pub fn mk_valid_xml(td: &mut TestDir) -> Result<PathBuf> {
|
|
|
|
let xml = td.mk_path("meta.xml");
|
|
|
|
let mut gen = SingleThinS::new(0, 1024, 2048, 2048);
|
|
|
|
write_xml(&xml, &mut gen)?;
|
|
|
|
Ok(xml)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn mk_valid_md(td: &mut TestDir) -> Result<PathBuf> {
|
|
|
|
let xml = td.mk_path("meta.xml");
|
|
|
|
let md = td.mk_path("meta.bin");
|
|
|
|
|
|
|
|
let mut gen = SingleThinS::new(0, 1024, 20480, 20480);
|
|
|
|
write_xml(&xml, &mut gen)?;
|
|
|
|
|
|
|
|
let _file = file_utils::create_sized_file(&md, 4096 * 4096);
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args!["-i", &xml, "-o", &md];
|
2021-07-20 15:07:55 +05:30
|
|
|
run_ok(THIN_RESTORE, &args)?;
|
|
|
|
|
|
|
|
Ok(md)
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------
|
|
|
|
|
|
|
|
// FIXME: replace mk_valid_md with this?
|
|
|
|
pub fn prep_metadata(td: &mut TestDir) -> Result<PathBuf> {
|
|
|
|
let md = mk_zeroed_md(td)?;
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args!["-o", &md, "--format", "--nr-data-blocks", "102400"];
|
2021-07-20 15:07:55 +05:30
|
|
|
run_ok(THIN_GENERATE_METADATA, &args)?;
|
|
|
|
|
|
|
|
// Create a 2GB device
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args!["-o", &md, "--create-thin", "1"];
|
2021-07-20 15:07:55 +05:30
|
|
|
run_ok(THIN_GENERATE_METADATA, &args)?;
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args![
|
2021-07-20 15:07:55 +05:30
|
|
|
"-o",
|
2021-07-20 23:41:46 +05:30
|
|
|
&md,
|
2021-07-20 15:07:55 +05:30
|
|
|
"--dev-id",
|
|
|
|
"1",
|
|
|
|
"--size",
|
|
|
|
"2097152",
|
|
|
|
"--rw=randwrite",
|
2021-07-20 23:41:46 +05:30
|
|
|
"--seq-nr=16"
|
2021-07-20 15:07:55 +05:30
|
|
|
];
|
|
|
|
run_ok(THIN_GENERATE_MAPPINGS, &args)?;
|
|
|
|
|
|
|
|
// Take a few snapshots.
|
|
|
|
let mut snap_id = 2;
|
|
|
|
for _i in 0..10 {
|
|
|
|
// take a snapshot
|
2021-07-20 23:41:46 +05:30
|
|
|
let snap_id_str = snap_id.to_string();
|
|
|
|
let args = args!["-o", &md, "--create-snap", &snap_id_str, "--origin", "1"];
|
2021-07-20 15:07:55 +05:30
|
|
|
run_ok(THIN_GENERATE_METADATA, &args)?;
|
|
|
|
|
|
|
|
// partially overwrite the origin (64MB)
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args![
|
2021-07-20 15:07:55 +05:30
|
|
|
"-o",
|
2021-07-20 23:41:46 +05:30
|
|
|
&md,
|
2021-07-20 15:07:55 +05:30
|
|
|
"--dev-id",
|
|
|
|
"1",
|
|
|
|
"--size",
|
|
|
|
"2097152",
|
|
|
|
"--io-size",
|
|
|
|
"131072",
|
|
|
|
"--rw=randwrite",
|
2021-07-20 23:41:46 +05:30
|
|
|
"--seq-nr=16"
|
2021-07-20 15:07:55 +05:30
|
|
|
];
|
|
|
|
run_ok(THIN_GENERATE_MAPPINGS, &args)?;
|
|
|
|
snap_id += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(md)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_needs_check(md: &PathBuf) -> Result<()> {
|
2021-07-20 23:41:46 +05:30
|
|
|
let args = args!["-o", &md, "--set-needs-check"];
|
2021-07-20 15:07:55 +05:30
|
|
|
run_ok(THIN_GENERATE_METADATA, &args)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn generate_metadata_leaks(
|
|
|
|
md: &PathBuf,
|
|
|
|
nr_blocks: u64,
|
|
|
|
expected: u32,
|
|
|
|
actual: u32,
|
|
|
|
) -> Result<()> {
|
2021-07-20 23:41:46 +05:30
|
|
|
let nr_blocks_str = nr_blocks.to_string();
|
|
|
|
let expected_str = expected.to_string();
|
|
|
|
let actual_str = actual.to_string();
|
|
|
|
let args = args![
|
2021-07-20 15:07:55 +05:30
|
|
|
"-o",
|
2021-07-20 23:41:46 +05:30
|
|
|
&md,
|
2021-07-20 15:07:55 +05:30
|
|
|
"--create-metadata-leaks",
|
|
|
|
"--nr-blocks",
|
2021-07-20 23:41:46 +05:30
|
|
|
&nr_blocks_str,
|
2021-07-20 15:07:55 +05:30
|
|
|
"--expected",
|
2021-07-20 23:41:46 +05:30
|
|
|
&expected_str,
|
2021-07-20 15:07:55 +05:30
|
|
|
"--actual",
|
2021-07-20 23:41:46 +05:30
|
|
|
&actual_str
|
2021-07-20 15:07:55 +05:30
|
|
|
];
|
|
|
|
run_ok(THIN_GENERATE_DAMAGE, &args)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_needs_check(md: &PathBuf) -> Result<bool> {
|
|
|
|
use thinp::thin::superblock::*;
|
|
|
|
|
|
|
|
let engine = SyncIoEngine::new(&md, 1, false)?;
|
|
|
|
let sb = read_superblock(&engine, SUPERBLOCK_LOCATION)?;
|
|
|
|
Ok(sb.flags.needs_check)
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------
|