[cache_restore/dump] mappings dump restore ok now
This commit is contained in:
		| @@ -4,12 +4,14 @@ | ||||
| #include <iostream> | ||||
|  | ||||
| #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; | ||||
|   | ||||
| @@ -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<le64>(packed); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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_disk *>(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_disk *>(superblock.data().raw()); | ||||
| 	superblock_traits::pack(sb_, *disk); | ||||
| } | ||||
|  | ||||
| //---------------------------------------------------------------- | ||||
|   | ||||
| @@ -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(); | ||||
| 	}; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -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); | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user