diff --git a/caching/cache_dump.cc b/caching/cache_dump.cc index 31ca00a..0cfb806 100644 --- a/caching/cache_dump.cc +++ b/caching/cache_dump.cc @@ -4,12 +4,14 @@ #include #include "version.h" +#include "caching/mapping_array.h" #include "caching/metadata.h" #include "caching/xml_format.h" #include "persistent-data/file_utils.h" using namespace std; using namespace caching; +using namespace caching::mapping_array_detail; using namespace caching::superblock_detail; //---------------------------------------------------------------- @@ -35,6 +37,18 @@ namespace { 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_mappings(); + + for (unsigned cblock = 0; cblock < sb.cache_blocks; cblock++) { + mapping m = md->mappings_->get(cblock); + + if (m.flags_ & M_VALID) + e->mapping(cblock, m.oblock_, m.flags_ & M_DIRTY); + } + + e->end_mappings(); + e->end_superblock(); return 0; diff --git a/caching/mapping_array.cc b/caching/mapping_array.cc index 3e43d87..c26460e 100644 --- a/caching/mapping_array.cc +++ b/caching/mapping_array.cc @@ -21,7 +21,7 @@ void mapping_traits::pack(value_type const &value, disk_type &disk) { uint64_t packed = value.oblock_ << 16; - packed = packed || (value.flags_ & FLAGS_MASK); + packed = packed | (value.flags_ & FLAGS_MASK); disk = base::to_disk(packed); } diff --git a/caching/metadata.cc b/caching/metadata.cc index d152874..66954d5 100644 --- a/caching/metadata.cc +++ b/caching/metadata.cc @@ -51,13 +51,9 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot) void metadata::commit() { - metadata_sm_->commit(); - metadata_sm_->copy_root(&sb_.metadata_space_map_root, sizeof(sb_.metadata_space_map_root)); - sb_.mapping_root = mappings_->get_root(); - - write_ref superblock = tm_->get_bm()->superblock_zero(SUPERBLOCK_LOCATION, superblock_validator()); - superblock_disk *disk = reinterpret_cast(superblock.data().raw()); - superblock_traits::pack(sb_, *disk); + commit_space_map(); + commit_mappings(); + commit_superblock(); } void @@ -96,6 +92,33 @@ metadata::open_metadata(block_manager<>::ptr bm) { tm_ = open_tm(bm); sb_ = read_superblock(tm_->get_bm()); + + mappings_ = mapping_array::ptr( + new mapping_array(tm_, + mapping_array::ref_counter(), + sb_.mapping_root, + sb_.cache_blocks)); +} + +void +metadata::commit_space_map() +{ + metadata_sm_->commit(); + metadata_sm_->copy_root(&sb_.metadata_space_map_root, sizeof(sb_.metadata_space_map_root)); +} + +void +metadata::commit_mappings() +{ + sb_.mapping_root = mappings_->get_root(); +} + +void +metadata::commit_superblock() +{ + write_ref superblock = tm_->get_bm()->superblock_zero(SUPERBLOCK_LOCATION, superblock_validator()); + superblock_disk *disk = reinterpret_cast(superblock.data().raw()); + superblock_traits::pack(sb_, *disk); } //---------------------------------------------------------------- diff --git a/caching/metadata.h b/caching/metadata.h index 20cb3d5..0556125 100644 --- a/caching/metadata.h +++ b/caching/metadata.h @@ -41,6 +41,10 @@ namespace caching { void create_metadata(block_manager<>::ptr bm); void open_metadata(block_manager<>::ptr bm); + + void commit_space_map(); + void commit_mappings(); + void commit_superblock(); }; }; diff --git a/caching/restore_emitter.cc b/caching/restore_emitter.cc index f871e61..c705a25 100644 --- a/caching/restore_emitter.cc +++ b/caching/restore_emitter.cc @@ -79,7 +79,10 @@ namespace { bool dirty) { mapping_array_detail::mapping m; m.oblock_ = oblock; - m.flags_ = 0; + m.flags_ = M_VALID; + + if (dirty) + m.flags_ = m.flags_ | M_DIRTY; md_->mappings_->set(cblock, m); }