diff --git a/metadata.cc b/metadata.cc index 82badbb..1032f44 100644 --- a/metadata.cc +++ b/metadata.cc @@ -65,7 +65,7 @@ namespace { block_manager<>::read_ref r = bm->read_lock(SUPERBLOCK_LOCATION); superblock_disk const *sbd = reinterpret_cast(&r.data()); - crc32c sum(160774); + crc32c sum(160774); // FIXME: magic number sum.append(&sbd->flags_, MD_BLOCK_SIZE - sizeof(uint32_t)); if (sum.get_sum() != to_cpu(sbd->csum_)) { ostringstream out; @@ -87,10 +87,11 @@ metadata::metadata(std::string const &dev_path, open_type ot) sb_(read_superblock(tm_->get_bm())), metadata_sm_(open_metadata_sm(tm_, static_cast(&sb_.metadata_space_map_root_))), data_sm_(open_disk_sm(tm_, static_cast(&sb_.data_space_map_root_))), - details_(tm_, sb_.device_details_root_, device_details_traits::ref_counter()), - mappings_top_level_(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_)), - mappings_(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_)) + details_(new detail_tree(tm_, sb_.device_details_root_, device_details_traits::ref_counter())), + mappings_top_level_(new dev_tree(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_))), + mappings_(new mapping_tree(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_))) { + tm_->set_sm(open_metadata_sm(tm_, sb_.metadata_space_map_root_)); } #if 0 @@ -104,10 +105,10 @@ metadata::metadata(std::string const &dev_path, open_type ot) void metadata::commit() { - sb_.data_mapping_root_ = mappings_.get_root(); - sb_.device_details_root_ = details_.get_root(); + sb_.data_mapping_root_ = mappings_->get_root(); + sb_.device_details_root_ = details_->get_root(); - // FIXME: copy the space map roots + // FIXME: commit and copy the space map roots write_ref superblock = tm_->get_bm()->superblock(SUPERBLOCK_LOCATION); superblock_disk *disk = reinterpret_cast(superblock.data()); diff --git a/metadata.h b/metadata.h index 39329d7..eebe006 100644 --- a/metadata.h +++ b/metadata.h @@ -142,9 +142,9 @@ namespace thin_provisioning { checked_space_map::ptr metadata_sm_; checked_space_map::ptr data_sm_; - detail_tree details_; - dev_tree mappings_top_level_; - mapping_tree mappings_; + detail_tree::ptr details_; + dev_tree::ptr mappings_top_level_; + mapping_tree::ptr mappings_; }; } diff --git a/metadata_checker.cc b/metadata_checker.cc index c212076..a826f5c 100644 --- a/metadata_checker.cc +++ b/metadata_checker.cc @@ -133,11 +133,11 @@ thin_provisioning::metadata_check(metadata::ptr md) mapping_validator::ptr mv(new mapping_validator(metadata_counter, data_counter)); - md->mappings_.visit(mv); + md->mappings_->visit(mv); set const &mapped_devs = mv->get_devices(); details_validator::ptr dv(new details_validator(metadata_counter)); - md->details_.visit(dv); + md->details_->visit(dv); set const &details_devs = dv->get_devices(); for (set::const_iterator it = mapped_devs.begin(); it != mapped_devs.end(); ++it) diff --git a/metadata_dumper.cc b/metadata_dumper.cc index 851310d..d6598cc 100644 --- a/metadata_dumper.cc +++ b/metadata_dumper.cc @@ -133,7 +133,7 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e) details_extractor::ptr de(new details_extractor); - md->details_.visit(de); + md->details_->visit(de); map const &devs = de->get_devices(); map::const_iterator it, end = devs.end(); @@ -148,7 +148,7 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e) dd.snapshotted_time_); mappings_extractor::ptr me(new mappings_extractor(dev_id, e, md->metadata_sm_, md->data_sm_)); - md->mappings_.visit(me); + md->mappings_->visit(me); e->end_device(); } diff --git a/restore_emitter.cc b/restore_emitter.cc index 3fe2046..5a2a874 100644 --- a/restore_emitter.cc +++ b/restore_emitter.cc @@ -56,14 +56,14 @@ namespace { // Add entry to the details tree uint64_t key[1] = {dev}; device_details details = {mapped_blocks, trans_id, creation_time, snap_time}; - md_->details_.insert(key, details); + md_->details_->insert(key, details); // Insert an empty mapping tree single_mapping_tree::ptr new_tree( new single_mapping_tree(md_->tm_, block_time_ref_counter(md_->data_sm_))); - md_->mappings_top_level_.insert(key, new_tree->get_root()); - md_->mappings_.set_root(md_->mappings_top_level_.get_root()); // FIXME: ugly + md_->mappings_top_level_->insert(key, new_tree->get_root()); + md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly current_device_ = optional(dev); } @@ -97,14 +97,14 @@ namespace { block_time bt; bt.block_ = data_block; bt.time_ = time; - md_->mappings_.insert(key, bt); - md_->mappings_top_level_.set_root(md_->mappings_.get_root()); + md_->mappings_->insert(key, bt); + md_->mappings_top_level_->set_root(md_->mappings_->get_root()); } private: bool device_exists(thin_dev_t dev) const { uint64_t key[1] = {dev}; - return md_->details_.lookup(key); + return md_->details_->lookup(key); } metadata::ptr md_; diff --git a/thin_pool.cc b/thin_pool.cc index 0e5c9ce..fb6ef4c 100644 --- a/thin_pool.cc +++ b/thin_pool.cc @@ -31,7 +31,7 @@ thin::maybe_address thin::lookup(block_address thin_block) { uint64_t key[2] = {dev_, thin_block}; - return pool_->md_->mappings_.lookup(key); + return pool_->md_->mappings_->lookup(key); } void @@ -41,33 +41,33 @@ thin::insert(block_address thin_block, block_address data_block) block_time bt; bt.block_ = data_block; bt.time_ = 0; // FIXME: use current time. - return pool_->md_->mappings_.insert(key, bt); + return pool_->md_->mappings_->insert(key, bt); } void thin::remove(block_address thin_block) { uint64_t key[2] = {dev_, thin_block}; - pool_->md_->mappings_.remove(key); + pool_->md_->mappings_->remove(key); } void thin::set_snapshot_time(uint32_t time) { uint64_t key[1] = { dev_ }; - optional mdetail = pool_->md_->details_.lookup(key); + optional mdetail = pool_->md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); mdetail->snapshotted_time_ = time; - pool_->md_->details_.insert(key, *mdetail); + pool_->md_->details_->insert(key, *mdetail); } block_address thin::get_mapped_blocks() const { uint64_t key[1] = { dev_ }; - optional mdetail = pool_->md_->details_.lookup(key); + optional mdetail = pool_->md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); @@ -78,12 +78,12 @@ void thin::set_mapped_blocks(block_address count) { uint64_t key[1] = { dev_ }; - optional mdetail = pool_->md_->details_.lookup(key); + optional mdetail = pool_->md_->details_->lookup(key); if (!mdetail) throw runtime_error("no such device"); mdetail->mapped_blocks_ = count; - pool_->md_->details_.insert(key, *mdetail); + pool_->md_->details_->insert(key, *mdetail); } //-------------------------------- @@ -107,8 +107,8 @@ thin_pool::create_thin(thin_dev_t dev) throw std::runtime_error("Device already exists"); single_mapping_tree::ptr new_tree(new single_mapping_tree(md_->tm_, block_time_ref_counter(md_->data_sm_))); - md_->mappings_top_level_.insert(key, new_tree->get_root()); - md_->mappings_.set_root(md_->mappings_top_level_.get_root()); // FIXME: ugly + md_->mappings_top_level_->insert(key, new_tree->get_root()); + md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly // FIXME: doesn't set up the device details } @@ -119,7 +119,7 @@ thin_pool::create_snap(thin_dev_t dev, thin_dev_t origin) uint64_t snap_key[1] = {dev}; uint64_t origin_key[1] = {origin}; - optional mtree_root = md_->mappings_top_level_.lookup(origin_key); + optional mtree_root = md_->mappings_top_level_->lookup(origin_key); if (!mtree_root) throw std::runtime_error("unknown origin"); @@ -127,8 +127,8 @@ thin_pool::create_snap(thin_dev_t dev, thin_dev_t origin) block_time_ref_counter(md_->data_sm_)); single_mapping_tree::ptr clone(otree.clone()); - md_->mappings_top_level_.insert(snap_key, clone->get_root()); - md_->mappings_.set_root(md_->mappings_top_level_.get_root()); // FIXME: ugly + md_->mappings_top_level_->insert(snap_key, clone->get_root()); + md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly md_->sb_.time_++; @@ -143,7 +143,7 @@ void thin_pool::del(thin_dev_t dev) { uint64_t key[1] = {dev}; - md_->mappings_top_level_.remove(key); + md_->mappings_top_level_->remove(key); } void @@ -198,7 +198,7 @@ thin::ptr thin_pool::open_thin(thin_dev_t dev) { uint64_t key[1] = {dev}; - optional mdetails = md_->details_.lookup(key); + optional mdetails = md_->details_->lookup(key); if (!mdetails) throw runtime_error("no such device"); @@ -211,7 +211,7 @@ bool thin_pool::device_exists(thin_dev_t dev) const { uint64_t key[1] = {dev}; - return md_->details_.lookup(key); + return md_->details_->lookup(key); } //---------------------------------------------------------------- diff --git a/transaction_manager.h b/transaction_manager.h index 353b38d..98045de 100644 --- a/transaction_manager.h +++ b/transaction_manager.h @@ -44,6 +44,10 @@ namespace persistent_data { return sm_; } + void set_sm(space_map::ptr sm) { + sm_ = sm; + } + block_manager<>::ptr get_bm() { return bm_; }