From 82324d1d27e16b202943e05627b4af3b8f1fa421 Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 24 May 2013 14:01:03 +0100 Subject: [PATCH] [thin_rmap] rmap_visitor now sorts the rmap into ascending data_block order. --- thin-provisioning/rmap_visitor.cc | 7 +++++++ unit-tests/rmap_visitor_t.cc | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/thin-provisioning/rmap_visitor.cc b/thin-provisioning/rmap_visitor.cc index d0914e1..5df2229 100644 --- a/thin-provisioning/rmap_visitor.cc +++ b/thin-provisioning/rmap_visitor.cc @@ -1,5 +1,6 @@ #include "thin-provisioning/rmap_visitor.h" +#include #include using namespace thin_provisioning; @@ -33,6 +34,12 @@ rmap_visitor::complete() { if (current_rmap_) 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); } vector const & diff --git a/unit-tests/rmap_visitor_t.cc b/unit-tests/rmap_visitor_t.cc index 6f78e6a..67196cb 100644 --- a/unit-tests/rmap_visitor_t.cc +++ b/unit-tests/rmap_visitor_t.cc @@ -38,6 +38,14 @@ namespace { visit(thin_dev, b, thin_dev * blocks_per_thin + b); } + void reverse_linear_thins(unsigned nr_thins, unsigned blocks_per_thin) { + for (uint32_t thin_dev = 0; thin_dev < nr_thins; thin_dev++) + for (block_address b = 0; b < blocks_per_thin; b++) { + block_address base = (nr_thins - thin_dev - 1) * blocks_per_thin; + visit(thin_dev, b, base + b); + } + } + void check_rmap_size(unsigned expected) { ASSERT_THAT(rmap_v_.get_rmap().size(), Eq(expected)); } @@ -153,4 +161,19 @@ TEST_F(RMapVisitorTests, overlapping_regions) check_rmap_at(1, 100, 125, 1, 0); } +TEST_F(RMapVisitorTests, rmap_is_sorted) +{ + add_data_region(75, 125); + add_data_region(350, 450); + reverse_linear_thins(10, 100); + + run(); + + check_rmap_size(4); + check_rmap_at(0, 75, 100, 9, 75); + check_rmap_at(1, 100, 125, 8, 0); + check_rmap_at(2, 350, 400, 6, 50); + check_rmap_at(3, 400, 450, 5, 0); +} + //----------------------------------------------------------------