thin-provisioning-tools/caching/mapping_array.h

85 lines
1.8 KiB
C
Raw Normal View History

2013-09-12 17:03:32 +05:30
#ifndef CACHE_MAPPING_ARRAY_H
#define CACHE_MAPPING_ARRAY_H
#include "persistent-data/data-structures/array.h"
//----------------------------------------------------------------
namespace caching {
enum mapping_flags {
M_VALID = 1,
M_DIRTY = 2
};
struct mapping {
uint64_t oblock_;
uint32_t flags_;
};
struct mapping_traits {
typedef base::le64 disk_type;
typedef mapping value_type;
typedef no_op_ref_counter<value_type> ref_counter;
static void unpack(disk_type const &disk, value_type &value);
static void pack(value_type const &value, disk_type &disk);
};
namespace mapping_array_damage {
class damage_visitor;
2013-10-08 14:06:20 +05:30
class damage {
public:
damage(std::string const &desc)
: desc_(desc) {
}
virtual ~damage() {}
virtual void visit(damage_visitor &v) const = 0;
2013-10-08 14:06:20 +05:30
std::string get_desc() const {
return desc_;
}
private:
std::string desc_;
};
struct missing_mappings : public damage {
2013-10-08 14:06:20 +05:30
missing_mappings(std::string const &desc, run<uint32_t> const &keys);
virtual void visit(damage_visitor &v) const;
run<uint32_t> keys_;
2013-10-08 14:06:20 +05:30
};
struct invalid_mapping : public damage {
invalid_mapping(std::string const &desc, block_address cblock, mapping const &m);
virtual void visit(damage_visitor &v) const;
block_address cblock_;
mapping m_;
};
class damage_visitor {
public:
virtual ~damage_visitor() {}
virtual void visit(mapping_array_damage::damage const &d) {
d.visit(*this);
}
virtual void visit(missing_mappings const &d) = 0;
2013-10-08 14:06:20 +05:30
virtual void visit(invalid_mapping const &d) = 0;
};
2013-09-12 17:03:32 +05:30
}
typedef persistent_data::array<mapping_traits> mapping_array;
void check_mapping_array(mapping_array const &array,
mapping_array_damage::damage_visitor &visitor);
2013-09-12 17:03:32 +05:30
}
//----------------------------------------------------------------
#endif