2013-05-21 16:16:37 +05:30
|
|
|
#include "thin-provisioning/mapping_tree.h"
|
|
|
|
|
|
|
|
#include "persistent-data/data-structures/btree_damage_visitor.h"
|
|
|
|
#include "persistent-data/space_map.h"
|
|
|
|
|
|
|
|
using namespace persistent_data;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace thin_provisioning {
|
|
|
|
namespace mapping_tree_detail {
|
|
|
|
space_map_ref_counter::space_map_ref_counter(space_map::ptr sm)
|
|
|
|
: sm_(sm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
space_map_ref_counter::inc(block_address b)
|
|
|
|
{
|
|
|
|
sm_->inc(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
space_map_ref_counter::dec(block_address b)
|
|
|
|
{
|
|
|
|
sm_->dec(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
block_time_ref_counter::block_time_ref_counter(space_map::ptr sm)
|
|
|
|
: sm_(sm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
block_time_ref_counter::inc(block_time bt)
|
|
|
|
{
|
|
|
|
sm_->inc(bt.block_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
block_time_ref_counter::dec(block_time bt)
|
|
|
|
{
|
|
|
|
sm_->dec(bt.block_);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
block_traits::unpack(disk_type const &disk, value_type &value)
|
|
|
|
{
|
|
|
|
uint64_t v = to_cpu<uint64_t>(disk);
|
|
|
|
value.block_ = v >> 24;
|
|
|
|
value.time_ = v & ((1 << 24) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
block_traits::pack(value_type const &value, disk_type &disk)
|
|
|
|
{
|
|
|
|
uint64_t v = (value.block_ << 24) | value.time_;
|
|
|
|
disk = base::to_disk<base::le64>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
2019-04-04 19:08:46 +05:30
|
|
|
mtree_ref_counter::mtree_ref_counter(transaction_manager &tm)
|
2013-05-21 16:16:37 +05:30
|
|
|
: tm_(tm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-08 16:54:37 +05:30
|
|
|
mtree_ref_counter::set(block_address const &b, uint32_t rc)
|
2013-05-21 16:16:37 +05:30
|
|
|
{
|
2020-04-08 16:54:37 +05:30
|
|
|
tm_.get_sm()->set_count(b, rc);
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-04-08 16:54:37 +05:30
|
|
|
mtree_ref_counter::inc(block_address const &b)
|
2013-05-21 16:16:37 +05:30
|
|
|
{
|
2020-04-08 16:54:37 +05:30
|
|
|
tm_.get_sm()->inc(b);
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
|
|
|
|
2020-04-08 16:54:37 +05:30
|
|
|
void
|
|
|
|
mtree_ref_counter::dec(block_address const &b)
|
|
|
|
{
|
|
|
|
tm_.get_sm()->dec(b);
|
|
|
|
}
|
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
mtree_traits::unpack(disk_type const &disk, value_type &value)
|
|
|
|
{
|
|
|
|
value = base::to_cpu<uint64_t>(disk);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mtree_traits::pack(value_type const &value, disk_type &disk)
|
|
|
|
{
|
|
|
|
disk = base::to_disk<base::le64>(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
2013-05-28 16:50:05 +05:30
|
|
|
missing_devices::missing_devices(std::string const &desc, run<uint64_t> const &keys)
|
2013-05-21 16:16:37 +05:30
|
|
|
: desc_(desc),
|
|
|
|
keys_(keys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
missing_devices::visit(damage_visitor &v) const
|
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------
|
|
|
|
|
|
|
|
missing_mappings::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
|
|
|
: desc_(desc),
|
|
|
|
thin_dev_(thin_dev),
|
|
|
|
keys_(keys)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
missing_mappings::visit(damage_visitor &v) const
|
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
using namespace thin_provisioning;
|
|
|
|
using namespace mapping_tree_detail;
|
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
struct noop_block_time_visitor : public mapping_tree_detail::mapping_visitor {
|
2013-05-21 16:16:37 +05:30
|
|
|
virtual void visit(btree_path const &, block_time const &) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
struct noop_block_visitor : public mapping_tree_detail::device_visitor {
|
2013-05-23 15:55:54 +05:30
|
|
|
virtual void visit(btree_path const &, uint64_t) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-07 16:46:46 +05:30
|
|
|
class dev_tree_damage_visitor {
|
2013-05-21 16:16:37 +05:30
|
|
|
public:
|
2015-04-07 16:46:46 +05:30
|
|
|
dev_tree_damage_visitor(damage_visitor &v)
|
2013-05-21 16:16:37 +05:30
|
|
|
: v_(v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(btree_path const &path, btree_detail::damage const &d) {
|
|
|
|
switch (path.size()) {
|
|
|
|
case 0:
|
|
|
|
v_.visit(missing_devices(d.desc_, d.lost_keys_));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
v_.visit(missing_mappings(d.desc_, path[0], d.lost_keys_));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-04-07 16:46:46 +05:30
|
|
|
throw std::runtime_error("dev_tree_damage_visitor: path too long");
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
damage_visitor &v_;
|
|
|
|
};
|
2015-04-07 16:46:46 +05:30
|
|
|
|
|
|
|
class mapping_tree_damage_visitor {
|
|
|
|
public:
|
|
|
|
mapping_tree_damage_visitor(damage_visitor &v)
|
|
|
|
: v_(v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(btree_path const &path, btree_detail::damage const &d) {
|
|
|
|
switch (path.size()) {
|
|
|
|
case 0:
|
|
|
|
v_.visit(missing_devices(d.desc_, d.lost_keys_));
|
|
|
|
break;
|
|
|
|
|
2015-07-03 17:30:13 +05:30
|
|
|
case 1:
|
|
|
|
v_.visit(missing_mappings(d.desc_, path[0], d.lost_keys_));
|
|
|
|
break;
|
|
|
|
|
2015-04-07 16:46:46 +05:30
|
|
|
default:
|
|
|
|
throw std::runtime_error("mapping_tree_damage_visitor: path too long");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
damage_visitor &v_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class single_mapping_tree_damage_visitor {
|
|
|
|
public:
|
2016-06-19 19:05:11 +05:30
|
|
|
single_mapping_tree_damage_visitor(damage_visitor &v,
|
|
|
|
uint64_t dev_id)
|
|
|
|
: v_(v),
|
|
|
|
dev_id_(dev_id) {
|
2015-04-07 16:46:46 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(btree_path const &path, btree_detail::damage const &d) {
|
|
|
|
switch (path.size()) {
|
|
|
|
case 0:
|
2016-06-19 19:05:11 +05:30
|
|
|
v_.visit(missing_mappings(d.desc_, dev_id_, d.lost_keys_));
|
2015-04-07 16:46:46 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw std::runtime_error("single_mapping_tree_damage_visitor: path too long");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
damage_visitor &v_;
|
2016-06-19 19:05:11 +05:30
|
|
|
uint64_t dev_id_;
|
2015-04-07 16:46:46 +05:30
|
|
|
};
|
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
void
|
|
|
|
thin_provisioning::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,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:50:15 +05:30
|
|
|
{
|
2015-04-07 16:46:46 +05:30
|
|
|
dev_tree_damage_visitor ll_dv(dv);
|
2020-07-02 20:33:23 +05:30
|
|
|
btree_visit_values(tree, dev_v, ll_dv, ignore_non_fatal);
|
2013-10-16 14:50:15 +05:30
|
|
|
}
|
2013-05-23 15:55:54 +05:30
|
|
|
|
|
|
|
void
|
|
|
|
thin_provisioning::check_mapping_tree(dev_tree const &tree,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &visitor,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-05-23 15:55:54 +05:30
|
|
|
{
|
2013-10-16 14:50:15 +05:30
|
|
|
noop_block_visitor dev_v;
|
2020-07-02 20:33:23 +05:30
|
|
|
walk_mapping_tree(tree, dev_v, visitor, ignore_non_fatal);
|
2013-10-16 14:50:15 +05:30
|
|
|
}
|
2013-05-23 15:55:54 +05:30
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
void
|
|
|
|
thin_provisioning::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,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:50:15 +05:30
|
|
|
{
|
2015-04-07 16:46:46 +05:30
|
|
|
mapping_tree_damage_visitor ll_dv(dv);
|
2020-07-02 20:33:23 +05:30
|
|
|
btree_visit_values(tree, mv, ll_dv, ignore_non_fatal);
|
2013-05-23 15:55:54 +05:30
|
|
|
}
|
|
|
|
|
2013-05-21 16:16:37 +05:30
|
|
|
void
|
|
|
|
thin_provisioning::check_mapping_tree(mapping_tree const &tree,
|
2020-07-02 20:33:23 +05:30
|
|
|
mapping_tree_detail::damage_visitor &visitor,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-05-21 16:16:37 +05:30
|
|
|
{
|
2013-10-16 14:50:15 +05:30
|
|
|
noop_block_time_visitor mv;
|
2020-07-02 20:33:23 +05:30
|
|
|
walk_mapping_tree(tree, mv, visitor, ignore_non_fatal);
|
2013-10-16 14:50:15 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
thin_provisioning::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,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:50:15 +05:30
|
|
|
{
|
2016-06-19 19:05:11 +05:30
|
|
|
single_mapping_tree_damage_visitor ll_dv(dv, dev_id);
|
2020-07-02 20:33:23 +05:30
|
|
|
btree_visit_values(tree, mv, ll_dv, ignore_non_fatal);
|
2013-10-16 14:50:15 +05:30
|
|
|
}
|
2013-05-21 16:16:37 +05:30
|
|
|
|
2013-10-16 14:50:15 +05:30
|
|
|
void
|
|
|
|
thin_provisioning::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,
|
2020-07-14 12:22:02 +05:30
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:50:15 +05:30
|
|
|
{
|
|
|
|
noop_block_time_visitor mv;
|
2020-07-02 20:33:23 +05:30
|
|
|
walk_mapping_tree(tree, dev_id, mv, visitor, ignore_non_fatal);
|
2013-05-21 16:16:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|