Merge remote-tracking branch 'ejt/master'

This commit is contained in:
Heinz Mauelshagen 2013-08-08 12:10:41 +02:00
commit a441b7d4db
10 changed files with 65 additions and 47 deletions

View File

@ -83,7 +83,7 @@ OBJECTS:=$(subst .cc,.o,$(SOURCE))
TOP_DIR:=@top_srcdir@ TOP_DIR:=@top_srcdir@
TOP_BUILDDIR:=@top_builddir@ TOP_BUILDDIR:=@top_builddir@
CFLAGS+=-g -Wall -O3 CFLAGS+=-g -Wall -O3
CXXFLAGS+=-std=c++11 -g -Wall -fno-strict-aliasing CXXFLAGS+=-g -Wall -fno-strict-aliasing
CXXFLAGS+=@CXXOPTIMISE_FLAG@ CXXFLAGS+=@CXXOPTIMISE_FLAG@
CXXFLAGS+=@CXXDEBUG_FLAG@ CXXFLAGS+=@CXXDEBUG_FLAG@
INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning

View File

@ -62,7 +62,7 @@ namespace base {
if (!runs_.size()) if (!runs_.size())
return false; return false;
auto it = runs_.lower_bound(run<T>(v)); typename rset::const_iterator it = runs_.lower_bound(run<T>(v));
if (it->begin_ == v) if (it->begin_ == v)
return true; return true;
@ -98,7 +98,7 @@ namespace base {
if (runs_.begin() == runs_.end()) if (runs_.begin() == runs_.end())
replacement.insert(run<T>()); replacement.insert(run<T>());
else { else {
auto b = runs_.begin(); typename rset::const_iterator b = runs_.begin();
maybe last = b->end_; maybe last = b->end_;
if (b->begin_) if (b->begin_)

View File

@ -19,6 +19,8 @@
#include "persistent-data/space-maps/careful_alloc.h" #include "persistent-data/space-maps/careful_alloc.h"
#include "persistent-data/space-maps/subtracting_span_iterator.h" #include "persistent-data/space-maps/subtracting_span_iterator.h"
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace { namespace {
@ -26,7 +28,7 @@ namespace {
class sm_careful_alloc : public checked_space_map { class sm_careful_alloc : public checked_space_map {
public: public:
typedef std::shared_ptr<sm_careful_alloc> ptr; typedef boost::shared_ptr<sm_careful_alloc> ptr;
sm_careful_alloc(checked_space_map::ptr sm) sm_careful_alloc(checked_space_map::ptr sm)
: sm_(sm) { : sm_(sm) {

View File

@ -29,16 +29,19 @@ rmap_visitor::visit(btree_path const &path,
} }
} }
namespace {
bool cmp_data_begin(rmap_visitor::rmap_region const &lhs,
rmap_visitor::rmap_region const &rhs) {
return lhs.data_begin < rhs.data_begin;
};
}
void void
rmap_visitor::complete() rmap_visitor::complete()
{ {
if (current_rmap_) if (current_rmap_)
push_current(); push_current();
auto cmp_data_begin = [] (rmap_region const &lhs, rmap_region const &rhs) {
return lhs.data_begin < rhs.data_begin;
};
std::sort(rmap_.begin(), rmap_.end(), cmp_data_begin); std::sort(rmap_.begin(), rmap_.end(), cmp_data_begin);
} }
@ -52,8 +55,9 @@ rmap_visitor::get_rmap() const
bool bool
rmap_visitor::in_regions(block_address b) const rmap_visitor::in_regions(block_address b) const
{ {
for (region const &r : regions_) vector<region>::const_iterator it;
if (r.contains(b)) for (it = regions_.begin(); it != regions_.end(); ++it)
if (it->contains(b))
return true; return true;
return false; return false;

View File

@ -131,7 +131,7 @@ namespace thin_provisioning {
using namespace superblock_detail; using namespace superblock_detail;
superblock sb; superblock sb;
auto r = bm->read_lock(location, superblock_validator()); block_manager<>::read_ref r = bm->read_lock(location, superblock_validator());
superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&r.data()); superblock_disk const *sbd = reinterpret_cast<superblock_disk const *>(&r.data());
superblock_traits::unpack(*sbd, sb); superblock_traits::unpack(*sbd, sb);
return sb; return sb;

View File

@ -168,7 +168,7 @@ namespace {
virtual void visit(superblock_detail::superblock_corruption const &d) { virtual void visit(superblock_detail::superblock_corruption const &d) {
out_ << "superblock is corrupt" << end_message(); out_ << "superblock is corrupt" << end_message();
{ {
auto _ = out_.push(); nested_output::nest _ = out_.push();
out_ << d.desc_ << end_message(); out_ << d.desc_ << end_message();
} }
err_ = combine_errors(err_, FATAL); err_ = combine_errors(err_, FATAL);
@ -195,7 +195,7 @@ namespace {
virtual void visit(device_tree_detail::missing_devices const &d) { virtual void visit(device_tree_detail::missing_devices const &d) {
out_ << "missing devices: " << d.keys_ << end_message(); out_ << "missing devices: " << d.keys_ << end_message();
{ {
auto _ = out_.push(); nested_output::nest _ = out_.push();
out_ << d.desc_ << end_message(); out_ << d.desc_ << end_message();
} }
@ -222,7 +222,7 @@ namespace {
virtual void visit(mapping_tree_detail::missing_devices const &d) { virtual void visit(mapping_tree_detail::missing_devices const &d) {
out_ << "missing all mappings for devices: " << d.keys_ << end_message(); out_ << "missing all mappings for devices: " << d.keys_ << end_message();
{ {
auto _ = out_.push(); nested_output::nest _ = out_.push();
out_ << d.desc_ << end_message(); out_ << d.desc_ << end_message();
} }
err_ = combine_errors(err_, FATAL); err_ = combine_errors(err_, FATAL);
@ -231,7 +231,7 @@ namespace {
virtual void visit(mapping_tree_detail::missing_mappings const &d) { virtual void visit(mapping_tree_detail::missing_mappings const &d) {
out_ << "thin device " << d.thin_dev_ << " is missing mappings " << d.keys_ << end_message(); out_ << "thin device " << d.thin_dev_ << " is missing mappings " << d.keys_ << end_message();
{ {
auto _ = out_.push(); nested_output::nest _ = out_.push();
out_ << d.desc_ << end_message(); out_ << d.desc_ << end_message();
} }
err_ = combine_errors(err_, FATAL); err_ = combine_errors(err_, FATAL);
@ -267,7 +267,7 @@ namespace {
out << "examining superblock" << end_message(); out << "examining superblock" << end_message();
{ {
auto _ = out.push(); nested_output::nest _ = out.push();
check_superblock(bm, sb_rep); check_superblock(bm, sb_rep);
} }
@ -280,7 +280,7 @@ namespace {
if (fs.check_device_tree) { if (fs.check_device_tree) {
out << "examining devices tree" << end_message(); out << "examining devices tree" << end_message();
{ {
auto _ = out.push(); nested_output::nest _ = out.push();
device_tree dtree(tm, sb.device_details_root_, device_tree dtree(tm, sb.device_details_root_,
device_tree_detail::device_details_traits::ref_counter()); device_tree_detail::device_details_traits::ref_counter());
check_device_tree(dtree, dev_rep); check_device_tree(dtree, dev_rep);
@ -290,7 +290,7 @@ namespace {
if (fs.check_mapping_tree_level1 && !fs.check_mapping_tree_level2) { if (fs.check_mapping_tree_level1 && !fs.check_mapping_tree_level2) {
out << "examining top level of mapping tree" << end_message(); out << "examining top level of mapping tree" << end_message();
{ {
auto _ = out.push(); nested_output::nest _ = out.push();
dev_tree dtree(tm, sb.data_mapping_root_, dev_tree dtree(tm, sb.data_mapping_root_,
mapping_tree_detail::mtree_traits::ref_counter(tm)); mapping_tree_detail::mtree_traits::ref_counter(tm));
check_mapping_tree(dtree, mapping_rep); check_mapping_tree(dtree, mapping_rep);
@ -299,7 +299,7 @@ namespace {
} else if (fs.check_mapping_tree_level2) { } else if (fs.check_mapping_tree_level2) {
out << "examining mapping tree" << end_message(); out << "examining mapping tree" << end_message();
{ {
auto _ = out.push(); nested_output::nest _ = out.push();
mapping_tree mtree(tm, sb.data_mapping_root_, mapping_tree mtree(tm, sb.data_mapping_root_,
mapping_tree_detail::block_traits::ref_counter(tm->get_sm())); mapping_tree_detail::block_traits::ref_counter(tm->get_sm()));
check_mapping_tree(mtree, mapping_rep); check_mapping_tree(mtree, mapping_rep);

View File

@ -50,7 +50,9 @@ namespace {
}; };
void display_rmap(ostream &out, vector<rmap_region> const &rmap) { void display_rmap(ostream &out, vector<rmap_region> const &rmap) {
for (rmap_region const &r : rmap) { vector<rmap_region>::const_iterator it;
for (it = rmap.begin(); it != rmap.end(); ++it) {
rmap_region const &r = *it;
out << "data " << r.data_begin out << "data " << r.data_begin
<< ".." << r.data_end << ".." << r.data_end
<< " -> thin(" << r.thin_dev << " -> thin(" << r.thin_dev
@ -66,8 +68,9 @@ namespace {
rmap_visitor rv; rmap_visitor rv;
try { try {
for (region const &r : regions) vector<region>::const_iterator it;
rv.add_data_region(r); for (it = regions.begin(); it != regions.end(); ++it)
rv.add_data_region(*it);
block_manager<>::ptr bm = open_bm(path); block_manager<>::ptr bm = open_bm(path);
transaction_manager::ptr tm = open_tm(bm); transaction_manager::ptr tm = open_tm(bm);

View File

@ -82,13 +82,14 @@ namespace {
<< ", path ["; << ", path [";
bool first = true; bool first = true;
for (auto k : ni.path) { btree_detail::btree_path::const_iterator it;
for (it = ni.path.begin(); it != ni.path.end(); ++it) {
if (first) if (first)
first = false; first = false;
else else
out << ", "; out << ", ";
out << k; out << *it;
} }
out << "], b " << ni.b out << "], b " << ni.b
@ -121,8 +122,9 @@ namespace {
unsigned get_nr_nodes(Predicate const &pred) const { unsigned get_nr_nodes(Predicate const &pred) const {
unsigned nr = 0; unsigned nr = 0;
for (auto n : nodes_) node_array::const_iterator it;
if (pred(n)) for (it = nodes_.begin(); it != nodes_.end(); ++it)
if (pred(*it))
nr++; nr++;
return nr; return nr;
@ -132,8 +134,9 @@ namespace {
node_info get_node(unsigned target, Predicate const &pred) const { node_info get_node(unsigned target, Predicate const &pred) const {
unsigned i = 0; unsigned i = 0;
for (auto n : nodes_) { node_array::const_iterator it;
if (pred(n)) { for (it = nodes_.begin(); it != nodes_.end(); ++it) {
if (pred(*it)) {
if (!target) if (!target)
break; break;
else else
@ -163,13 +166,14 @@ namespace {
node_array v; node_array v;
for (auto n : nodes_) { node_array::const_iterator it;
for (it = nodes_.begin(); it != nodes_.end(); ++it) {
if (!target) if (!target)
break; break;
if (pred(n)) { if (pred(*it)) {
if (target <= count) if (target <= count)
v.push_back(n); v.push_back(*it);
target--; target--;
} }
@ -525,8 +529,9 @@ TEST_F(BTreeDamageVisitorTests, populated_tree_with_a_sequence_of_damaged_leaf_n
unsigned const COUNT = 5; unsigned const COUNT = 5;
node_array nodes = layout_->get_random_nodes(COUNT, is_leaf); node_array nodes = layout_->get_random_nodes(COUNT, is_leaf);
for (auto n : nodes) node_array::const_iterator it;
trash_block(n.b); for (it = nodes.begin(); it != nodes.end(); ++it)
trash_block(it->b);
block_address begin = *nodes[0].keys.begin_; block_address begin = *nodes[0].keys.begin_;
block_address end = *nodes[COUNT - 1].keys.end_; block_address end = *nodes[COUNT - 1].keys.end_;
@ -627,15 +632,17 @@ TEST_F(BTreeDamageVisitor2Tests, populated_tree_with_no_damage)
run(); run();
} }
namespace {
bool leaf1(node_info const &n) {
return (n.leaf && n.path.size() == 1 && n.path[0] == 1);
}
}
TEST_F(BTreeDamageVisitor2Tests, damaged_leaf) TEST_F(BTreeDamageVisitor2Tests, damaged_leaf)
{ {
insert_values(10, 1000); insert_values(10, 1000);
tree_complete(); tree_complete();
auto leaf1 = [] (node_info const &n) {
return (n.leaf && n.path.size() == 1 && n.path[0] == 1);
};
node_info n = layout_->random_node(leaf1); node_info n = layout_->random_node(leaf1);
trash_block(n.b); trash_block(n.b);

View File

@ -19,6 +19,8 @@
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "persistent-data/cache.h" #include "persistent-data/cache.h"
#include <boost/shared_ptr.hpp>
using namespace boost; using namespace boost;
using namespace base; using namespace base;
using namespace std; using namespace std;
@ -53,7 +55,7 @@ namespace {
struct SharedThingTraits { struct SharedThingTraits {
typedef unsigned key_type; typedef unsigned key_type;
typedef std::shared_ptr<Thing> value_type; typedef boost::shared_ptr<Thing> value_type;
static key_type get_key(value_type const &p) { static key_type get_key(value_type const &p) {
return p->key_; return p->key_;

View File

@ -119,7 +119,7 @@ TEST(RegularSpanItTests, regular_span_iterator)
TEST_F(SpanItTests, sub_it_with_no_removed_blocks) TEST_F(SpanItTests, sub_it_with_no_removed_blocks)
{ {
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 47)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }
@ -128,7 +128,7 @@ TEST_F(SpanItTests, sub_it_with_removed_first_block)
{ {
forbidden.add(23); forbidden.add(23);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(24, 47)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(24, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }
@ -138,7 +138,7 @@ TEST_F(SpanItTests, sub_it_with_removed_run_overlapping_front_of_first_block)
for (block_address i = 19; i < 26; i++) for (block_address i = 19; i < 26; i++)
forbidden.add(i); forbidden.add(i);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(26, 47)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(26, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }
@ -147,7 +147,7 @@ TEST_F(SpanItTests, sub_it_with_removed_mid_block)
{ {
forbidden.add(40); forbidden.add(40);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 40)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 40))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(41, 47)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(41, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
@ -158,7 +158,7 @@ TEST_F(SpanItTests, sub_it_with_removed_run_mid_block)
for (block_address i = 26; i < 36; i++) for (block_address i = 26; i < 36; i++)
forbidden.add(i); forbidden.add(i);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(36, 47)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(36, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
@ -168,7 +168,7 @@ TEST_F(SpanItTests, sub_it_with_removed_end_block)
{ {
forbidden.add(46); forbidden.add(46);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 46)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 46))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }
@ -178,7 +178,7 @@ TEST_F(SpanItTests, sub_it_with_removed_run_end_block)
for (block_address i = 26; i < 50; i++) for (block_address i = 26; i < 50; i++)
forbidden.add(i); forbidden.add(i);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }
@ -188,7 +188,7 @@ TEST_F(SpanItTests, sub_it_with_removed_run_overlapping_2_blocks)
for (block_address i = 26; i < 70; i++) for (block_address i = 26; i < 70; i++)
forbidden.add(i); forbidden.add(i);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 26))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(70, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(70, 103))));
} }
@ -200,7 +200,7 @@ TEST_F(SpanItTests, sub_it_with_removed_intermediate_blocks)
forbidden.add(57); forbidden.add(57);
forbidden.add(58); forbidden.add(58);
auto it = run(); subtracting_span_iterator it = run();
ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 47)))); ASSERT_THAT(it.first(), Eq(maybe_span(span(23, 47))));
ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103)))); ASSERT_THAT(it.next(), Eq(maybe_span(span(59, 103))));
} }