[thin_pool] Fix snapshot creation
This commit is contained in:
parent
2cce8a51a7
commit
66b519db83
@ -153,24 +153,27 @@ thin_pool::create_snap(thin_dev_t dev, thin_dev_t origin)
|
|||||||
uint64_t snap_key[1] = {dev};
|
uint64_t snap_key[1] = {dev};
|
||||||
uint64_t origin_key[1] = {origin};
|
uint64_t origin_key[1] = {origin};
|
||||||
|
|
||||||
boost::optional<uint64_t> mtree_root = md_->mappings_top_level_->lookup(origin_key);
|
if (device_exists(dev))
|
||||||
|
throw std::runtime_error("device already exists");
|
||||||
|
|
||||||
|
// find the mapping tree of the origin
|
||||||
|
dev_tree::maybe_value mtree_root = md_->mappings_top_level_->lookup(origin_key);
|
||||||
if (!mtree_root)
|
if (!mtree_root)
|
||||||
throw std::runtime_error("unknown origin");
|
throw std::runtime_error("unknown origin");
|
||||||
|
|
||||||
single_mapping_tree otree(*md_->tm_, *mtree_root,
|
single_mapping_tree otree(*md_->tm_, *mtree_root,
|
||||||
mapping_tree_detail::block_time_ref_counter(md_->data_sm_));
|
mapping_tree_detail::block_time_ref_counter(md_->data_sm_));
|
||||||
|
|
||||||
|
// clone the origin
|
||||||
single_mapping_tree::ptr clone(otree.clone());
|
single_mapping_tree::ptr clone(otree.clone());
|
||||||
md_->mappings_top_level_->insert(snap_key, clone->get_root());
|
md_->mappings_top_level_->insert(snap_key, clone->get_root());
|
||||||
md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly
|
md_->mappings_->set_root(md_->mappings_top_level_->get_root()); // FIXME: ugly
|
||||||
|
|
||||||
md_->sb_.time_++;
|
md_->sb_.time_++;
|
||||||
|
|
||||||
thin::ptr o = open_thin(origin);
|
// create details for the snapshot
|
||||||
thin::ptr s = open_thin(dev);
|
thin::ptr s = create_device(dev);
|
||||||
o->set_snapshot_time(md_->sb_.time_);
|
set_snapshot_details(s, origin);
|
||||||
s->set_snapshot_time(md_->sb_.time_);
|
close_device(s);
|
||||||
s->set_mapped_blocks(o->get_mapped_blocks());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -296,6 +299,16 @@ thin_pool::close_device(thin::ptr td)
|
|||||||
td->open_count_--;
|
td->open_count_--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
thin_pool::set_snapshot_details(thin::ptr snap, thin_dev_t origin)
|
||||||
|
{
|
||||||
|
thin::ptr o = open_device(origin);
|
||||||
|
o->set_snapshot_time(md_->sb_.time_);
|
||||||
|
snap->set_snapshot_time(md_->sb_.time_);
|
||||||
|
snap->set_mapped_blocks(o->get_mapped_blocks());
|
||||||
|
close_device(o);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
thin_pool::write_changed_details()
|
thin_pool::write_changed_details()
|
||||||
{
|
{
|
||||||
|
@ -98,6 +98,7 @@ namespace thin_provisioning {
|
|||||||
thin::ptr create_device(thin_dev_t dev);
|
thin::ptr create_device(thin_dev_t dev);
|
||||||
thin::ptr open_device(thin_dev_t dev);
|
thin::ptr open_device(thin_dev_t dev);
|
||||||
void close_device(thin::ptr device);
|
void close_device(thin::ptr device);
|
||||||
|
void set_snapshot_details(thin::ptr snap, thin_dev_t origin);
|
||||||
void write_changed_details();
|
void write_changed_details();
|
||||||
|
|
||||||
metadata::ptr md_;
|
metadata::ptr md_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user