Make all the members of metadata shared_ptrs so it's easier to defer

construction.
This commit is contained in:
Joe Thornber 2011-10-28 16:28:24 +01:00
parent a134e853b4
commit 5c7287929a
7 changed files with 41 additions and 36 deletions

View File

@ -65,7 +65,7 @@ namespace {
block_manager<>::read_ref r = bm->read_lock(SUPERBLOCK_LOCATION);
superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&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<uint32_t>(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<void *>(&sb_.metadata_space_map_root_))),
data_sm_(open_disk_sm(tm_, static_cast<void *>(&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_disk *>(superblock.data());

View File

@ -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_;
};
}

View File

@ -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<uint64_t> const &mapped_devs = mv->get_devices();
details_validator::ptr dv(new details_validator(metadata_counter));
md->details_.visit(dv);
md->details_->visit(dv);
set<uint64_t> const &details_devs = dv->get_devices();
for (set<uint64_t>::const_iterator it = mapped_devs.begin(); it != mapped_devs.end(); ++it)

View File

@ -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<uint64_t, device_details> const &devs = de->get_devices();
map<uint64_t, device_details>::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();
}

View File

@ -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<uint32_t>(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_;

View File

@ -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<device_details> mdetail = pool_->md_->details_.lookup(key);
optional<device_details> 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<device_details> mdetail = pool_->md_->details_.lookup(key);
optional<device_details> 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<device_details> mdetail = pool_->md_->details_.lookup(key);
optional<device_details> 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<uint64_t> mtree_root = md_->mappings_top_level_.lookup(origin_key);
optional<uint64_t> 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<device_details> mdetails = md_->details_.lookup(key);
optional<device_details> 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);
}
//----------------------------------------------------------------

View File

@ -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_;
}