2013-05-20 20:39:13 +05:30
|
|
|
#include "thin-provisioning/device_tree.h"
|
|
|
|
|
|
|
|
#include "persistent-data/data-structures/btree_damage_visitor.h"
|
|
|
|
|
|
|
|
using namespace persistent_data;
|
|
|
|
using namespace thin_provisioning;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
using namespace device_tree_detail;
|
|
|
|
|
2013-10-16 14:49:29 +05:30
|
|
|
struct visitor_adapter {
|
|
|
|
visitor_adapter(device_visitor &dv)
|
|
|
|
: dv_(dv) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void visit(btree_path const &path, device_details const &dd) {
|
|
|
|
dv_.visit(path[0], dd);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
device_visitor &dv_;
|
|
|
|
};
|
|
|
|
|
2013-05-20 20:39:13 +05:30
|
|
|
// No op for now, should add sanity checks in here however.
|
2013-10-16 14:49:29 +05:30
|
|
|
struct noop_visitor : public device_visitor {
|
|
|
|
virtual void visit(block_address dev_id, device_details const &dd) {
|
2013-05-20 20:39:13 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ll_damage_visitor {
|
|
|
|
public:
|
2013-05-21 16:16:37 +05:30
|
|
|
// FIXME: is the namespace needed on here?
|
2013-05-20 20:39:13 +05:30
|
|
|
ll_damage_visitor(device_tree_detail::damage_visitor &v)
|
|
|
|
: v_(v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(btree_path const &path, btree_detail::damage const &d) {
|
2013-05-21 16:16:37 +05:30
|
|
|
v_.visit(missing_devices(d.desc_, d.lost_keys_));
|
2013-05-20 20:39:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
device_tree_detail::damage_visitor &v_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace thin_provisioning {
|
|
|
|
namespace device_tree_detail {
|
2016-03-05 11:29:24 +05:30
|
|
|
device_details::device_details()
|
|
|
|
: mapped_blocks_(0),
|
|
|
|
transaction_id_(0),
|
|
|
|
creation_time_(0),
|
|
|
|
snapshotted_time_(0) {
|
|
|
|
}
|
|
|
|
|
2020-05-29 12:18:10 +05:30
|
|
|
device_details::device_details(uint64_t tid, uint32_t time)
|
|
|
|
: mapped_blocks_(0),
|
|
|
|
transaction_id_(tid),
|
|
|
|
creation_time_(time),
|
|
|
|
snapshotted_time_(time) {
|
|
|
|
}
|
|
|
|
|
2013-05-20 21:05:26 +05:30
|
|
|
void
|
|
|
|
device_details_traits::unpack(device_details_disk const &disk, device_details &value)
|
|
|
|
{
|
|
|
|
value.mapped_blocks_ = to_cpu<uint64_t>(disk.mapped_blocks_);
|
|
|
|
value.transaction_id_ = to_cpu<uint64_t>(disk.transaction_id_);
|
|
|
|
value.creation_time_ = to_cpu<uint32_t>(disk.creation_time_);
|
|
|
|
value.snapshotted_time_ = to_cpu<uint32_t>(disk.snapshotted_time_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
device_details_traits::pack(device_details const &value, device_details_disk &disk)
|
|
|
|
{
|
|
|
|
disk.mapped_blocks_ = to_disk<le64>(value.mapped_blocks_);
|
|
|
|
disk.transaction_id_ = to_disk<le64>(value.transaction_id_);
|
|
|
|
disk.creation_time_ = to_disk<le32>(value.creation_time_);
|
|
|
|
disk.snapshotted_time_ = to_disk<le32>(value.snapshotted_time_);
|
|
|
|
}
|
|
|
|
|
2013-05-20 20:39:13 +05:30
|
|
|
missing_devices::missing_devices(std::string const &desc,
|
2013-05-28 16:50:05 +05:30
|
|
|
run<uint64_t> const &keys)
|
2013-05-20 20:39:13 +05:30
|
|
|
: desc_(desc),
|
|
|
|
keys_(keys) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void missing_devices::visit(damage_visitor &v) const {
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
}
|
2013-10-16 14:49:29 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
2013-05-20 20:39:13 +05:30
|
|
|
|
2013-10-16 14:49:29 +05:30
|
|
|
void
|
|
|
|
thin_provisioning::walk_device_tree(device_tree const &tree,
|
|
|
|
device_tree_detail::device_visitor &vv,
|
2020-07-02 20:33:23 +05:30
|
|
|
device_tree_detail::damage_visitor &dv,
|
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:49:29 +05:30
|
|
|
{
|
|
|
|
visitor_adapter av(vv);
|
|
|
|
ll_damage_visitor ll_dv(dv);
|
2020-07-02 20:33:23 +05:30
|
|
|
btree_visit_values(tree, av, ll_dv, ignore_non_fatal);
|
2013-10-16 14:49:29 +05:30
|
|
|
}
|
2013-05-20 20:39:13 +05:30
|
|
|
|
2013-10-16 14:49:29 +05:30
|
|
|
void
|
2020-07-02 20:33:23 +05:30
|
|
|
thin_provisioning::check_device_tree(device_tree const &tree,
|
|
|
|
damage_visitor &visitor,
|
|
|
|
bool ignore_non_fatal)
|
2013-10-16 14:49:29 +05:30
|
|
|
{
|
|
|
|
noop_visitor vv;
|
2020-07-02 20:33:23 +05:30
|
|
|
walk_device_tree(tree, vv, visitor, ignore_non_fatal);
|
2013-05-20 20:39:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|