diff --git a/Gemfile.lock b/Gemfile.lock index f7aad93..5e49ad7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -21,9 +21,9 @@ GEM multi_json (~> 1.3) multi_json (1.8.0) multi_test (0.0.2) - rspec-expectations (2.14.2) + rspec-expectations (2.14.3) diff-lcs (>= 1.1.3, < 2.0) - thinp_xml (0.0.10) + thinp_xml (0.0.12) ejt_command_line (= 0.0.2) PLATFORMS diff --git a/caching/cache_dump.cc b/caching/cache_dump.cc index 0cfb806..2702820 100644 --- a/caching/cache_dump.cc +++ b/caching/cache_dump.cc @@ -36,7 +36,9 @@ namespace { emitter::ptr e = create_xml_emitter(out); 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(); diff --git a/caching/emitter.h b/caching/emitter.h index c70b56e..1563cdc 100644 --- a/caching/emitter.h +++ b/caching/emitter.h @@ -20,7 +20,8 @@ namespace caching { virtual void begin_superblock(std::string const &uuid, pd::block_address block_size, 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; diff --git a/caching/hint_array.cc b/caching/hint_array.cc index 0c6c39d..5e2375a 100644 --- a/caching/hint_array.cc +++ b/caching/hint_array.cc @@ -36,6 +36,8 @@ namespace { all_widths #undef xx + default: + throw runtime_error("invalid hint width"); } // never get here @@ -59,6 +61,8 @@ namespace { #define xx(n) case n: return mk_array(tm, root, nr_entries) all_widths #undef xx + default: + throw runtime_error("invalid hint width"); } // never get here diff --git a/caching/hint_array.h b/caching/hint_array.h index dd8d2a5..6bb9884 100644 --- a/caching/hint_array.h +++ b/caching/hint_array.h @@ -19,12 +19,12 @@ namespace caching { // FIXME: slow copying for now static void unpack(disk_type const &disk, value_type &value) { 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) { for (unsigned byte = 0; byte < WIDTH; byte++) - disk[byte] = value[byte]; + disk[byte] = value.at(byte); } }; diff --git a/caching/metadata.cc b/caching/metadata.cc index 4e26657..90a1dd3 100644 --- a/caching/metadata.cc +++ b/caching/metadata.cc @@ -57,6 +57,14 @@ metadata::commit() commit_superblock(); } +void +metadata::setup_hint_array(size_t width) +{ + if (width > 0) + hints_ = hint_array::ptr( + new hint_array(tm_, width)); +} + void metadata::init_superblock() { @@ -85,7 +93,9 @@ metadata::create_metadata(block_manager<>::ptr bm) tm_->set_sm(metadata_sm_); 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 diff --git a/caching/metadata.h b/caching/metadata.h index d4a6cd2..e4fe965 100644 --- a/caching/metadata.h +++ b/caching/metadata.h @@ -28,6 +28,8 @@ namespace caching { metadata(block_manager<>::ptr bm, open_type ot); void commit(); + void setup_hint_array(size_t width); + typedef persistent_data::transaction_manager tm; tm::ptr tm_; diff --git a/caching/restore_emitter.cc b/caching/restore_emitter.cc index 8269ad7..35654da 100644 --- a/caching/restore_emitter.cc +++ b/caching/restore_emitter.cc @@ -23,7 +23,8 @@ namespace { virtual void begin_superblock(std::string const &uuid, pd::block_address block_size, pd::block_address nr_cache_blocks, - std::string const &policy) { + std::string const &policy, + size_t hint_width) { superblock &sb = md_->sb_; @@ -31,11 +32,13 @@ namespace { memset(sb.uuid, 0, sizeof(sb.uuid)); sb.magic = caching::superblock_detail::SUPERBLOCK_MAGIC; 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)); - 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.hint_root = 0; @@ -60,6 +63,9 @@ namespace { unmapped_value.oblock_ = 0; unmapped_value.flags_ = 0; md_->mappings_->grow(nr_cache_blocks, unmapped_value); + + vector hint_value(hint_width, '\0'); + md_->hints_->grow(nr_cache_blocks, hint_value); } virtual void end_superblock() { diff --git a/caching/superblock.cc b/caching/superblock.cc index e783e16..2766c24 100644 --- a/caching/superblock.cc +++ b/caching/superblock.cc @@ -22,6 +22,7 @@ superblock_traits::unpack(superblock_disk const &disk, superblock &core) core.policy_version[i] = to_cpu(disk.policy_version[i]); core.policy_hint_size = to_cpu(disk.policy_hint_size); + cerr << "unpacking: hint width = " << core.policy_hint_size << endl; ::memcpy(core.metadata_space_map_root, disk.metadata_space_map_root, diff --git a/caching/xml_format.cc b/caching/xml_format.cc index f3b9610..50180ff 100644 --- a/caching/xml_format.cc +++ b/caching/xml_format.cc @@ -33,12 +33,14 @@ namespace { void begin_superblock(std::string const &uuid, block_address block_size, block_address nr_cache_blocks, - std::string const &policy) { + std::string const &policy, + size_t hint_width) { indent(); out_ << "" << endl; + << " policy=\"" << policy << "\"" + << " hint_width=\"" << hint_width << "\">" << endl; inc(); } @@ -164,7 +166,8 @@ namespace { e->begin_superblock(get_attr(attr, "uuid"), get_attr(attr, "block_size"), get_attr(attr, "nr_cache_blocks"), - get_attr(attr, "policy")); + get_attr(attr, "policy"), + get_attr(attr, "hint_width")); } bool to_bool(string const &str) {