2013-08-16 18:09:12 +05:30
|
|
|
#ifndef CACHE_SUPERBLOCK_H
|
|
|
|
#define CACHE_SUPERBLOCK_H
|
|
|
|
|
2013-11-19 15:53:35 +05:30
|
|
|
#include "base/endian_utils.h"
|
2013-08-16 18:09:12 +05:30
|
|
|
#include "persistent-data/data-structures/btree.h"
|
|
|
|
|
2016-09-30 20:51:20 +05:30
|
|
|
#include <boost/optional.hpp>
|
2013-10-11 18:02:57 +05:30
|
|
|
#include <set>
|
|
|
|
|
2013-08-16 18:09:12 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace caching {
|
2013-10-07 19:51:45 +05:30
|
|
|
typedef unsigned char __u8;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2016-09-30 20:51:20 +05:30
|
|
|
unsigned const MIN_METADATA_VERSION = 1;
|
|
|
|
unsigned const MAX_METADATA_VERSION = 2;
|
2013-10-07 19:51:45 +05:30
|
|
|
unsigned const SPACE_MAP_ROOT_SIZE = 128;
|
|
|
|
unsigned const CACHE_POLICY_NAME_SIZE = 16;
|
|
|
|
unsigned const CACHE_POLICY_VERSION_SIZE = 3;
|
|
|
|
block_address const SUPERBLOCK_LOCATION = 0;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-11 18:02:57 +05:30
|
|
|
class superblock_flags {
|
|
|
|
public:
|
|
|
|
enum flag {
|
2015-06-09 18:31:22 +05:30
|
|
|
CLEAN_SHUTDOWN,
|
|
|
|
NEEDS_CHECK
|
2013-10-11 18:02:57 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
enum flag_bits {
|
2015-06-09 18:31:22 +05:30
|
|
|
CLEAN_SHUTDOWN_BIT = 0,
|
|
|
|
NEEDS_CHECK_BIT = 1,
|
2013-10-11 18:02:57 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
superblock_flags();
|
|
|
|
superblock_flags(uint32_t bits);
|
|
|
|
|
|
|
|
void set_flag(flag f);
|
2013-10-29 17:05:05 +05:30
|
|
|
void clear_flag(flag f);
|
2013-10-11 18:02:57 +05:30
|
|
|
bool get_flag(flag f) const;
|
|
|
|
uint32_t encode() const;
|
|
|
|
uint32_t get_unhandled_flags() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32_t unhandled_flags_;
|
|
|
|
std::set<flag> flags_;
|
|
|
|
};
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
struct superblock {
|
|
|
|
superblock();
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint32_t csum;
|
2013-10-11 18:02:57 +05:30
|
|
|
superblock_flags flags;
|
2013-10-07 19:51:45 +05:30
|
|
|
uint64_t blocknr;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
__u8 uuid[16];
|
|
|
|
uint64_t magic;
|
|
|
|
uint32_t version;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
__u8 policy_name[CACHE_POLICY_NAME_SIZE];
|
|
|
|
uint32_t policy_version[CACHE_POLICY_VERSION_SIZE];
|
|
|
|
uint32_t policy_hint_size;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint64_t mapping_root;
|
|
|
|
uint64_t hint_root;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint64_t discard_root;
|
|
|
|
uint64_t discard_block_size;
|
|
|
|
uint64_t discard_nr_blocks;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint32_t data_block_size; /* in 512-byte sectors */
|
|
|
|
uint32_t metadata_block_size; /* in 512-byte sectors */
|
|
|
|
uint32_t cache_blocks;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint32_t compat_flags;
|
|
|
|
uint32_t compat_ro_flags;
|
|
|
|
uint32_t incompat_flags;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
uint32_t read_hits;
|
|
|
|
uint32_t read_misses;
|
|
|
|
uint32_t write_hits;
|
|
|
|
uint32_t write_misses;
|
2016-09-30 20:51:20 +05:30
|
|
|
|
|
|
|
boost::optional<uint64_t> dirty_root;
|
2013-10-07 19:51:45 +05:30
|
|
|
};
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-17 16:15:20 +05:30
|
|
|
enum incompat_bits {
|
|
|
|
VARIABLE_HINT_SIZE_BIT = 0
|
|
|
|
};
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
//--------------------------------
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
namespace superblock_damage {
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
class damage_visitor;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
class damage {
|
|
|
|
public:
|
|
|
|
damage(std::string const &desc)
|
|
|
|
: desc_(desc) {
|
|
|
|
}
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
virtual ~damage() {}
|
|
|
|
virtual void visit(damage_visitor &v) const = 0;
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
std::string const &get_desc() const {
|
|
|
|
return desc_;
|
|
|
|
}
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
private:
|
|
|
|
std::string desc_;
|
2013-08-16 18:09:12 +05:30
|
|
|
};
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
struct superblock_corrupt : public damage {
|
|
|
|
superblock_corrupt(std::string const &desc);
|
|
|
|
void visit(damage_visitor &v) const;
|
2013-08-16 18:09:12 +05:30
|
|
|
};
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
struct superblock_invalid : public damage {
|
|
|
|
superblock_invalid(std::string const &desc);
|
2013-08-16 18:09:12 +05:30
|
|
|
void visit(damage_visitor &v) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class damage_visitor {
|
|
|
|
public:
|
|
|
|
virtual ~damage_visitor() {}
|
|
|
|
|
|
|
|
void visit(damage const &d);
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
virtual void visit(superblock_corrupt const &d) = 0;
|
|
|
|
virtual void visit(superblock_invalid const &d) = 0;
|
2013-08-16 18:09:12 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-10-07 19:51:45 +05:30
|
|
|
//--------------------------------
|
|
|
|
|
2014-07-25 19:16:51 +05:30
|
|
|
bcache::validator::ptr superblock_validator();
|
2013-08-16 18:09:12 +05:30
|
|
|
|
2020-04-30 19:00:01 +05:30
|
|
|
superblock read_superblock(persistent_data::block_manager::ptr bm,
|
2013-10-07 19:51:45 +05:30
|
|
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
2013-09-19 18:15:56 +05:30
|
|
|
|
2020-04-30 19:00:01 +05:30
|
|
|
void write_superblock(persistent_data::block_manager::ptr bm,
|
2013-10-07 19:51:45 +05:30
|
|
|
superblock const &sb,
|
|
|
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
|
|
|
|
|
|
|
void check_superblock(superblock const &sb,
|
|
|
|
persistent_data::block_address nr_metadata_blocks,
|
|
|
|
superblock_damage::damage_visitor &visitor);
|
2013-09-19 18:15:56 +05:30
|
|
|
|
2020-04-30 19:00:01 +05:30
|
|
|
void check_superblock(persistent_data::block_manager::ptr bm,
|
2013-10-07 19:51:45 +05:30
|
|
|
persistent_data::block_address nr_metadata_blocks,
|
|
|
|
superblock_damage::damage_visitor &visitor);
|
2013-08-16 18:09:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|