[cache_restore/dump] hint_width work.

dump/restore cycle works again.
This commit is contained in:
Joe Thornber 2013-09-26 11:36:01 +01:00
parent bd1a189298
commit bb898eeaad
10 changed files with 43 additions and 14 deletions

View File

@ -21,9 +21,9 @@ GEM
multi_json (~> 1.3) multi_json (~> 1.3)
multi_json (1.8.0) multi_json (1.8.0)
multi_test (0.0.2) multi_test (0.0.2)
rspec-expectations (2.14.2) rspec-expectations (2.14.3)
diff-lcs (>= 1.1.3, < 2.0) diff-lcs (>= 1.1.3, < 2.0)
thinp_xml (0.0.10) thinp_xml (0.0.12)
ejt_command_line (= 0.0.2) ejt_command_line (= 0.0.2)
PLATFORMS PLATFORMS

View File

@ -36,7 +36,9 @@ namespace {
emitter::ptr e = create_xml_emitter(out); emitter::ptr e = create_xml_emitter(out);
superblock const &sb = md->sb_; superblock const &sb = md->sb_;
e->begin_superblock(to_string(sb.uuid), sb.data_block_size, sb.cache_blocks, to_string(sb.policy_name)); e->begin_superblock(to_string(sb.uuid), sb.data_block_size,
sb.cache_blocks, to_string(sb.policy_name),
sb.policy_hint_size);
e->begin_mappings(); e->begin_mappings();

View File

@ -20,7 +20,8 @@ namespace caching {
virtual void begin_superblock(std::string const &uuid, virtual void begin_superblock(std::string const &uuid,
pd::block_address block_size, pd::block_address block_size,
pd::block_address nr_cache_blocks, pd::block_address nr_cache_blocks,
std::string const &policy) = 0; std::string const &policy,
size_t hint_width) = 0;
virtual void end_superblock() = 0; virtual void end_superblock() = 0;

View File

@ -36,6 +36,8 @@ namespace {
all_widths all_widths
#undef xx #undef xx
default:
throw runtime_error("invalid hint width");
} }
// never get here // never get here
@ -59,6 +61,8 @@ namespace {
#define xx(n) case n: return mk_array<n>(tm, root, nr_entries) #define xx(n) case n: return mk_array<n>(tm, root, nr_entries)
all_widths all_widths
#undef xx #undef xx
default:
throw runtime_error("invalid hint width");
} }
// never get here // never get here

View File

@ -19,12 +19,12 @@ namespace caching {
// FIXME: slow copying for now // FIXME: slow copying for now
static void unpack(disk_type const &disk, value_type &value) { static void unpack(disk_type const &disk, value_type &value) {
for (unsigned byte = 0; byte < WIDTH; byte++) for (unsigned byte = 0; byte < WIDTH; byte++)
value[byte] = disk[byte]; value.at(byte) = disk[byte];
} }
static void pack(value_type const &value, disk_type &disk) { static void pack(value_type const &value, disk_type &disk) {
for (unsigned byte = 0; byte < WIDTH; byte++) for (unsigned byte = 0; byte < WIDTH; byte++)
disk[byte] = value[byte]; disk[byte] = value.at(byte);
} }
}; };

View File

@ -57,6 +57,14 @@ metadata::commit()
commit_superblock(); commit_superblock();
} }
void
metadata::setup_hint_array(size_t width)
{
if (width > 0)
hints_ = hint_array::ptr(
new hint_array(tm_, width));
}
void void
metadata::init_superblock() metadata::init_superblock()
{ {
@ -85,7 +93,9 @@ metadata::create_metadata(block_manager<>::ptr bm)
tm_->set_sm(metadata_sm_); tm_->set_sm(metadata_sm_);
mappings_ = mapping_array::ptr(new mapping_array(tm_, mapping_array::ref_counter())); mappings_ = mapping_array::ptr(new mapping_array(tm_, mapping_array::ref_counter()));
// hints_ = hint_array::ptr(new hint_array(tm_));
// We can't instantiate the hint array yet, since we don't know the
// hint width.
} }
void void

View File

@ -28,6 +28,8 @@ namespace caching {
metadata(block_manager<>::ptr bm, open_type ot); metadata(block_manager<>::ptr bm, open_type ot);
void commit(); void commit();
void setup_hint_array(size_t width);
typedef persistent_data::transaction_manager tm; typedef persistent_data::transaction_manager tm;
tm::ptr tm_; tm::ptr tm_;

View File

@ -23,7 +23,8 @@ namespace {
virtual void begin_superblock(std::string const &uuid, virtual void begin_superblock(std::string const &uuid,
pd::block_address block_size, pd::block_address block_size,
pd::block_address nr_cache_blocks, pd::block_address nr_cache_blocks,
std::string const &policy) { std::string const &policy,
size_t hint_width) {
superblock &sb = md_->sb_; superblock &sb = md_->sb_;
@ -31,11 +32,13 @@ namespace {
memset(sb.uuid, 0, sizeof(sb.uuid)); memset(sb.uuid, 0, sizeof(sb.uuid));
sb.magic = caching::superblock_detail::SUPERBLOCK_MAGIC; sb.magic = caching::superblock_detail::SUPERBLOCK_MAGIC;
sb.version = 0; // FIXME: fix sb.version = 0; // FIXME: fix
// strncpy(sb.policy_name, policy.c_str(), sizeof(sb.policy_name)); strncpy((char *) sb.policy_name, policy.c_str(), sizeof(sb.policy_name));
memset(sb.policy_version, 0, sizeof(sb.policy_version)); memset(sb.policy_version, 0, sizeof(sb.policy_version));
sb.policy_hint_size = 0; // FIXME: fix sb.policy_hint_size = hint_width;
md_->setup_hint_array(hint_width);
memset(sb.metadata_space_map_root, 0, sizeof(sb.metadata_space_map_root)); memset(sb.metadata_space_map_root, 0,
sizeof(sb.metadata_space_map_root));
sb.mapping_root = 0; sb.mapping_root = 0;
sb.hint_root = 0; sb.hint_root = 0;
@ -60,6 +63,9 @@ namespace {
unmapped_value.oblock_ = 0; unmapped_value.oblock_ = 0;
unmapped_value.flags_ = 0; unmapped_value.flags_ = 0;
md_->mappings_->grow(nr_cache_blocks, unmapped_value); md_->mappings_->grow(nr_cache_blocks, unmapped_value);
vector<unsigned char> hint_value(hint_width, '\0');
md_->hints_->grow(nr_cache_blocks, hint_value);
} }
virtual void end_superblock() { virtual void end_superblock() {

View File

@ -22,6 +22,7 @@ superblock_traits::unpack(superblock_disk const &disk, superblock &core)
core.policy_version[i] = to_cpu<uint32_t>(disk.policy_version[i]); core.policy_version[i] = to_cpu<uint32_t>(disk.policy_version[i]);
core.policy_hint_size = to_cpu<uint32_t>(disk.policy_hint_size); core.policy_hint_size = to_cpu<uint32_t>(disk.policy_hint_size);
cerr << "unpacking: hint width = " << core.policy_hint_size << endl;
::memcpy(core.metadata_space_map_root, ::memcpy(core.metadata_space_map_root,
disk.metadata_space_map_root, disk.metadata_space_map_root,

View File

@ -33,12 +33,14 @@ namespace {
void begin_superblock(std::string const &uuid, void begin_superblock(std::string const &uuid,
block_address block_size, block_address block_size,
block_address nr_cache_blocks, block_address nr_cache_blocks,
std::string const &policy) { std::string const &policy,
size_t hint_width) {
indent(); indent();
out_ << "<superblock uuid=\"" << uuid << "\"" out_ << "<superblock uuid=\"" << uuid << "\""
<< " block_size=\"" << block_size << "\"" << " block_size=\"" << block_size << "\""
<< " nr_cache_blocks=\"" << nr_cache_blocks << "\"" << " nr_cache_blocks=\"" << nr_cache_blocks << "\""
<< " policy=\"" << policy << "\">" << endl; << " policy=\"" << policy << "\""
<< " hint_width=\"" << hint_width << "\">" << endl;
inc(); inc();
} }
@ -164,7 +166,8 @@ namespace {
e->begin_superblock(get_attr<string>(attr, "uuid"), e->begin_superblock(get_attr<string>(attr, "uuid"),
get_attr<uint64_t>(attr, "block_size"), get_attr<uint64_t>(attr, "block_size"),
get_attr<uint64_t>(attr, "nr_cache_blocks"), get_attr<uint64_t>(attr, "nr_cache_blocks"),
get_attr<string>(attr, "policy")); get_attr<string>(attr, "policy"),
get_attr<size_t>(attr, "hint_width"));
} }
bool to_bool(string const &str) { bool to_bool(string const &str) {