thin-provisioning-tools/thin-provisioning/device_tree.h

85 lines
2.2 KiB
C
Raw Normal View History

2013-05-20 20:39:13 +05:30
#ifndef THIN_DEVICE_CHECKER_H
#define THIN_DEVICE_CHECKER_H
#include "persistent-data/data-structures/btree.h"
2013-05-28 16:21:44 +05:30
#include "persistent-data/run.h"
2013-05-20 20:39:13 +05:30
//----------------------------------------------------------------
namespace thin_provisioning {
namespace device_tree_detail {
struct device_details_disk {
le64 mapped_blocks_;
le64 transaction_id_; /* when created */
le32 creation_time_;
le32 snapshotted_time_;
} __attribute__ ((packed));
struct device_details {
uint64_t mapped_blocks_;
uint64_t transaction_id_; /* when created */
uint32_t creation_time_;
uint32_t snapshotted_time_;
device_details();
};
struct device_details_traits {
typedef device_details_disk disk_type;
typedef device_details value_type;
typedef persistent_data::no_op_ref_counter<device_details> ref_counter;
static void unpack(device_details_disk const &disk, device_details &value);
static void pack(device_details const &value, device_details_disk &disk);
};
2013-05-20 20:39:13 +05:30
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-20 20:39:13 +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-20 20:39:13 +05:30
};
class damage_visitor {
public:
typedef boost::shared_ptr<damage_visitor> ptr;
2013-10-16 14:49:29 +05:30
2013-05-20 20:39:13 +05:30
virtual ~damage_visitor() {}
void visit(damage const &d) {
d.visit(*this);
}
2013-05-21 16:16:37 +05:30
virtual void visit(missing_devices const &d) = 0;
2013-05-20 20:39:13 +05:30
};
// FIXME: need to add some more damage types for bad leaf data
2013-10-16 14:49:29 +05:30
class device_visitor {
public:
virtual ~device_visitor() {}
virtual void visit(block_address dev_id, device_details const &v) = 0;
};
2013-05-20 20:39:13 +05:30
};
typedef persistent_data::btree<1, device_tree_detail::device_details_traits> device_tree;
2013-10-16 14:49:29 +05:30
void walk_device_tree(device_tree const &tree,
device_tree_detail::device_visitor &dev_v,
device_tree_detail::damage_visitor &dv);
2013-05-20 20:39:13 +05:30
void check_device_tree(device_tree const &tree,
device_tree_detail::damage_visitor &visitor);
}
//----------------------------------------------------------------
#endif