2013-09-12 17:03:32 +05:30
|
|
|
#include "caching/restore_emitter.h"
|
|
|
|
#include "caching/superblock.h"
|
2013-09-19 18:15:56 +05:30
|
|
|
#include "caching/mapping_array.h"
|
2013-09-12 17:03:32 +05:30
|
|
|
|
|
|
|
using namespace caching;
|
2013-09-19 18:15:56 +05:30
|
|
|
using namespace std;
|
2013-10-07 19:51:45 +05:30
|
|
|
using namespace superblock_damage;
|
2013-09-12 17:03:32 +05:30
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class restorer : public emitter {
|
|
|
|
public:
|
2016-09-30 20:51:20 +05:30
|
|
|
restorer(metadata::ptr md, bool clean_shutdown, unsigned metadata_version)
|
2020-04-08 16:42:59 +05:30
|
|
|
: md_(md),
|
2016-09-30 20:51:20 +05:30
|
|
|
clean_shutdown_(clean_shutdown),
|
|
|
|
metadata_version_(metadata_version) {
|
2013-09-18 17:30:26 +05:30
|
|
|
}
|
|
|
|
|
2013-09-12 17:03:32 +05:30
|
|
|
virtual void begin_superblock(std::string const &uuid,
|
|
|
|
pd::block_address block_size,
|
|
|
|
pd::block_address nr_cache_blocks,
|
2013-09-26 16:06:01 +05:30
|
|
|
std::string const &policy,
|
|
|
|
size_t hint_width) {
|
2013-09-18 17:30:26 +05:30
|
|
|
|
|
|
|
superblock &sb = md_->sb_;
|
2016-09-30 20:51:20 +05:30
|
|
|
sb.version = metadata_version_;
|
2018-06-13 17:20:48 +05:30
|
|
|
strncpy((char *) sb.policy_name, policy.c_str(), sizeof(sb.policy_name) - 1);
|
2013-10-07 19:51:45 +05:30
|
|
|
memset(sb.policy_version, 0, sizeof(sb.policy_version)); // FIXME: should come from xml
|
2013-09-26 16:06:01 +05:30
|
|
|
sb.policy_hint_size = hint_width;
|
|
|
|
md_->setup_hint_array(hint_width);
|
2013-09-18 17:30:26 +05:30
|
|
|
|
|
|
|
sb.data_block_size = block_size;
|
|
|
|
sb.cache_blocks = nr_cache_blocks;
|
|
|
|
|
2013-09-19 18:15:56 +05:30
|
|
|
struct mapping unmapped_value;
|
|
|
|
unmapped_value.oblock_ = 0;
|
|
|
|
unmapped_value.flags_ = 0;
|
|
|
|
md_->mappings_->grow(nr_cache_blocks, unmapped_value);
|
2013-09-26 16:06:01 +05:30
|
|
|
|
2016-09-30 20:51:20 +05:30
|
|
|
if (metadata_version_ > 1)
|
|
|
|
// make everything dirty by default
|
|
|
|
md_->dirty_bits_->grow(nr_cache_blocks, true);
|
|
|
|
|
2013-09-26 16:06:01 +05:30
|
|
|
vector<unsigned char> hint_value(hint_width, '\0');
|
|
|
|
md_->hints_->grow(nr_cache_blocks, hint_value);
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void end_superblock() {
|
2013-10-29 18:16:23 +05:30
|
|
|
md_->commit(clean_shutdown_);
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void begin_mappings() {
|
2013-09-18 17:30:26 +05:30
|
|
|
// noop
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void end_mappings() {
|
2013-09-18 17:30:26 +05:30
|
|
|
// noop
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void mapping(pd::block_address cblock,
|
|
|
|
pd::block_address oblock,
|
|
|
|
bool dirty) {
|
2013-12-09 18:16:46 +05:30
|
|
|
caching::mapping m;
|
2013-09-18 17:30:26 +05:30
|
|
|
m.oblock_ = oblock;
|
2013-09-23 15:45:41 +05:30
|
|
|
m.flags_ = M_VALID;
|
|
|
|
|
2016-09-30 20:51:20 +05:30
|
|
|
if (metadata_version_ == 1) {
|
|
|
|
if (dirty)
|
|
|
|
m.flags_ = m.flags_ | M_DIRTY;
|
|
|
|
} else
|
|
|
|
md_->dirty_bits_->set(cblock, dirty);
|
2013-09-18 17:30:26 +05:30
|
|
|
|
|
|
|
md_->mappings_->set(cblock, m);
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void begin_hints() {
|
2013-09-24 17:07:27 +05:30
|
|
|
// noop
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void end_hints() {
|
2013-09-24 17:07:27 +05:30
|
|
|
// noop
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hint(pd::block_address cblock,
|
2013-09-24 17:07:27 +05:30
|
|
|
vector<unsigned char> const &data) {
|
2013-10-11 14:33:51 +05:30
|
|
|
md_->hints_->set_hint(cblock, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void begin_discards() {
|
|
|
|
// noop
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void end_discards() {
|
|
|
|
// noop
|
|
|
|
}
|
2013-09-24 17:07:27 +05:30
|
|
|
|
2013-10-11 14:33:51 +05:30
|
|
|
virtual void discard(block_address dblock, block_address dblock_e) {
|
|
|
|
while (dblock != dblock_e) {
|
|
|
|
md_->discard_bits_->set(dblock, true);
|
|
|
|
dblock++;
|
|
|
|
}
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
metadata::ptr md_;
|
2013-10-29 18:16:23 +05:30
|
|
|
bool clean_shutdown_;
|
2016-09-30 20:51:20 +05:30
|
|
|
unsigned metadata_version_;
|
2013-09-12 17:03:32 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
emitter::ptr
|
2016-09-30 20:51:20 +05:30
|
|
|
caching::create_restore_emitter(metadata::ptr md, unsigned metadata_version,
|
2017-08-29 17:03:32 +05:30
|
|
|
shutdown_type st)
|
2013-09-12 17:03:32 +05:30
|
|
|
{
|
2017-08-29 17:03:32 +05:30
|
|
|
return emitter::ptr(new restorer(md, st == CLEAN_SHUTDOWN, metadata_version));
|
2013-09-12 17:03:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|