Merge branch 'master' of github.com:jthornber/thin-provisioning-tools
This commit is contained in:
@@ -18,13 +18,14 @@
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "base/error_string.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <stdexcept>
|
||||
@@ -44,11 +45,8 @@ namespace {
|
||||
// FIXME: introduce a new exception for this, or at least lift this
|
||||
// to exception.h
|
||||
void syscall_failed(char const *call) {
|
||||
char buffer[128];
|
||||
char *msg = strerror_r(errno, buffer, sizeof(buffer));
|
||||
|
||||
ostringstream out;
|
||||
out << "syscall '" << call << "' failed: " << msg;
|
||||
out << "syscall '" << call << "' failed: " << base::error_string(errno);;
|
||||
throw runtime_error(out.str());
|
||||
}
|
||||
|
||||
|
@@ -286,23 +286,8 @@ namespace persistent_data {
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------
|
||||
|
||||
struct ablock_counter {
|
||||
ablock_counter(block_counter &bc)
|
||||
: bc_(bc) {
|
||||
}
|
||||
|
||||
void visit(btree_detail::node_location const &loc, block_address b) {
|
||||
bc_.inc(b);
|
||||
}
|
||||
|
||||
private:
|
||||
block_counter &bc_;
|
||||
};
|
||||
|
||||
void count_metadata_blocks(block_counter &bc) const {
|
||||
ablock_counter vc(bc);
|
||||
block_address_counter vc(bc);
|
||||
count_btree_blocks(block_tree_, bc, vc);
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@ using namespace persistent_data;
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
static const uint64_t m1 = 0x9e37fffffffc0001UL;
|
||||
static const uint64_t m1 = 0x9e37fffffffc0001ULL;
|
||||
static const unsigned bits = 18;
|
||||
|
||||
static uint32_t hash1(block_address const &b) {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#ifndef PERSISTENT_DATA_DATA_STRUCTURES_BTREE_COUNTER_H
|
||||
#define PERSISTENT_DATA_DATA_STRUCTURES_BTREE_COUNTER_H
|
||||
|
||||
#include "persistent-data/data-structures/btree.h"
|
||||
#include "persistent-data/block_counter.h"
|
||||
|
||||
//----------------------------------------------------------------
|
||||
@@ -65,6 +66,19 @@ namespace persistent_data {
|
||||
}
|
||||
};
|
||||
|
||||
struct block_address_counter {
|
||||
block_address_counter(block_counter &bc)
|
||||
: bc_(bc) {
|
||||
}
|
||||
|
||||
void visit(btree_detail::node_location const &loc, block_address b) {
|
||||
bc_.inc(b);
|
||||
}
|
||||
|
||||
private:
|
||||
block_counter &bc_;
|
||||
};
|
||||
|
||||
// Counts how many times each metadata block is referenced in the
|
||||
// tree. Blocks already referenced in the block counter are not
|
||||
// walked. This walk should only be done once you're sure the tree
|
||||
|
@@ -89,6 +89,10 @@ namespace {
|
||||
sm_->iterate(it);
|
||||
}
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const {
|
||||
sm_->count_metadata(bc);
|
||||
}
|
||||
|
||||
virtual size_t root_size() const {
|
||||
return sm_->root_size();
|
||||
}
|
||||
|
@@ -105,6 +105,9 @@ namespace persistent_data {
|
||||
throw std::runtime_error("'extend' not implemented");
|
||||
}
|
||||
|
||||
void count_metadata(block_counter &bc) const {
|
||||
}
|
||||
|
||||
// FIXME: meaningless, but this class is only used for testing
|
||||
size_t root_size() const {
|
||||
return 0;
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "persistent-data/space-maps/careful_alloc.h"
|
||||
|
||||
#include "persistent-data/data-structures/btree_damage_visitor.h"
|
||||
#include "persistent-data/data-structures/btree_counter.h"
|
||||
#include "persistent-data/checksum.h"
|
||||
#include "persistent-data/math_utils.h"
|
||||
#include "persistent-data/transaction_manager.h"
|
||||
@@ -112,7 +113,7 @@ namespace {
|
||||
ref_t b1 = test_bit_le(bits, b * 2);
|
||||
ref_t b2 = test_bit_le(bits, b * 2 + 1);
|
||||
ref_t result = b2 ? 1 : 0;
|
||||
result |= b1 ? 0b10 : 0;
|
||||
result |= b1 ? 2 : 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ namespace {
|
||||
ref_t b1 = test_bit_le(bits, b * 2);
|
||||
ref_t b2 = test_bit_le(bits, b * 2 + 1);
|
||||
ref_t result = b2 ? 1 : 0;
|
||||
result |= b1 ? 0b10 : 0;
|
||||
result |= b1 ? 2 : 0;
|
||||
it(offset + b, result);
|
||||
}
|
||||
}
|
||||
@@ -223,6 +224,7 @@ namespace {
|
||||
public:
|
||||
typedef boost::shared_ptr<index_store> ptr;
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const = 0;
|
||||
virtual void resize(block_address nr_indexes) = 0;
|
||||
virtual index_entry find_ie(block_address b) const = 0;
|
||||
virtual void save_ie(block_address b, struct index_entry ie) = 0;
|
||||
@@ -406,6 +408,13 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const {
|
||||
indexes_->count_metadata(bc);
|
||||
|
||||
noop_value_counter<uint32_t> vc;
|
||||
count_btree_blocks(ref_counts_, bc, vc);
|
||||
}
|
||||
|
||||
virtual size_t root_size() const {
|
||||
return sizeof(sm_root_disk);
|
||||
}
|
||||
@@ -555,6 +564,29 @@ namespace {
|
||||
bitmaps_(tm, root, index_entry_traits::ref_counter()) {
|
||||
}
|
||||
|
||||
//--------------------------------
|
||||
|
||||
struct index_entry_counter {
|
||||
index_entry_counter(block_counter &bc)
|
||||
: bc_(bc) {
|
||||
}
|
||||
|
||||
void visit(btree_detail::node_location const &loc, index_entry const &ie) {
|
||||
if (ie.blocknr_ != 0)
|
||||
bc_.inc(ie.blocknr_);
|
||||
}
|
||||
|
||||
private:
|
||||
block_counter &bc_;
|
||||
};
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const {
|
||||
index_entry_counter vc(bc);
|
||||
count_btree_blocks(bitmaps_, bc, vc);
|
||||
}
|
||||
|
||||
//--------------------------------
|
||||
|
||||
virtual void resize(block_address nr_entries) {
|
||||
// No op
|
||||
}
|
||||
@@ -613,6 +645,17 @@ namespace {
|
||||
load_ies();
|
||||
}
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const {
|
||||
bc.inc(bitmap_root_);
|
||||
|
||||
for (unsigned i = 0; i < entries_.size(); i++) {
|
||||
block_address b = entries_[i].blocknr_;
|
||||
|
||||
if (b != 0)
|
||||
bc.inc(b);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void resize(block_address nr_indexes) {
|
||||
entries_.resize(nr_indexes);
|
||||
}
|
||||
|
@@ -178,6 +178,10 @@ namespace {
|
||||
sm_->iterate(it);
|
||||
}
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const {
|
||||
sm_->count_metadata(bc);
|
||||
}
|
||||
|
||||
virtual size_t root_size() const {
|
||||
cant_recurse("root_size");
|
||||
recursing_const_lock lock(*this);
|
||||
|
@@ -119,6 +119,7 @@ namespace persistent_data {
|
||||
|
||||
namespace space_map_detail {
|
||||
class damage {
|
||||
public:
|
||||
virtual ~damage() {}
|
||||
};
|
||||
|
||||
@@ -141,6 +142,7 @@ namespace persistent_data {
|
||||
public:
|
||||
typedef boost::shared_ptr<persistent_space_map> ptr;
|
||||
|
||||
virtual void count_metadata(block_counter &bc) const = 0;
|
||||
virtual size_t root_size() const = 0;
|
||||
virtual void copy_root(void *dest, size_t len) const = 0;
|
||||
};
|
||||
|
Reference in New Issue
Block a user