2013-09-12 18:51:25 +05:30
|
|
|
#include "caching/mapping_array.h"
|
|
|
|
#include "persistent-data/endian_utils.h"
|
|
|
|
|
2013-10-08 14:29:16 +05:30
|
|
|
#include <set>
|
|
|
|
|
2013-10-08 13:41:04 +05:30
|
|
|
using namespace caching;
|
|
|
|
using namespace caching::mapping_array_damage;
|
2013-10-08 14:29:16 +05:30
|
|
|
using namespace std;
|
2013-09-12 18:51:25 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const uint64_t FLAGS_MASK = (1 << 16) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mapping_traits::unpack(disk_type const &disk, value_type &value)
|
|
|
|
{
|
|
|
|
uint64_t v = base::to_cpu<uint64_t>(disk);
|
|
|
|
value.oblock_ = v >> 16;
|
|
|
|
value.flags_ = v & FLAGS_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mapping_traits::pack(value_type const &value, disk_type &disk)
|
|
|
|
{
|
|
|
|
uint64_t packed = value.oblock_ << 16;
|
2013-09-23 15:45:41 +05:30
|
|
|
packed = packed | (value.flags_ & FLAGS_MASK);
|
2013-09-12 18:51:25 +05:30
|
|
|
disk = base::to_disk<le64>(packed);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
2013-10-02 15:20:13 +05:30
|
|
|
|
2013-10-08 14:06:20 +05:30
|
|
|
missing_mappings::missing_mappings(std::string const &desc, run<uint32_t> const &keys)
|
|
|
|
: damage(desc),
|
|
|
|
keys_(keys)
|
2013-10-02 15:20:13 +05:30
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
missing_mappings::visit(damage_visitor &v) const
|
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
2013-10-08 14:06:20 +05:30
|
|
|
invalid_mapping::invalid_mapping(std::string const &desc,
|
|
|
|
block_address cblock, mapping const &m)
|
|
|
|
: damage(desc),
|
|
|
|
cblock_(cblock),
|
|
|
|
m_(m)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
invalid_mapping::visit(damage_visitor &v) const
|
|
|
|
{
|
|
|
|
v.visit(*this);
|
|
|
|
}
|
|
|
|
|
2013-10-02 15:20:13 +05:30
|
|
|
namespace {
|
2013-10-08 16:42:01 +05:30
|
|
|
class check_mapping_visitor : public mapping_visitor {
|
2013-10-08 14:29:16 +05:30
|
|
|
public:
|
2013-10-08 16:42:01 +05:30
|
|
|
check_mapping_visitor(damage_visitor &visitor)
|
2013-10-08 14:29:16 +05:30
|
|
|
: visitor_(visitor) {
|
2013-10-02 15:20:13 +05:30
|
|
|
}
|
2013-10-08 14:29:16 +05:30
|
|
|
|
2013-10-08 16:42:01 +05:30
|
|
|
virtual void visit(block_address cblock, mapping const &m) {
|
2013-10-08 14:29:16 +05:30
|
|
|
if (!valid_mapping(m))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (seen_oblock(m))
|
|
|
|
visitor_.visit(invalid_mapping("origin block already mapped", cblock, m));
|
|
|
|
else
|
|
|
|
record_oblock(m);
|
|
|
|
|
|
|
|
if (unknown_flags(m))
|
|
|
|
visitor_.visit(invalid_mapping("unknown flags in mapping", cblock, m));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool valid_mapping(mapping const &m) {
|
|
|
|
return !!(m.flags_ & M_VALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool seen_oblock(mapping const &m) const {
|
|
|
|
return seen_oblocks_.find(m.oblock_) != seen_oblocks_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void record_oblock(mapping const &m) {
|
|
|
|
seen_oblocks_.insert(m.oblock_);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool unknown_flags(mapping const &m) {
|
|
|
|
return (m.flags_ & ~(M_VALID | M_DIRTY));
|
|
|
|
}
|
|
|
|
|
|
|
|
damage_visitor &visitor_;
|
|
|
|
set<block_address> seen_oblocks_;
|
2013-10-02 15:20:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
class ll_damage_visitor {
|
|
|
|
public:
|
|
|
|
ll_damage_visitor(damage_visitor &v)
|
|
|
|
: v_(v) {
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void visit(array_detail::damage const &d) {
|
2013-10-08 14:06:20 +05:30
|
|
|
v_.visit(missing_mappings(d.desc_, d.lost_keys_));
|
2013-10-02 15:20:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
damage_visitor &v_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-08 16:42:01 +05:30
|
|
|
caching::walk_mapping_array(mapping_array const &array,
|
|
|
|
mapping_visitor &mv,
|
|
|
|
damage_visitor &dv)
|
2013-10-02 15:20:13 +05:30
|
|
|
{
|
2013-10-08 16:42:01 +05:30
|
|
|
ll_damage_visitor ll(dv);
|
2013-10-08 14:29:16 +05:30
|
|
|
array.visit_values(mv, ll);
|
2013-10-02 15:20:13 +05:30
|
|
|
}
|
|
|
|
|
2013-10-08 16:42:01 +05:30
|
|
|
void
|
|
|
|
caching::check_mapping_array(mapping_array const &array, damage_visitor &visitor)
|
|
|
|
{
|
|
|
|
check_mapping_visitor mv(visitor);
|
|
|
|
walk_mapping_array(array, mv, visitor);
|
|
|
|
}
|
|
|
|
|
2013-10-02 15:20:13 +05:30
|
|
|
//----------------------------------------------------------------
|