diff --git a/thin-provisioning/device_tree.cc b/thin-provisioning/device_tree.cc index f4fffac..5684ab0 100644 --- a/thin-provisioning/device_tree.cc +++ b/thin-provisioning/device_tree.cc @@ -37,6 +37,24 @@ namespace { namespace thin_provisioning { namespace device_tree_detail { + void + device_details_traits::unpack(device_details_disk const &disk, device_details &value) + { + value.mapped_blocks_ = to_cpu(disk.mapped_blocks_); + value.transaction_id_ = to_cpu(disk.transaction_id_); + value.creation_time_ = to_cpu(disk.creation_time_); + value.snapshotted_time_ = to_cpu(disk.snapshotted_time_); + } + + void + device_details_traits::pack(device_details const &value, device_details_disk &disk) + { + disk.mapped_blocks_ = to_disk(value.mapped_blocks_); + disk.transaction_id_ = to_disk(value.transaction_id_); + disk.creation_time_ = to_disk(value.creation_time_); + disk.snapshotted_time_ = to_disk(value.snapshotted_time_); + } + missing_devices::missing_devices(std::string const &desc, range const &keys) : desc_(desc), diff --git a/thin-provisioning/device_tree.h b/thin-provisioning/device_tree.h index 1e51b77..c088c3b 100644 --- a/thin-provisioning/device_tree.h +++ b/thin-provisioning/device_tree.h @@ -4,14 +4,33 @@ #include "persistent-data/data-structures/btree.h" #include "persistent-data/range.h" -#include "thin-provisioning/metadata_disk_structures.h" - //---------------------------------------------------------------- namespace thin_provisioning { - typedef persistent_data::btree<1, device_details_traits> device_tree; - namespace device_tree_detail { + struct device_details_disk { + le64 mapped_blocks_; + le64 transaction_id_; /* when created */ + le32 creation_time_; + le32 snapshotted_time_; + } __attribute__ ((packed)); + + struct device_details { + uint64_t mapped_blocks_; + uint64_t transaction_id_; /* when created */ + uint32_t creation_time_; + uint32_t snapshotted_time_; + }; + + struct device_details_traits { + typedef device_details_disk disk_type; + typedef device_details value_type; + typedef persistent_data::no_op_ref_counter ref_counter; + + static void unpack(device_details_disk const &disk, device_details &value); + static void pack(device_details const &value, device_details_disk &disk); + }; + class damage_visitor; struct damage { @@ -42,6 +61,8 @@ namespace thin_provisioning { }; + typedef persistent_data::btree<1, device_tree_detail::device_details_traits> device_tree; + void check_device_tree(device_tree const &tree, device_tree_detail::damage_visitor &visitor); } diff --git a/thin-provisioning/metadata.cc b/thin-provisioning/metadata.cc index 3ce66d6..a35a521 100644 --- a/thin-provisioning/metadata.cc +++ b/thin-provisioning/metadata.cc @@ -107,7 +107,7 @@ metadata::metadata(std::string const &dev_path, open_type ot, tm_->set_sm(metadata_sm_); data_sm_ = open_disk_sm(tm_, static_cast(&sb_.data_space_map_root_)); - details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_details_traits::ref_counter())); + details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_tree_detail::device_details_traits::ref_counter())); mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_))); mappings_ = mapping_tree::ptr(new mapping_tree(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_))); break; @@ -120,7 +120,7 @@ metadata::metadata(std::string const &dev_path, open_type ot, tm_->set_sm(metadata_sm_); data_sm_ = create_disk_sm(tm_, nr_data_blocks); - details_ = device_tree::ptr(new device_tree(tm_, device_details_traits::ref_counter())); + details_ = device_tree::ptr(new device_tree(tm_, device_tree_detail::device_details_traits::ref_counter())); mappings_ = mapping_tree::ptr(new mapping_tree(tm_, block_time_ref_counter(data_sm_))); mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, mappings_->get_root(), mtree_ref_counter(tm_))); @@ -146,7 +146,7 @@ metadata::metadata(std::string const &dev_path, block_address metadata_snap) tm_->set_sm(metadata_sm_); data_sm_ = open_disk_sm(tm_, static_cast(&sb_.data_space_map_root_)); - details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_details_traits::ref_counter())); + details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_tree_detail::device_details_traits::ref_counter())); mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_))); mappings_ = mapping_tree::ptr(new mapping_tree(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_))); } @@ -168,7 +168,7 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot, tm_->set_sm(metadata_sm_); data_sm_ = open_disk_sm(tm_, static_cast(&sb_.data_space_map_root_)); - details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_details_traits::ref_counter())); + details_ = device_tree::ptr(new device_tree(tm_, sb_.device_details_root_, device_tree_detail::device_details_traits::ref_counter())); mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, sb_.data_mapping_root_, mtree_ref_counter(tm_))); mappings_ = mapping_tree::ptr(new mapping_tree(tm_, sb_.data_mapping_root_, block_time_ref_counter(data_sm_))); break; @@ -181,7 +181,7 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot, tm_->set_sm(metadata_sm_); data_sm_ = create_disk_sm(tm_, nr_data_blocks); - details_ = device_tree::ptr(new device_tree(tm_, device_details_traits::ref_counter())); + details_ = device_tree::ptr(new device_tree(tm_, device_tree_detail::device_details_traits::ref_counter())); mappings_ = mapping_tree::ptr(new mapping_tree(tm_, block_time_ref_counter(data_sm_))); mappings_top_level_ = dev_tree::ptr(new dev_tree(tm_, mappings_->get_root(), mtree_ref_counter(tm_))); diff --git a/thin-provisioning/metadata_disk_structures.cc b/thin-provisioning/metadata_disk_structures.cc index a32d5d4..f484763 100644 --- a/thin-provisioning/metadata_disk_structures.cc +++ b/thin-provisioning/metadata_disk_structures.cc @@ -24,24 +24,6 @@ using namespace thin_provisioning; //---------------------------------------------------------------- -void -device_details_traits::unpack(device_details_disk const &disk, device_details &value) -{ - value.mapped_blocks_ = to_cpu(disk.mapped_blocks_); - value.transaction_id_ = to_cpu(disk.transaction_id_); - value.creation_time_ = to_cpu(disk.creation_time_); - value.snapshotted_time_ = to_cpu(disk.snapshotted_time_); -} - -void -device_details_traits::pack(device_details const &value, device_details_disk &disk) -{ - disk.mapped_blocks_ = to_disk(value.mapped_blocks_); - disk.transaction_id_ = to_disk(value.transaction_id_); - disk.creation_time_ = to_disk(value.creation_time_); - disk.snapshotted_time_ = to_disk(value.snapshotted_time_); -} - void superblock_traits::unpack(superblock_disk const &disk, superblock &value) { diff --git a/thin-provisioning/metadata_disk_structures.h b/thin-provisioning/metadata_disk_structures.h index 76fe27d..0b1d978 100644 --- a/thin-provisioning/metadata_disk_structures.h +++ b/thin-provisioning/metadata_disk_structures.h @@ -27,29 +27,6 @@ namespace thin_provisioning { using namespace base; // FIXME: don't use namespaces in headers. - struct device_details_disk { - le64 mapped_blocks_; - le64 transaction_id_; /* when created */ - le32 creation_time_; - le32 snapshotted_time_; - } __attribute__ ((packed)); - - struct device_details { - uint64_t mapped_blocks_; - uint64_t transaction_id_; /* when created */ - uint32_t creation_time_; - uint32_t snapshotted_time_; - }; - - struct device_details_traits { - typedef device_details_disk disk_type; - typedef device_details value_type; - typedef persistent_data::no_op_ref_counter ref_counter; - - static void unpack(device_details_disk const &disk, device_details &value); - static void pack(device_details const &value, device_details_disk &disk); - }; - unsigned const SPACE_MAP_ROOT_SIZE = 128; typedef unsigned char __u8; diff --git a/thin-provisioning/metadata_dumper.cc b/thin-provisioning/metadata_dumper.cc index 1848ab0..5933bf1 100644 --- a/thin-provisioning/metadata_dumper.cc +++ b/thin-provisioning/metadata_dumper.cc @@ -135,11 +135,11 @@ namespace { bool found_errors_; }; - class details_extractor : public btree<1, device_details_traits>::visitor { + class details_extractor : public btree<1, device_tree_detail::device_details_traits>::visitor { public: - typedef typename btree<1, device_details_traits>::visitor::node_location node_location; + typedef typename btree<1, device_tree_detail::device_details_traits>::visitor::node_location node_location; typedef boost::shared_ptr ptr; - typedef btree_checker<1, device_details_traits> checker; + typedef btree_checker<1, device_tree_detail::device_details_traits> checker; details_extractor() : counter_(), @@ -157,7 +157,7 @@ namespace { } bool visit_leaf(node_location const &loc, - btree_detail::node_ref const &n) { + btree_detail::node_ref const &n) { if (!checker_.visit_leaf(loc, n)) return false; @@ -167,7 +167,7 @@ namespace { return true; } - map const &get_devices() const { + map const &get_devices() const { return devices_; } @@ -179,7 +179,7 @@ namespace { // Declaration order of counter_ and checker_ is important. block_counter counter_; checker checker_; - map devices_; + map devices_; }; } @@ -203,12 +203,12 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, bool repair) if (de.corruption() && !repair) throw runtime_error("corruption in device details tree"); - map const &devs = de.get_devices(); + map const &devs = de.get_devices(); - map::const_iterator it, end = devs.end(); + map::const_iterator it, end = devs.end(); for (it = devs.begin(); it != end; ++it) { uint64_t dev_id = it->first; - device_details const &dd = it->second; + device_tree_detail::device_details const &dd = it->second; e->begin_device(dev_id, dd.mapped_blocks_, diff --git a/thin-provisioning/restore_emitter.cc b/thin-provisioning/restore_emitter.cc index fa12f3e..c57c700 100644 --- a/thin-provisioning/restore_emitter.cc +++ b/thin-provisioning/restore_emitter.cc @@ -76,7 +76,7 @@ namespace { // Add entry to the details tree uint64_t key[1] = {dev}; - device_details details = {mapped_blocks, trans_id, (uint32_t)creation_time, (uint32_t)snap_time}; + device_tree_detail::device_details details = {mapped_blocks, trans_id, (uint32_t)creation_time, (uint32_t)snap_time}; md_->details_->insert(key, details); current_mapping_ = empty_mapping_->clone(); diff --git a/thin-provisioning/thin_pool.cc b/thin-provisioning/thin_pool.cc index 71716c2..9c233d7 100644 --- a/thin-provisioning/thin_pool.cc +++ b/thin-provisioning/thin_pool.cc @@ -73,7 +73,7 @@ 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"); @@ -85,7 +85,7 @@ 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"); @@ -96,7 +96,7 @@ 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"); @@ -220,7 +220,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");