[thin-provisioning] walk_device_tree()

This commit is contained in:
Joe Thornber 2013-10-16 10:19:29 +01:00
parent 0fe7dddd8a
commit a06139ef9f
2 changed files with 47 additions and 11 deletions

View File

@ -10,9 +10,22 @@ using namespace thin_provisioning;
namespace { namespace {
using namespace device_tree_detail; using namespace device_tree_detail;
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_;
};
// No op for now, should add sanity checks in here however. // No op for now, should add sanity checks in here however.
struct leaf_visitor { struct noop_visitor : public device_visitor {
virtual void visit(btree_path const &path, device_details const &dd) { virtual void visit(block_address dev_id, device_details const &dd) {
} }
}; };
@ -62,15 +75,26 @@ namespace thin_provisioning {
v.visit(*this); v.visit(*this);
} }
} }
}
void check_device_tree(device_tree const &tree, damage_visitor &visitor)
{ //----------------------------------------------------------------
block_counter counter; // FIXME: get rid of this counter arg
leaf_visitor vv; void
ll_damage_visitor dv(visitor); thin_provisioning::walk_device_tree(device_tree const &tree,
device_tree_detail::device_visitor &vv,
btree_visit_values(tree, counter, vv, dv); device_tree_detail::damage_visitor &dv)
} {
block_counter counter;
visitor_adapter av(vv);
ll_damage_visitor ll_dv(dv);
btree_visit_values(tree, counter, av, ll_dv);
}
void
thin_provisioning::check_device_tree(device_tree const &tree, damage_visitor &visitor)
{
noop_visitor vv;
walk_device_tree(tree, vv, visitor);
} }
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -4,6 +4,8 @@
#include "persistent-data/data-structures/btree.h" #include "persistent-data/data-structures/btree.h"
#include "persistent-data/run.h" #include "persistent-data/run.h"
using namespace boost;
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace thin_provisioning { namespace thin_provisioning {
@ -48,6 +50,8 @@ namespace thin_provisioning {
class damage_visitor { class damage_visitor {
public: public:
typedef shared_ptr<damage_visitor> ptr;
virtual ~damage_visitor() {} virtual ~damage_visitor() {}
void visit(damage const &d) { void visit(damage const &d) {
@ -59,10 +63,18 @@ namespace thin_provisioning {
// FIXME: need to add some more damage types for bad leaf data // FIXME: need to add some more damage types for bad leaf data
class device_visitor {
public:
virtual ~device_visitor() {}
virtual void visit(block_address dev_id, device_details const &v) = 0;
};
}; };
typedef persistent_data::btree<1, device_tree_detail::device_details_traits> device_tree; typedef persistent_data::btree<1, device_tree_detail::device_details_traits> device_tree;
void walk_device_tree(device_tree const &tree,
device_tree_detail::device_visitor &dev_v,
device_tree_detail::damage_visitor &dv);
void check_device_tree(device_tree const &tree, void check_device_tree(device_tree const &tree,
device_tree_detail::damage_visitor &visitor); device_tree_detail::damage_visitor &visitor);
} }