2020-07-28 15:21:48 +05:30
|
|
|
use anyhow::{anyhow, Result};
|
2020-08-11 17:52:14 +05:30
|
|
|
use indicatif::{ProgressBar, ProgressStyle};
|
2020-07-30 14:42:51 +05:30
|
|
|
use nom::{number::complete::*, IResult};
|
2020-08-08 21:12:32 +05:30
|
|
|
use std::collections::BTreeMap;
|
2020-07-27 20:23:42 +05:30
|
|
|
use std::path::Path;
|
2020-08-11 17:52:14 +05:30
|
|
|
use std::sync::mpsc::{channel, Receiver, Sender, TryRecvError};
|
2020-07-27 20:23:42 +05:30
|
|
|
use std::sync::{Arc, Mutex};
|
2020-08-11 17:52:14 +05:30
|
|
|
use std::{thread, time};
|
2020-07-29 21:08:52 +05:30
|
|
|
use threadpool::ThreadPool;
|
2020-06-09 13:45:00 +05:30
|
|
|
|
2020-08-08 21:12:32 +05:30
|
|
|
use crate::checksum;
|
2020-08-10 17:26:41 +05:30
|
|
|
use crate::io_engine::{AsyncIoEngine, Block, IoEngine, SyncIoEngine};
|
2020-08-11 15:20:43 +05:30
|
|
|
use crate::pdata::btree::{btree_to_map, btree_to_map_with_sm, BTreeWalker, Node, NodeVisitor};
|
2020-08-06 12:21:48 +05:30
|
|
|
use crate::pdata::space_map::*;
|
2020-08-11 15:20:43 +05:30
|
|
|
use crate::pdata::unpack::*;
|
2020-07-28 15:21:48 +05:30
|
|
|
use crate::thin::superblock::*;
|
2020-07-29 15:42:03 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2020-07-30 14:42:51 +05:30
|
|
|
#[allow(dead_code)]
|
2020-07-28 15:21:48 +05:30
|
|
|
struct BlockTime {
|
|
|
|
block: u64,
|
|
|
|
time: u32,
|
|
|
|
}
|
|
|
|
|
2020-08-05 12:31:02 +05:30
|
|
|
impl Unpack for BlockTime {
|
2020-08-03 19:34:59 +05:30
|
|
|
fn disk_size() -> u32 {
|
|
|
|
8
|
|
|
|
}
|
|
|
|
|
2020-07-28 15:21:48 +05:30
|
|
|
fn unpack(i: &[u8]) -> IResult<&[u8], BlockTime> {
|
|
|
|
let (i, n) = le_u64(i)?;
|
|
|
|
let block = n >> 24;
|
|
|
|
let time = n & ((1 << 24) - 1);
|
|
|
|
|
|
|
|
Ok((
|
|
|
|
i,
|
|
|
|
BlockTime {
|
|
|
|
block,
|
|
|
|
time: time as u32,
|
|
|
|
},
|
|
|
|
))
|
2020-06-09 13:45:00 +05:30
|
|
|
}
|
2020-07-28 15:21:48 +05:30
|
|
|
}
|
|
|
|
|
2020-08-08 14:24:16 +05:30
|
|
|
struct BottomLevelVisitor {
|
2020-08-08 17:59:30 +05:30
|
|
|
data_sm: Arc<Mutex<dyn SpaceMap + Send>>,
|
2020-08-08 14:24:16 +05:30
|
|
|
}
|
2020-07-28 15:21:48 +05:30
|
|
|
|
2020-08-03 20:52:08 +05:30
|
|
|
impl NodeVisitor<BlockTime> for BottomLevelVisitor {
|
2020-08-08 14:24:16 +05:30
|
|
|
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<BlockTime>) -> Result<()> {
|
|
|
|
// FIXME: do other checks
|
|
|
|
|
2020-08-08 21:12:32 +05:30
|
|
|
if let Node::Leaf {
|
|
|
|
header: _h,
|
|
|
|
keys: _k,
|
|
|
|
values,
|
|
|
|
} = node
|
|
|
|
{
|
2020-08-10 17:26:41 +05:30
|
|
|
if values.len() == 0 {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut data_sm = self.data_sm.lock().unwrap();
|
2020-08-08 17:59:30 +05:30
|
|
|
|
2020-08-10 17:26:41 +05:30
|
|
|
let mut start = values[0].block;
|
|
|
|
let mut len = 1;
|
|
|
|
|
|
|
|
for n in 1..values.len() {
|
|
|
|
let block = values[n].block;
|
|
|
|
if block == start + len {
|
|
|
|
len += 1;
|
|
|
|
} else {
|
|
|
|
data_sm.inc(start, len)?;
|
|
|
|
start = block;
|
|
|
|
len = 1;
|
|
|
|
}
|
2020-08-08 14:24:16 +05:30
|
|
|
}
|
2020-08-10 17:26:41 +05:30
|
|
|
|
|
|
|
data_sm.inc(start, len)?;
|
2020-08-08 14:24:16 +05:30
|
|
|
}
|
|
|
|
|
2020-08-03 20:52:08 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct DeviceDetail {
|
|
|
|
mapped_blocks: u64,
|
|
|
|
transaction_id: u64,
|
|
|
|
creation_time: u32,
|
|
|
|
snapshotted_time: u32,
|
|
|
|
}
|
|
|
|
|
2020-08-05 12:31:02 +05:30
|
|
|
impl Unpack for DeviceDetail {
|
2020-08-03 20:52:08 +05:30
|
|
|
fn disk_size() -> u32 {
|
|
|
|
24
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unpack(i: &[u8]) -> IResult<&[u8], DeviceDetail> {
|
|
|
|
let (i, mapped_blocks) = le_u64(i)?;
|
|
|
|
let (i, transaction_id) = le_u64(i)?;
|
|
|
|
let (i, creation_time) = le_u32(i)?;
|
|
|
|
let (i, snapshotted_time) = le_u32(i)?;
|
|
|
|
|
|
|
|
Ok((
|
|
|
|
i,
|
|
|
|
DeviceDetail {
|
|
|
|
mapped_blocks,
|
|
|
|
transaction_id,
|
|
|
|
creation_time,
|
|
|
|
snapshotted_time,
|
|
|
|
},
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-29 15:42:03 +05:30
|
|
|
//------------------------------------------
|
|
|
|
|
2020-08-08 21:12:32 +05:30
|
|
|
struct OverflowChecker<'a> {
|
|
|
|
data_sm: &'a dyn SpaceMap,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> OverflowChecker<'a> {
|
|
|
|
fn new(data_sm: &'a dyn SpaceMap) -> OverflowChecker<'a> {
|
|
|
|
OverflowChecker { data_sm }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> NodeVisitor<u32> for OverflowChecker<'a> {
|
|
|
|
fn visit(&mut self, _w: &BTreeWalker, _b: &Block, node: &Node<u32>) -> Result<()> {
|
|
|
|
if let Node::Leaf {
|
|
|
|
header: _h,
|
|
|
|
keys,
|
|
|
|
values,
|
|
|
|
} = node
|
|
|
|
{
|
|
|
|
for n in 0..keys.len() {
|
|
|
|
let k = keys[n];
|
|
|
|
let v = values[n];
|
|
|
|
let expected = self.data_sm.get(k)?;
|
|
|
|
if expected != v {
|
|
|
|
return Err(anyhow!("Bad reference count for data block {}. Expected {}, but space map contains {}.",
|
|
|
|
k, expected, v));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
struct ReportOptions {}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
enum ReportOutcome {
|
|
|
|
Success,
|
|
|
|
NonFatal,
|
|
|
|
Fatal,
|
|
|
|
}
|
|
|
|
|
|
|
|
use ReportOutcome::*;
|
|
|
|
|
|
|
|
impl ReportOutcome {
|
|
|
|
fn combine(lhs: &ReportOutcome, rhs: &ReportOutcome) -> ReportOutcome {
|
|
|
|
match (lhs, rhs) {
|
|
|
|
(Success, rhs) => rhs.clone(),
|
|
|
|
(lhs, Success) => lhs.clone(),
|
|
|
|
(Fatal, _) => Fatal,
|
|
|
|
(_, Fatal) => Fatal,
|
|
|
|
(_, _) => NonFatal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ReportCmd {
|
2020-08-12 14:05:21 +05:30
|
|
|
Log(String),
|
2020-08-11 17:52:14 +05:30
|
|
|
Complete,
|
|
|
|
Title(String),
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
struct Report {
|
|
|
|
opts: ReportOptions,
|
|
|
|
outcome: ReportOutcome,
|
|
|
|
tx: Sender<ReportCmd>,
|
2020-08-11 17:52:14 +05:30
|
|
|
tid: thread::JoinHandle<()>,
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
impl Report {
|
|
|
|
fn new(
|
|
|
|
opts: ReportOptions,
|
|
|
|
sm: Arc<Mutex<dyn SpaceMap + Send + Sync>>,
|
|
|
|
total_allocated: u64,
|
|
|
|
) -> Result<Report> {
|
2020-08-11 17:52:14 +05:30
|
|
|
let (tx, rx) = channel();
|
2020-08-12 14:55:06 +05:30
|
|
|
let tid = thread::spawn(move || report_thread(sm, total_allocated, rx));
|
|
|
|
Ok(Report {
|
|
|
|
opts,
|
|
|
|
outcome: ReportOutcome::Success,
|
|
|
|
tx,
|
|
|
|
tid,
|
|
|
|
})
|
2020-08-11 17:52:14 +05:30
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
fn info<I: Into<String>>(&mut self, txt: I) -> Result<()> {
|
|
|
|
self.tx.send(ReportCmd::Log(txt.into()))?;
|
2020-08-12 14:05:21 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
fn add_outcome(&mut self, rhs: ReportOutcome) {
|
|
|
|
self.outcome = ReportOutcome::combine(&self.outcome, &rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn non_fatal<I: Into<String>>(&mut self, txt: I) -> Result<()> {
|
|
|
|
self.add_outcome(NonFatal);
|
|
|
|
self.tx.send(ReportCmd::Log(txt.into()))?;
|
2020-08-11 17:52:14 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
fn fatal<I: Into<String>>(&mut self, txt: I) -> Result<()> {
|
|
|
|
self.add_outcome(Fatal);
|
|
|
|
self.tx.send(ReportCmd::Log(txt.into()))?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn complete(self) -> Result<()> {
|
|
|
|
self.tx.send(ReportCmd::Complete)?;
|
2020-08-11 17:52:14 +05:30
|
|
|
self.tid.join();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_title(&mut self, txt: &str) -> Result<()> {
|
2020-08-12 14:55:06 +05:30
|
|
|
self.tx.send(ReportCmd::Title(txt.to_string()))?;
|
2020-08-11 17:52:14 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
fn report_thread(
|
2020-08-11 17:52:14 +05:30
|
|
|
sm: Arc<Mutex<dyn SpaceMap + Send + Sync>>,
|
|
|
|
total_allocated: u64,
|
2020-08-12 14:55:06 +05:30
|
|
|
rx: Receiver<ReportCmd>,
|
2020-08-11 17:52:14 +05:30
|
|
|
) {
|
|
|
|
let interval = time::Duration::from_millis(250);
|
|
|
|
let bar = ProgressBar::new(total_allocated);
|
|
|
|
loop {
|
2020-08-12 14:05:21 +05:30
|
|
|
loop {
|
|
|
|
match rx.try_recv() {
|
2020-08-12 14:55:06 +05:30
|
|
|
Ok(ReportCmd::Log(txt)) => {
|
2020-08-12 14:05:21 +05:30
|
|
|
bar.println(txt);
|
|
|
|
}
|
2020-08-12 14:55:06 +05:30
|
|
|
Ok(ReportCmd::Complete) => {
|
2020-08-12 14:05:21 +05:30
|
|
|
bar.finish();
|
|
|
|
return;
|
|
|
|
}
|
2020-08-12 14:55:06 +05:30
|
|
|
Ok(ReportCmd::Title(txt)) => {
|
2020-08-12 14:05:21 +05:30
|
|
|
let mut fmt = "Checking thin metadata [{bar:40}] Remaining {eta}, ".to_string();
|
|
|
|
fmt.push_str(&txt);
|
|
|
|
bar.set_style(
|
|
|
|
ProgressStyle::default_bar()
|
|
|
|
.template(&fmt)
|
|
|
|
.progress_chars("=> "),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Err(TryRecvError::Disconnected) => {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Err(TryRecvError::Empty) => {
|
|
|
|
break;
|
|
|
|
}
|
2020-08-11 17:52:14 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let sm = sm.lock().unwrap();
|
|
|
|
let nr_allocated = sm.get_nr_allocated().unwrap();
|
|
|
|
drop(sm);
|
|
|
|
|
|
|
|
bar.set_position(nr_allocated);
|
|
|
|
bar.tick();
|
|
|
|
|
|
|
|
thread::sleep(interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2020-08-12 12:32:29 +05:30
|
|
|
fn check_space_map(
|
2020-08-12 14:05:21 +05:30
|
|
|
kind: &str,
|
2020-08-12 12:32:29 +05:30
|
|
|
engine: Arc<dyn IoEngine + Send + Sync>,
|
2020-08-12 14:55:06 +05:30
|
|
|
bar: &mut Report,
|
2020-08-12 12:32:29 +05:30
|
|
|
entries: Vec<IndexEntry>,
|
2020-08-12 14:05:21 +05:30
|
|
|
metadata_sm: Option<Arc<Mutex<dyn SpaceMap + Send + Sync>>>,
|
2020-08-12 12:32:29 +05:30
|
|
|
sm: Arc<Mutex<dyn SpaceMap + Send + Sync>>,
|
|
|
|
root: SMRoot,
|
|
|
|
) -> Result<()> {
|
|
|
|
let sm = sm.lock().unwrap();
|
|
|
|
|
|
|
|
// overflow btree
|
|
|
|
{
|
|
|
|
let mut v = OverflowChecker::new(&*sm);
|
2020-08-12 14:05:21 +05:30
|
|
|
let mut w;
|
|
|
|
if metadata_sm.is_none() {
|
|
|
|
w = BTreeWalker::new(engine.clone(), false);
|
|
|
|
} else {
|
|
|
|
w = BTreeWalker::new_with_sm(engine.clone(), metadata_sm.unwrap().clone(), false)?;
|
|
|
|
}
|
2020-08-12 12:32:29 +05:30
|
|
|
w.walk(&mut v, root.ref_count_root)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut blocks = Vec::new();
|
|
|
|
for i in &entries {
|
|
|
|
blocks.push(Block::new(i.blocknr));
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: we should do this in batches
|
|
|
|
engine.read_many(&mut blocks)?;
|
|
|
|
|
|
|
|
let mut leaks = 0;
|
|
|
|
let mut fail = false;
|
|
|
|
let mut blocknr = 0;
|
|
|
|
for n in 0..entries.len() {
|
|
|
|
let b = &blocks[n];
|
|
|
|
if checksum::metadata_block_type(&b.get_data()) != checksum::BT::BITMAP {
|
|
|
|
return Err(anyhow!(
|
|
|
|
"Index entry points to block ({}) that isn't a bitmap",
|
|
|
|
b.loc
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
let bitmap = unpack::<Bitmap>(b.get_data())?;
|
|
|
|
for e in bitmap.entries {
|
|
|
|
if blocknr >= root.nr_blocks {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
match e {
|
|
|
|
BitmapEntry::Small(actual) => {
|
|
|
|
let expected = sm.get(blocknr)?;
|
|
|
|
if actual == 1 && expected == 0 {
|
|
|
|
leaks += 1;
|
|
|
|
} else if actual != expected as u8 {
|
2020-08-12 14:55:06 +05:30
|
|
|
bar.fatal(format!("Bad reference count for {} block {}. Expected {}, but space map contains {}.",
|
2020-08-12 14:05:21 +05:30
|
|
|
kind, blocknr, expected, actual))?;
|
2020-08-12 12:32:29 +05:30
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BitmapEntry::Overflow => {
|
|
|
|
let expected = sm.get(blocknr)?;
|
|
|
|
if expected < 3 {
|
2020-08-12 14:55:06 +05:30
|
|
|
bar.fatal(format!("Bad reference count for {} block {}. Expected {}, but space map says it's >= 3.",
|
2020-08-12 14:05:21 +05:30
|
|
|
kind, blocknr, expected))?;
|
2020-08-12 12:32:29 +05:30
|
|
|
fail = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
blocknr += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if leaks > 0 {
|
2020-08-12 14:55:06 +05:30
|
|
|
bar.non_fatal(format!(
|
2020-08-12 14:05:21 +05:30
|
|
|
"{} {} blocks have leaked. Use --auto-repair to fix.",
|
|
|
|
leaks, kind
|
|
|
|
))?;
|
2020-08-12 12:32:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if fail {
|
|
|
|
return Err(anyhow!("Inconsistent data space map"));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2020-08-12 14:05:21 +05:30
|
|
|
fn inc_entries(sm: &Arc<Mutex<dyn SpaceMap + Sync + Send>>, entries: &[IndexEntry]) -> Result<()> {
|
|
|
|
let mut sm = sm.lock().unwrap();
|
|
|
|
for ie in entries {
|
|
|
|
sm.inc(ie.blocknr, 1)?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2020-08-08 21:12:32 +05:30
|
|
|
const MAX_CONCURRENT_IO: u32 = 1024;
|
|
|
|
|
2020-08-10 15:54:50 +05:30
|
|
|
pub struct ThinCheckOptions<'a> {
|
|
|
|
pub dev: &'a Path,
|
|
|
|
pub async_io: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn check(opts: &ThinCheckOptions) -> Result<()> {
|
|
|
|
let engine: Arc<dyn IoEngine + Send + Sync>;
|
|
|
|
|
|
|
|
let nr_threads;
|
|
|
|
if opts.async_io {
|
|
|
|
nr_threads = std::cmp::min(4, num_cpus::get());
|
|
|
|
engine = Arc::new(AsyncIoEngine::new(opts.dev, MAX_CONCURRENT_IO)?);
|
|
|
|
} else {
|
|
|
|
nr_threads = num_cpus::get() * 2;
|
|
|
|
engine = Arc::new(SyncIoEngine::new(opts.dev, nr_threads)?);
|
|
|
|
}
|
2020-06-09 13:45:00 +05:30
|
|
|
|
2020-08-10 17:26:41 +05:30
|
|
|
// superblock
|
2020-08-03 20:52:08 +05:30
|
|
|
let sb = read_superblock(engine.as_ref(), SUPERBLOCK_LOCATION)?;
|
2020-08-04 16:41:36 +05:30
|
|
|
|
2020-08-11 17:52:14 +05:30
|
|
|
let nr_allocated_metadata;
|
|
|
|
{
|
|
|
|
let root = unpack::<SMRoot>(&sb.metadata_sm_root[0..])?;
|
|
|
|
nr_allocated_metadata = root.nr_allocated;
|
|
|
|
}
|
|
|
|
|
2020-08-11 15:20:43 +05:30
|
|
|
// Device details. We read this once to get the number of thin devices, and hence the
|
|
|
|
// maximum metadata ref count. Then create metadata space map, and reread to increment
|
|
|
|
// the ref counts for that metadata.
|
2020-08-10 19:15:35 +05:30
|
|
|
let devs = btree_to_map::<DeviceDetail>(engine.clone(), false, sb.details_root)?;
|
|
|
|
let nr_devs = devs.len();
|
2020-08-11 15:20:43 +05:30
|
|
|
let metadata_sm = core_sm(engine.get_nr_blocks(), nr_devs as u32);
|
2020-08-12 14:55:06 +05:30
|
|
|
let opts = ReportOptions {};
|
|
|
|
let mut report = Report::new(opts, metadata_sm.clone(), nr_allocated_metadata)?;
|
2020-08-11 17:52:14 +05:30
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
report.set_title("device details tree")?;
|
2020-08-11 15:20:43 +05:30
|
|
|
let _devs = btree_to_map_with_sm::<DeviceDetail>(
|
|
|
|
engine.clone(),
|
|
|
|
metadata_sm.clone(),
|
|
|
|
false,
|
|
|
|
sb.details_root,
|
|
|
|
)?;
|
2020-08-04 16:41:36 +05:30
|
|
|
|
2020-08-11 15:20:43 +05:30
|
|
|
// increment superblock
|
|
|
|
{
|
|
|
|
let mut sm = metadata_sm.lock().unwrap();
|
|
|
|
sm.inc(SUPERBLOCK_LOCATION, 1)?;
|
|
|
|
}
|
2020-08-11 17:52:14 +05:30
|
|
|
|
2020-08-06 12:21:48 +05:30
|
|
|
// mapping top level
|
2020-08-10 19:15:35 +05:30
|
|
|
let roots = btree_to_map::<u64>(engine.clone(), false, sb.mapping_root)?;
|
2020-07-27 20:23:42 +05:30
|
|
|
|
2020-08-10 20:12:10 +05:30
|
|
|
// Check the mappings filling in the data_sm as we go.
|
2020-08-12 14:55:06 +05:30
|
|
|
report.set_title("mapping tree")?;
|
2020-08-08 21:12:32 +05:30
|
|
|
let data_sm;
|
2020-08-04 16:41:36 +05:30
|
|
|
{
|
2020-08-06 12:21:48 +05:30
|
|
|
// FIXME: with a thread pool we need to return errors another way.
|
2020-08-10 15:14:47 +05:30
|
|
|
let nr_workers = nr_threads;
|
2020-08-04 16:41:36 +05:30
|
|
|
let pool = ThreadPool::new(nr_workers);
|
|
|
|
|
2020-08-08 14:24:16 +05:30
|
|
|
let root = unpack::<SMRoot>(&sb.data_sm_root[0..])?;
|
2020-08-08 21:12:32 +05:30
|
|
|
data_sm = core_sm(root.nr_blocks, nr_devs as u32);
|
2020-08-08 14:24:16 +05:30
|
|
|
|
2020-08-11 17:52:14 +05:30
|
|
|
for (_thin_id, root) in roots {
|
2020-08-11 15:20:43 +05:30
|
|
|
let mut w = BTreeWalker::new_with_sm(engine.clone(), metadata_sm.clone(), false)?;
|
2020-08-08 14:24:16 +05:30
|
|
|
let data_sm = data_sm.clone();
|
2020-08-04 16:41:36 +05:30
|
|
|
pool.execute(move || {
|
2020-08-08 21:12:32 +05:30
|
|
|
let mut v = BottomLevelVisitor { data_sm };
|
2020-08-10 17:26:41 +05:30
|
|
|
|
|
|
|
// FIXME: return error
|
|
|
|
match w.walk(&mut v, root) {
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("walk failed {:?}", e);
|
|
|
|
std::process::abort();
|
|
|
|
}
|
2020-08-11 17:52:14 +05:30
|
|
|
Ok(_result) => {
|
|
|
|
//eprintln!("checked thin_dev {} -> {:?}", thin_id, result);
|
2020-08-10 17:26:41 +05:30
|
|
|
}
|
|
|
|
}
|
2020-08-04 16:41:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
pool.join();
|
|
|
|
}
|
2020-08-06 12:21:48 +05:30
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
report.set_title("data space map")?;
|
2020-08-12 12:32:29 +05:30
|
|
|
let root = unpack::<SMRoot>(&sb.data_sm_root[0..])?;
|
2020-08-12 14:05:21 +05:30
|
|
|
|
|
|
|
let entries = btree_to_map_with_sm::<IndexEntry>(
|
|
|
|
engine.clone(),
|
|
|
|
metadata_sm.clone(),
|
|
|
|
false,
|
|
|
|
root.bitmap_root,
|
|
|
|
)?;
|
2020-08-12 12:32:29 +05:30
|
|
|
let entries: Vec<IndexEntry> = entries.values().cloned().collect();
|
2020-08-12 14:05:21 +05:30
|
|
|
inc_entries(&metadata_sm, &entries[0..])?;
|
|
|
|
|
|
|
|
check_space_map(
|
|
|
|
"data",
|
|
|
|
engine.clone(),
|
2020-08-12 14:55:06 +05:30
|
|
|
&mut report,
|
2020-08-12 14:05:21 +05:30
|
|
|
entries,
|
|
|
|
Some(metadata_sm.clone()),
|
|
|
|
data_sm.clone(),
|
|
|
|
root,
|
|
|
|
)?;
|
2020-08-10 19:15:35 +05:30
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
report.set_title("metadata space map")?;
|
2020-08-12 12:32:29 +05:30
|
|
|
let root = unpack::<SMRoot>(&sb.metadata_sm_root[0..])?;
|
|
|
|
let mut b = Block::new(root.bitmap_root);
|
|
|
|
engine.read(&mut b)?;
|
|
|
|
let entries = unpack::<MetadataIndex>(b.get_data())?.indexes;
|
|
|
|
|
|
|
|
// Unused entries will point to block 0
|
|
|
|
let entries: Vec<IndexEntry> = entries
|
|
|
|
.iter()
|
|
|
|
.take_while(|e| e.blocknr != 0)
|
|
|
|
.cloned()
|
|
|
|
.collect();
|
2020-08-12 14:05:21 +05:30
|
|
|
inc_entries(&metadata_sm, &entries[0..])?;
|
2020-08-12 12:32:29 +05:30
|
|
|
|
|
|
|
let _counts = btree_to_map_with_sm::<u32>(
|
|
|
|
engine.clone(),
|
|
|
|
metadata_sm.clone(),
|
|
|
|
false,
|
|
|
|
root.ref_count_root,
|
|
|
|
)?;
|
2020-08-12 14:05:21 +05:30
|
|
|
|
|
|
|
// Now the counts should be correct and we can check it.
|
|
|
|
check_space_map(
|
|
|
|
"metadata",
|
|
|
|
engine.clone(),
|
2020-08-12 14:55:06 +05:30
|
|
|
&mut report,
|
2020-08-12 14:05:21 +05:30
|
|
|
entries,
|
|
|
|
None,
|
|
|
|
metadata_sm.clone(),
|
|
|
|
root,
|
|
|
|
)?;
|
2020-08-10 20:12:10 +05:30
|
|
|
|
2020-08-12 14:55:06 +05:30
|
|
|
report.complete()?;
|
2020-06-09 13:45:00 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
2020-07-29 21:08:52 +05:30
|
|
|
|
|
|
|
//------------------------------------------
|