2013-05-20 22:07:46 +05:30
|
|
|
#ifndef MAPPING_TREE_H
|
|
|
|
#define MAPPING_TREE_H
|
|
|
|
|
2020-07-27 08:18:54 +05:30
|
|
|
#include "base/run.h"
|
2013-05-20 22:07:46 +05:30
|
|
|
#include "persistent-data/data-structures/btree.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace thin_provisioning {
|
|
|
|
namespace mapping_tree_detail {
|
|
|
|
class space_map_ref_counter {
|
|
|
|
public:
|
2013-05-21 16:16:37 +05:30
|
|
|
space_map_ref_counter(space_map::ptr sm);
|
2013-05-20 22:07:46 +05:30
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
void inc(block_address b);
|
|
|
|
void dec(block_address b);
|
2013-05-20 22:07:46 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
space_map::ptr sm_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct block_time {
|
|
|
|
uint64_t block_;
|
|
|
|
uint32_t time_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class block_time_ref_counter {
|
|
|
|
public:
|
2013-05-21 16:16:37 +05:30
|
|
|
block_time_ref_counter(space_map::ptr sm);
|
|
|
|
void inc(block_time bt);
|
|
|
|
void dec(block_time bt);
|
2013-05-20 22:07:46 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
space_map::ptr sm_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct block_traits {
|
|
|
|
typedef base::le64 disk_type;
|
|
|
|
typedef block_time value_type;
|
|
|
|
typedef block_time_ref_counter ref_counter;
|
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
static void unpack(disk_type const &disk, value_type &value);
|
|
|
|
static void pack(value_type const &value, disk_type &disk);
|
2013-05-20 22:07:46 +05:30
|
|
|
};
|
|
|
|
|
2020-04-08 16:54:37 +05:30
|
|
|
class mtree_ref_counter final : public ref_counter<block_address> {
|
2013-05-20 22:07:46 +05:30
|
|
|
public:
|
2019-04-04 19:08:46 +05:30
|
|
|
mtree_ref_counter(transaction_manager &tm);
|
2013-05-20 22:07:46 +05:30
|
|
|
|
2020-04-08 16:54:37 +05:30
|
|
|
void set(block_address const &b, uint32_t rc);
|
|
|
|
void inc(block_address const &b);
|
|
|
|
void dec(block_address const &b);
|
2013-05-20 22:07:46 +05:30
|
|
|
|
|
|
|
private:
|
2019-04-04 19:08:46 +05:30
|
|
|
transaction_manager &tm_;
|
2013-05-20 22:07:46 +05:30
|
|
|
};
|
|
|
|
|
2015-04-07 16:40:38 +05:30
|
|
|
// This value type is itself a tree containing mappings.
|
|
|
|
// Used when manipulating the top level of the mapping
|
|
|
|
// tree.
|
2013-05-20 22:07:46 +05:30
|
|
|
struct mtree_traits {
|
|
|
|
typedef base::le64 disk_type;
|
|
|
|
typedef uint64_t value_type;
|
|
|
|
typedef mtree_ref_counter ref_counter;
|
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
static void unpack(disk_type const &disk, value_type &value);
|
|
|
|
static void pack(value_type const &value, disk_type &disk);
|
|
|
|
};
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
class damage_visitor;
|
|
|
|
|
|
|
|
struct damage {
|
|
|
|
virtual ~damage() {}
|
|
|
|
virtual void visit(damage_visitor &v) const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct missing_devices : public damage {
|
2013-05-28 16:50:05 +05:30
|
|
|
missing_devices(std::string const &desc, run<uint64_t> const &keys);
|
2013-05-21 16:16:37 +05:30
|
|
|
virtual void visit(damage_visitor &v) const;
|
|
|
|
|
|
|
|
std::string desc_;
|
2013-05-28 16:50:05 +05:30
|
|
|
run<uint64_t> keys_;
|
2013-05-21 16:16:37 +05:30
|
|
|
};
|
2013-05-20 22:07:46 +05:30
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
struct missing_mappings : public damage {
|
|
|
|
missing_mappings(std::string const &desc, uint64_t thin_dev,
|
2013-05-28 16:50:05 +05:30
|
|
|
run<uint64_t> const &keys);
|
2013-05-21 16:16:37 +05:30
|
|
|
virtual void visit(damage_visitor &v) const;
|
|
|
|
|
|
|
|
std::string desc_;
|
|
|
|
uint64_t thin_dev_;
|
2013-05-28 16:50:05 +05:30
|
|
|
run<uint64_t> keys_;
|
2013-05-21 16:16:37 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
class damage_visitor {
|
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<damage_visitor> ptr;
|
2013-10-16 14:50:15 +05:30
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
virtual ~damage_visitor() {}
|
|
|
|
|
|
|
|
void visit(damage const &d) {
|
|
|
|
d.visit(*this);
|
2013-05-20 22:07:46 +05:30
|
|
|
}
|
2013-05-21 16:16:37 +05:30
|
|
|
|
|
|
|
virtual void visit(missing_devices const &d) = 0;
|
|
|
|
virtual void visit(missing_mappings const &d) = 0;
|
2013-05-20 22:07:46 +05:30
|
|
|
};
|
2013-05-21 16:16:37 +05:30
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
class mapping_visitor {
|
|
|
|
public:
|
|
|
|
virtual ~mapping_visitor() {}
|
|
|
|
|
|
|
|
// path contains 2 elements, the dev key, then the oblock
|
|
|
|
virtual void visit(btree_path const &path, block_time const &m) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class device_visitor {
|
|
|
|
public:
|
|
|
|
virtual ~device_visitor() {}
|
|
|
|
virtual void visit(btree_path const &path, block_address dtree_root) = 0;
|
|
|
|
};
|
2013-05-20 22:07:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
typedef persistent_data::btree<2, mapping_tree_detail::block_traits> mapping_tree;
|
|
|
|
typedef persistent_data::btree<1, mapping_tree_detail::mtree_traits> dev_tree;
|
|
|
|
typedef persistent_data::btree<1, mapping_tree_detail::block_traits> single_mapping_tree;
|
2013-05-21 16:16:37 +05:30
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
void walk_mapping_tree(dev_tree const &tree,
|
|
|
|
mapping_tree_detail::device_visitor &dev_v,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &dv,
|
|
|
|
bool ignore_non_fatal = false);
|
2013-10-16 14:50:15 +05:30
|
|
|
|
|
|
|
void walk_mapping_tree(mapping_tree const &tree,
|
|
|
|
mapping_tree_detail::mapping_visitor &mv,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &dv,
|
|
|
|
bool ignore_non_fatal = false);
|
2013-10-16 14:50:15 +05:30
|
|
|
|
|
|
|
void walk_mapping_tree(single_mapping_tree const &tree,
|
2016-06-19 19:05:11 +05:30
|
|
|
uint64_t dev_id,
|
2013-10-16 14:50:15 +05:30
|
|
|
mapping_tree_detail::mapping_visitor &mv,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &dv,
|
|
|
|
bool ignore_non_fatal = false);
|
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
void check_mapping_tree(single_mapping_tree const &tree,
|
2016-06-19 19:05:11 +05:30
|
|
|
uint64_t dev_id,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &visitor,
|
|
|
|
bool ignore_non_fatal = false);
|
|
|
|
|
|
|
|
void check_mapping_tree(dev_tree const &tree,
|
|
|
|
mapping_tree_detail::damage_visitor &visitor,
|
|
|
|
bool ignore_non_fatal = false);
|
|
|
|
|
|
|
|
void check_mapping_tree(mapping_tree const &tree,
|
|
|
|
mapping_tree_detail::damage_visitor &visitor,
|
|
|
|
bool ignore_non_fatal = false);
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
2013-05-20 22:07:46 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|