Move device_details_traits into the device_tree_detail namespace.

This commit is contained in:
Joe Thornber 2013-05-20 16:35:26 +01:00
parent fcb617f858
commit 35880f3038
8 changed files with 62 additions and 64 deletions

View File

@ -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<uint64_t>(disk.mapped_blocks_);
value.transaction_id_ = to_cpu<uint64_t>(disk.transaction_id_);
value.creation_time_ = to_cpu<uint32_t>(disk.creation_time_);
value.snapshotted_time_ = to_cpu<uint32_t>(disk.snapshotted_time_);
}
void
device_details_traits::pack(device_details const &value, device_details_disk &disk)
{
disk.mapped_blocks_ = to_disk<le64>(value.mapped_blocks_);
disk.transaction_id_ = to_disk<le64>(value.transaction_id_);
disk.creation_time_ = to_disk<le32>(value.creation_time_);
disk.snapshotted_time_ = to_disk<le32>(value.snapshotted_time_);
}
missing_devices::missing_devices(std::string const &desc,
range<uint64_t> const &keys)
: desc_(desc),

View File

@ -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<device_details> 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);
}

View File

@ -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<void *>(&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<void *>(&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<void *>(&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_)));

View File

@ -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<uint64_t>(disk.mapped_blocks_);
value.transaction_id_ = to_cpu<uint64_t>(disk.transaction_id_);
value.creation_time_ = to_cpu<uint32_t>(disk.creation_time_);
value.snapshotted_time_ = to_cpu<uint32_t>(disk.snapshotted_time_);
}
void
device_details_traits::pack(device_details const &value, device_details_disk &disk)
{
disk.mapped_blocks_ = to_disk<le64>(value.mapped_blocks_);
disk.transaction_id_ = to_disk<le64>(value.transaction_id_);
disk.creation_time_ = to_disk<le32>(value.creation_time_);
disk.snapshotted_time_ = to_disk<le32>(value.snapshotted_time_);
}
void
superblock_traits::unpack(superblock_disk const &disk, superblock &value)
{

View File

@ -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<device_details> 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;

View File

@ -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<details_extractor> 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<device_details_traits> const &n) {
btree_detail::node_ref<device_tree_detail::device_details_traits> const &n) {
if (!checker_.visit_leaf(loc, n))
return false;
@ -167,7 +167,7 @@ namespace {
return true;
}
map<uint64_t, device_details> const &get_devices() const {
map<uint64_t, device_tree_detail::device_details> 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<uint64_t, device_details> devices_;
map<uint64_t, device_tree_detail::device_details> 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<uint64_t, device_details> const &devs = de.get_devices();
map<uint64_t, device_tree_detail::device_details> const &devs = de.get_devices();
map<uint64_t, device_details>::const_iterator it, end = devs.end();
map<uint64_t, device_tree_detail::device_details>::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_,

View File

@ -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();

View File

@ -73,7 +73,7 @@ void
thin::set_snapshot_time(uint32_t time)
{
uint64_t key[1] = { dev_ };
optional<device_details> mdetail = pool_->md_->details_->lookup(key);
optional<device_tree_detail::device_details> 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<device_details> mdetail = pool_->md_->details_->lookup(key);
optional<device_tree_detail::device_details> 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<device_details> mdetail = pool_->md_->details_->lookup(key);
optional<device_tree_detail::device_details> 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<device_details> mdetails = md_->details_->lookup(key);
optional<device_tree_detail::device_details> mdetails = md_->details_->lookup(key);
if (!mdetails)
throw runtime_error("no such device");