[block_manager] Hard code block size to 4k.
We're never going to use anything other than 4k, and by hard coding it we avoid making block_manager a template.
This commit is contained in:
parent
3e5de399a7
commit
e801cc607b
@ -76,6 +76,7 @@ SOURCE=\
|
|||||||
era/writeset_tree.cc \
|
era/writeset_tree.cc \
|
||||||
era/xml_format.cc \
|
era/xml_format.cc \
|
||||||
main.cc \
|
main.cc \
|
||||||
|
persistent-data/block.cc \
|
||||||
persistent-data/checksum.cc \
|
persistent-data/checksum.cc \
|
||||||
persistent-data/data-structures/bitset.cc \
|
persistent-data/data-structures/bitset.cc \
|
||||||
persistent-data/data-structures/bloom_filter.cc \
|
persistent-data/data-structures/bloom_filter.cc \
|
||||||
|
@ -19,10 +19,6 @@ using namespace file_utils;
|
|||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
// FIXME: get from linux headers
|
|
||||||
#define SECTOR_SHIFT 9
|
|
||||||
#define PAGE_SIZE 4096
|
|
||||||
|
|
||||||
#define MIN_BLOCKS 16
|
#define MIN_BLOCKS 16
|
||||||
#define WRITEBACK_LOW_THRESHOLD_PERCENT 33
|
#define WRITEBACK_LOW_THRESHOLD_PERCENT 33
|
||||||
#define WRITEBACK_HIGH_THRESHOLD_PERCENT 66
|
#define WRITEBACK_HIGH_THRESHOLD_PERCENT 66
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "base/container_of.h"
|
#include "base/container_of.h"
|
||||||
#include "base/file_utils.h"
|
#include "base/file_utils.h"
|
||||||
|
#include "block-cache/io_engine.h"
|
||||||
|
|
||||||
#include <boost/intrusive/list.hpp>
|
#include <boost/intrusive/list.hpp>
|
||||||
#include <boost/intrusive/set.hpp>
|
#include <boost/intrusive/set.hpp>
|
||||||
|
@ -204,7 +204,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clear_needs_check(string const &path) {
|
void clear_needs_check(string const &path) {
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_WRITE);
|
||||||
|
|
||||||
superblock sb = read_superblock(bm);
|
superblock sb = read_superblock(bm);
|
||||||
sb.flags.clear_flag(superblock_flags::NEEDS_CHECK);
|
sb.flags.clear_flag(superblock_flags::NEEDS_CHECK);
|
||||||
@ -223,7 +223,7 @@ namespace {
|
|||||||
return FATAL;
|
return FATAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_ONLY);
|
||||||
|
|
||||||
superblock_reporter sb_rep(out);
|
superblock_reporter sb_rep(out);
|
||||||
mapping_reporter mapping_rep(out);
|
mapping_reporter mapping_rep(out);
|
||||||
|
@ -35,7 +35,7 @@ namespace {
|
|||||||
|
|
||||||
int dump(string const &dev, string const &output, flags const &fs) {
|
int dump(string const &dev, string const &output, flags const &fs) {
|
||||||
try {
|
try {
|
||||||
block_manager<>::ptr bm = open_bm(dev, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(dev, block_manager::READ_ONLY);
|
||||||
metadata::ptr md(new metadata(bm));
|
metadata::ptr md(new metadata(bm));
|
||||||
|
|
||||||
if (want_stdout(output)) {
|
if (want_stdout(output)) {
|
||||||
|
@ -19,12 +19,12 @@ using namespace caching;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
metadata::ptr open_metadata_for_read(string const &path) {
|
metadata::ptr open_metadata_for_read(string const &path) {
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_ONLY);
|
||||||
return metadata::ptr(new metadata(bm));
|
return metadata::ptr(new metadata(bm));
|
||||||
}
|
}
|
||||||
|
|
||||||
emitter::ptr output_emitter(string const &path) {
|
emitter::ptr output_emitter(string const &path) {
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_WRITE);
|
||||||
metadata::ptr md(new metadata(bm, metadata::CREATE));
|
metadata::ptr md(new metadata(bm, metadata::CREATE));
|
||||||
return create_restore_emitter(md, true);
|
return create_restore_emitter(md, true);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace {
|
|||||||
bool metadata_touched = false;
|
bool metadata_touched = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
block_manager<>::ptr bm = open_bm(*fs.output, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(*fs.output, block_manager::READ_WRITE);
|
||||||
|
|
||||||
check_file_exists(*fs.input);
|
check_file_exists(*fs.input);
|
||||||
ifstream in(fs.input->c_str(), ifstream::in);
|
ifstream in(fs.input->c_str(), ifstream::in);
|
||||||
|
@ -296,7 +296,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int writeback_(flags const &f) {
|
int writeback_(flags const &f) {
|
||||||
block_manager<>::ptr bm = open_bm(*f.metadata_dev, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(*f.metadata_dev, block_manager::READ_WRITE);
|
||||||
metadata md(bm);
|
metadata md(bm);
|
||||||
|
|
||||||
// FIXME: we're going to have to copy runs to get the through put with small block sizes
|
// FIXME: we're going to have to copy runs to get the through put with small block sizes
|
||||||
|
@ -10,7 +10,7 @@ namespace pd = persistent_data;
|
|||||||
namespace {
|
namespace {
|
||||||
// FIXME: duplication
|
// FIXME: duplication
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
open_tm(block_manager<>::ptr bm) {
|
open_tm(block_manager::ptr bm) {
|
||||||
auto nr_blocks = bm->get_nr_blocks();
|
auto nr_blocks = bm->get_nr_blocks();
|
||||||
if (!nr_blocks)
|
if (!nr_blocks)
|
||||||
throw runtime_error("Metadata is not large enough for superblock.");
|
throw runtime_error("Metadata is not large enough for superblock.");
|
||||||
@ -33,7 +33,7 @@ namespace {
|
|||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, open_type ot, unsigned metadata_version)
|
metadata::metadata(block_manager::ptr bm, open_type ot, unsigned metadata_version)
|
||||||
{
|
{
|
||||||
switch (ot) {
|
switch (ot) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
@ -45,7 +45,7 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot, unsigned metadata_vers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm)
|
metadata::metadata(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
open_metadata(bm);
|
open_metadata(bm);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ metadata::setup_hint_array(size_t width)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
metadata::create_metadata(block_manager<>::ptr bm, unsigned metadata_version)
|
metadata::create_metadata(block_manager::ptr bm, unsigned metadata_version)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm);
|
tm_ = open_tm(bm);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ metadata::create_metadata(block_manager<>::ptr bm, unsigned metadata_version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
metadata::open_metadata(block_manager<>::ptr bm)
|
metadata::open_metadata(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm);
|
tm_ = open_tm(bm);
|
||||||
sb_ = read_superblock(tm_->get_bm());
|
sb_ = read_superblock(tm_->get_bm());
|
||||||
|
@ -22,12 +22,12 @@ namespace caching {
|
|||||||
CREATE
|
CREATE
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
typedef boost::shared_ptr<metadata> ptr;
|
typedef boost::shared_ptr<metadata> ptr;
|
||||||
|
|
||||||
metadata(block_manager<>::ptr bm, open_type ot, unsigned metadata_version = 2); // Create only
|
metadata(block_manager::ptr bm, open_type ot, unsigned metadata_version = 2); // Create only
|
||||||
metadata(block_manager<>::ptr bm);
|
metadata(block_manager::ptr bm);
|
||||||
|
|
||||||
void commit(bool clean_shutdown = true);
|
void commit(bool clean_shutdown = true);
|
||||||
void setup_hint_array(size_t width);
|
void setup_hint_array(size_t width);
|
||||||
@ -45,8 +45,8 @@ namespace caching {
|
|||||||
private:
|
private:
|
||||||
void init_superblock();
|
void init_superblock();
|
||||||
|
|
||||||
void create_metadata(block_manager<>::ptr bm, unsigned metadata_version);
|
void create_metadata(block_manager::ptr bm, unsigned metadata_version);
|
||||||
void open_metadata(block_manager<>::ptr bm);
|
void open_metadata(block_manager::ptr bm);
|
||||||
|
|
||||||
void commit_space_map();
|
void commit_space_map();
|
||||||
void commit_mappings();
|
void commit_mappings();
|
||||||
|
@ -325,11 +325,11 @@ namespace validator {
|
|||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
superblock
|
superblock
|
||||||
caching::read_superblock(block_manager<>::ptr bm, block_address location)
|
caching::read_superblock(block_manager::ptr bm, block_address location)
|
||||||
{
|
{
|
||||||
using namespace validator;
|
using namespace validator;
|
||||||
superblock sb;
|
superblock sb;
|
||||||
block_manager<>::read_ref r = bm->read_lock(location, mk_v());
|
block_manager::read_ref r = bm->read_lock(location, mk_v());
|
||||||
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);
|
||||||
|
|
||||||
@ -337,10 +337,10 @@ caching::read_superblock(block_manager<>::ptr bm, block_address location)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
caching::write_superblock(block_manager<>::ptr bm, superblock const &sb, block_address location)
|
caching::write_superblock(block_manager::ptr bm, superblock const &sb, block_address location)
|
||||||
{
|
{
|
||||||
using namespace validator;
|
using namespace validator;
|
||||||
block_manager<>::write_ref w = bm->superblock_zero(location, mk_v());
|
block_manager::write_ref w = bm->superblock_zero(location, mk_v());
|
||||||
superblock_traits::pack(sb, *reinterpret_cast<superblock_disk *>(w.data()));
|
superblock_traits::pack(sb, *reinterpret_cast<superblock_disk *>(w.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +415,7 @@ caching::check_superblock(superblock const &sb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
caching::check_superblock(persistent_data::block_manager<>::ptr bm,
|
caching::check_superblock(persistent_data::block_manager::ptr bm,
|
||||||
block_address nr_metadata_blocks,
|
block_address nr_metadata_blocks,
|
||||||
damage_visitor &visitor)
|
damage_visitor &visitor)
|
||||||
{
|
{
|
||||||
|
@ -137,10 +137,10 @@ namespace caching {
|
|||||||
|
|
||||||
bcache::validator::ptr superblock_validator();
|
bcache::validator::ptr superblock_validator();
|
||||||
|
|
||||||
superblock read_superblock(persistent_data::block_manager<>::ptr bm,
|
superblock read_superblock(persistent_data::block_manager::ptr bm,
|
||||||
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
void write_superblock(persistent_data::block_manager<>::ptr bm,
|
void write_superblock(persistent_data::block_manager::ptr bm,
|
||||||
superblock const &sb,
|
superblock const &sb,
|
||||||
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ namespace caching {
|
|||||||
persistent_data::block_address nr_metadata_blocks,
|
persistent_data::block_address nr_metadata_blocks,
|
||||||
superblock_damage::damage_visitor &visitor);
|
superblock_damage::damage_visitor &visitor);
|
||||||
|
|
||||||
void check_superblock(persistent_data::block_manager<>::ptr bm,
|
void check_superblock(persistent_data::block_manager::ptr bm,
|
||||||
persistent_data::block_address nr_metadata_blocks,
|
persistent_data::block_address nr_metadata_blocks,
|
||||||
superblock_damage::damage_visitor &visitor);
|
superblock_damage::damage_visitor &visitor);
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ namespace {
|
|||||||
return FATAL;
|
return FATAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_ONLY);
|
||||||
|
|
||||||
superblock_reporter sb_rep(out);
|
superblock_reporter sb_rep(out);
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ namespace {
|
|||||||
|
|
||||||
int dump(string const &dev, string const &output, flags const &fs) {
|
int dump(string const &dev, string const &output, flags const &fs) {
|
||||||
try {
|
try {
|
||||||
block_manager<>::ptr bm = open_bm(dev, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(dev, block_manager::READ_ONLY);
|
||||||
metadata::ptr md(new metadata(bm, metadata::OPEN));
|
metadata::ptr md(new metadata(bm, metadata::OPEN));
|
||||||
|
|
||||||
if (want_stdout(output)) {
|
if (want_stdout(output)) {
|
||||||
|
@ -152,7 +152,7 @@ namespace {
|
|||||||
int invalidate(string const &dev, string const &output, flags const &fs) {
|
int invalidate(string const &dev, string const &output, flags const &fs) {
|
||||||
try {
|
try {
|
||||||
set<uint32_t> blocks;
|
set<uint32_t> blocks;
|
||||||
block_manager<>::ptr bm = open_bm(dev, block_manager<>::READ_ONLY, !fs.metadata_snapshot_);
|
block_manager::ptr bm = open_bm(dev, block_manager::READ_ONLY, !fs.metadata_snapshot_);
|
||||||
|
|
||||||
if (fs.metadata_snapshot_) {
|
if (fs.metadata_snapshot_) {
|
||||||
superblock sb = read_superblock(bm);
|
superblock sb = read_superblock(bm);
|
||||||
|
@ -36,7 +36,7 @@ namespace {
|
|||||||
int restore(flags const &fs, bool quiet) {
|
int restore(flags const &fs, bool quiet) {
|
||||||
bool metadata_touched = false;
|
bool metadata_touched = false;
|
||||||
try {
|
try {
|
||||||
block_manager<>::ptr bm = open_bm(*fs.output, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(*fs.output, block_manager::READ_WRITE);
|
||||||
file_utils::check_file_exists(*fs.output);
|
file_utils::check_file_exists(*fs.output);
|
||||||
metadata_touched = true;
|
metadata_touched = true;
|
||||||
metadata::ptr md(new metadata(bm, metadata::CREATE));
|
metadata::ptr md(new metadata(bm, metadata::CREATE));
|
||||||
|
@ -8,7 +8,7 @@ using namespace era;
|
|||||||
namespace {
|
namespace {
|
||||||
// FIXME: duplication
|
// FIXME: duplication
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
open_tm(block_manager<>::ptr bm) {
|
open_tm(block_manager::ptr bm) {
|
||||||
auto nr_blocks = bm->get_nr_blocks();
|
auto nr_blocks = bm->get_nr_blocks();
|
||||||
if (!nr_blocks)
|
if (!nr_blocks)
|
||||||
throw runtime_error("Metadata is not large enough for superblock.");
|
throw runtime_error("Metadata is not large enough for superblock.");
|
||||||
@ -29,7 +29,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, open_type ot)
|
metadata::metadata(block_manager::ptr bm, open_type ot)
|
||||||
{
|
{
|
||||||
switch (ot) {
|
switch (ot) {
|
||||||
case CREATE:
|
case CREATE:
|
||||||
@ -42,13 +42,13 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, block_address metadata_snap)
|
metadata::metadata(block_manager::ptr bm, block_address metadata_snap)
|
||||||
{
|
{
|
||||||
open_metadata(bm);
|
open_metadata(bm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
metadata::create_metadata(block_manager<>::ptr bm)
|
metadata::create_metadata(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm);
|
tm_ = open_tm(bm);
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ metadata::create_metadata(block_manager<>::ptr bm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
metadata::open_metadata(block_manager<>::ptr bm, block_address loc)
|
metadata::open_metadata(block_manager::ptr bm, block_address loc)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm);
|
tm_ = open_tm(bm);
|
||||||
sb_ = read_superblock(tm_->get_bm(), loc);
|
sb_ = read_superblock(tm_->get_bm(), loc);
|
||||||
|
@ -23,12 +23,12 @@ namespace era {
|
|||||||
OPEN
|
OPEN
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
typedef boost::shared_ptr<metadata> ptr;
|
typedef boost::shared_ptr<metadata> ptr;
|
||||||
|
|
||||||
metadata(block_manager<>::ptr bm, open_type ot);
|
metadata(block_manager::ptr bm, open_type ot);
|
||||||
metadata(block_manager<>::ptr bm, block_address metadata_snap);
|
metadata(block_manager::ptr bm, block_address metadata_snap);
|
||||||
void commit();
|
void commit();
|
||||||
|
|
||||||
typedef persistent_data::transaction_manager tm;
|
typedef persistent_data::transaction_manager tm;
|
||||||
@ -39,8 +39,8 @@ namespace era {
|
|||||||
era_array::ptr era_array_;
|
era_array::ptr era_array_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void create_metadata(block_manager<>::ptr bm);
|
void create_metadata(block_manager::ptr bm);
|
||||||
void open_metadata(block_manager<>::ptr bm,
|
void open_metadata(block_manager::ptr bm,
|
||||||
block_address loc = SUPERBLOCK_LOCATION);
|
block_address loc = SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
void commit_space_map();
|
void commit_space_map();
|
||||||
|
@ -245,10 +245,10 @@ namespace era_validator {
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
superblock
|
superblock
|
||||||
era::read_superblock(block_manager<>::ptr bm, block_address location)
|
era::read_superblock(block_manager::ptr bm, block_address location)
|
||||||
{
|
{
|
||||||
superblock sb;
|
superblock sb;
|
||||||
block_manager<>::read_ref r = bm->read_lock(location, era_validator::mk_v());
|
block_manager::read_ref r = bm->read_lock(location, era_validator::mk_v());
|
||||||
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);
|
||||||
|
|
||||||
@ -256,9 +256,9 @@ era::read_superblock(block_manager<>::ptr bm, block_address location)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
era::write_superblock(block_manager<>::ptr bm, superblock const &sb, block_address location)
|
era::write_superblock(block_manager::ptr bm, superblock const &sb, block_address location)
|
||||||
{
|
{
|
||||||
block_manager<>::write_ref w = bm->superblock_zero(location, era_validator::mk_v());
|
block_manager::write_ref w = bm->superblock_zero(location, era_validator::mk_v());
|
||||||
superblock_traits::pack(sb, *reinterpret_cast<superblock_disk *>(w.data()));
|
superblock_traits::pack(sb, *reinterpret_cast<superblock_disk *>(w.data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ era::check_superblock(superblock const &sb,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
era::check_superblock(persistent_data::block_manager<>::ptr bm,
|
era::check_superblock(persistent_data::block_manager::ptr bm,
|
||||||
block_address nr_metadata_blocks,
|
block_address nr_metadata_blocks,
|
||||||
damage_visitor &visitor)
|
damage_visitor &visitor)
|
||||||
{
|
{
|
||||||
|
@ -114,10 +114,10 @@ namespace era {
|
|||||||
|
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
superblock read_superblock(persistent_data::block_manager<>::ptr bm,
|
superblock read_superblock(persistent_data::block_manager::ptr bm,
|
||||||
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
void write_superblock(persistent_data::block_manager<>::ptr bm,
|
void write_superblock(persistent_data::block_manager::ptr bm,
|
||||||
superblock const &sb,
|
superblock const &sb,
|
||||||
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
persistent_data::block_address location = SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ namespace era {
|
|||||||
persistent_data::block_address nr_metadata_blocks,
|
persistent_data::block_address nr_metadata_blocks,
|
||||||
superblock_damage::damage_visitor &visitor);
|
superblock_damage::damage_visitor &visitor);
|
||||||
|
|
||||||
void check_superblock(persistent_data::block_manager<>::ptr bm,
|
void check_superblock(persistent_data::block_manager::ptr bm,
|
||||||
persistent_data::block_address nr_metadata_blocks,
|
persistent_data::block_address nr_metadata_blocks,
|
||||||
superblock_damage::damage_visitor &visitor);
|
superblock_damage::damage_visitor &visitor);
|
||||||
}
|
}
|
||||||
|
203
persistent-data/block.cc
Normal file
203
persistent-data/block.cc
Normal file
@ -0,0 +1,203 @@
|
|||||||
|
// Copyright (C) 2011 Red Hat, Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// This file is part of the thin-provisioning-tools source.
|
||||||
|
//
|
||||||
|
// thin-provisioning-tools is free software: you can redistribute it
|
||||||
|
// and/or modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation, either version 3 of
|
||||||
|
// the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// thin-provisioning-tools is distributed in the hope that it will be
|
||||||
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||||
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with thin-provisioning-tools. If not, see
|
||||||
|
// <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "block.h"
|
||||||
|
|
||||||
|
#include "base/error_string.h"
|
||||||
|
#include "base/file_utils.h"
|
||||||
|
#include "block-cache/io_engine.h"
|
||||||
|
|
||||||
|
#include <boost/bind.hpp>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
using namespace persistent_data;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
block_manager::read_ref::read_ref(block_cache::block &b)
|
||||||
|
: b_(b)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::read_ref::read_ref(read_ref const &rhs)
|
||||||
|
: b_(rhs.b_)
|
||||||
|
{
|
||||||
|
b_.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::read_ref::~read_ref()
|
||||||
|
{
|
||||||
|
b_.put();
|
||||||
|
}
|
||||||
|
|
||||||
|
block_address
|
||||||
|
block_manager::read_ref::get_location() const
|
||||||
|
{
|
||||||
|
return b_.get_index();
|
||||||
|
}
|
||||||
|
|
||||||
|
void const *
|
||||||
|
block_manager::read_ref::data() const
|
||||||
|
{
|
||||||
|
return b_.get_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------
|
||||||
|
|
||||||
|
block_manager::write_ref::write_ref(block_cache::block &b)
|
||||||
|
: read_ref(b),
|
||||||
|
ref_count_(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref::write_ref(block_cache::block &b, unsigned &ref_count)
|
||||||
|
: read_ref(b),
|
||||||
|
ref_count_(&ref_count) {
|
||||||
|
if (*ref_count_)
|
||||||
|
throw std::runtime_error("superblock already locked");
|
||||||
|
(*ref_count_)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref::write_ref(write_ref const &rhs)
|
||||||
|
: read_ref(rhs),
|
||||||
|
ref_count_(rhs.ref_count_) {
|
||||||
|
if (ref_count_)
|
||||||
|
(*ref_count_)++;
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref::~write_ref()
|
||||||
|
{
|
||||||
|
if (ref_count_) {
|
||||||
|
if (!*ref_count_) {
|
||||||
|
std::cerr << "write_ref ref_count going below zero";
|
||||||
|
::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
(*ref_count_)--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
block_manager::write_ref::data()
|
||||||
|
{
|
||||||
|
return read_ref::b_.get_data();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
block_manager::choose_cache_size(block_address nr_blocks) const
|
||||||
|
{
|
||||||
|
uint64_t const DEFAULT_CACHE_SIZE = 1024 * 1024 * 16;
|
||||||
|
return std::min<uint64_t>(DEFAULT_CACHE_SIZE, MD_BLOCK_SIZE * nr_blocks);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::block_manager(std::string const &path,
|
||||||
|
block_address nr_blocks,
|
||||||
|
unsigned max_concurrent_blocks,
|
||||||
|
mode m,
|
||||||
|
bool excl)
|
||||||
|
: fd_(open_or_create_block_file(path, nr_blocks * MD_BLOCK_SIZE, m, excl)),
|
||||||
|
bc_(fd_, MD_BLOCK_SIZE >> SECTOR_SHIFT, nr_blocks, choose_cache_size(nr_blocks)),
|
||||||
|
superblock_ref_count_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
file_utils::file_descriptor
|
||||||
|
block_manager::open_or_create_block_file(std::string const &path, off_t file_size, mode m, bool excl)
|
||||||
|
{
|
||||||
|
switch (m) {
|
||||||
|
case READ_ONLY:
|
||||||
|
return file_utils::open_block_file(path, file_size, false, excl);
|
||||||
|
|
||||||
|
case READ_WRITE:
|
||||||
|
return file_utils::open_block_file(path, file_size, true, excl);
|
||||||
|
|
||||||
|
case CREATE:
|
||||||
|
return file_utils::create_block_file(path, file_size);
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw std::runtime_error("unsupported mode");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::read_ref
|
||||||
|
block_manager::read_lock(block_address location,
|
||||||
|
typename bcache::validator::ptr v) const
|
||||||
|
{
|
||||||
|
block_cache::block &b = bc_.get(location, 0, v);
|
||||||
|
return read_ref(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref
|
||||||
|
block_manager::write_lock(block_address location,
|
||||||
|
typename bcache::validator::ptr v)
|
||||||
|
{
|
||||||
|
block_cache::block &b = bc_.get(location, block_cache::GF_DIRTY, v);
|
||||||
|
return write_ref(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref
|
||||||
|
block_manager::write_lock_zero(block_address location,
|
||||||
|
typename bcache::validator::ptr v)
|
||||||
|
{
|
||||||
|
block_cache::block &b = bc_.get(location, block_cache::GF_ZERO, v);
|
||||||
|
return write_ref(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref
|
||||||
|
block_manager::superblock(block_address location,
|
||||||
|
typename bcache::validator::ptr v)
|
||||||
|
{
|
||||||
|
if (bc_.get_nr_locked() > 0)
|
||||||
|
throw std::runtime_error("attempt to lock superblock while other locks are still held");
|
||||||
|
|
||||||
|
block_cache::block &b = bc_.get(location, block_cache::GF_DIRTY | block_cache::GF_BARRIER, v);
|
||||||
|
return write_ref(b, superblock_ref_count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_manager::write_ref
|
||||||
|
block_manager::superblock_zero(block_address location,
|
||||||
|
typename bcache::validator::ptr v)
|
||||||
|
{
|
||||||
|
if (bc_.get_nr_locked() > 0)
|
||||||
|
throw std::runtime_error("attempt to lock superblock while other locks are still held");
|
||||||
|
|
||||||
|
block_cache::block &b = bc_.get(location, block_cache::GF_ZERO | block_cache::GF_BARRIER, v);
|
||||||
|
return write_ref(b, superblock_ref_count_);
|
||||||
|
}
|
||||||
|
|
||||||
|
block_address
|
||||||
|
block_manager::get_nr_blocks() const
|
||||||
|
{
|
||||||
|
return bc_.get_nr_blocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
block_manager::prefetch(block_address b) const
|
||||||
|
{
|
||||||
|
bc_.prefetch(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
block_manager::flush() const
|
||||||
|
{
|
||||||
|
bc_.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
@ -38,7 +38,6 @@ namespace persistent_data {
|
|||||||
|
|
||||||
uint32_t const MD_BLOCK_SIZE = 4096;
|
uint32_t const MD_BLOCK_SIZE = 4096;
|
||||||
|
|
||||||
template <uint32_t BlockSize = MD_BLOCK_SIZE>
|
|
||||||
class block_manager : private boost::noncopyable {
|
class block_manager : private boost::noncopyable {
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<block_manager> ptr;
|
typedef boost::shared_ptr<block_manager> ptr;
|
||||||
@ -57,7 +56,7 @@ namespace persistent_data {
|
|||||||
|
|
||||||
class read_ref {
|
class read_ref {
|
||||||
public:
|
public:
|
||||||
static uint32_t const BLOCK_SIZE = BlockSize;
|
static uint32_t const BLOCK_SIZE = MD_BLOCK_SIZE;
|
||||||
|
|
||||||
read_ref(block_cache::block &b);
|
read_ref(block_cache::block &b);
|
||||||
|
|
||||||
@ -149,8 +148,6 @@ namespace persistent_data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "block.tcc"
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,224 +0,0 @@
|
|||||||
// Copyright (C) 2011 Red Hat, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
// This file is part of the thin-provisioning-tools source.
|
|
||||||
//
|
|
||||||
// thin-provisioning-tools is free software: you can redistribute it
|
|
||||||
// and/or modify it under the terms of the GNU General Public License
|
|
||||||
// as published by the Free Software Foundation, either version 3 of
|
|
||||||
// the License, or (at your option) any later version.
|
|
||||||
//
|
|
||||||
// thin-provisioning-tools is distributed in the hope that it will be
|
|
||||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
||||||
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License along
|
|
||||||
// with thin-provisioning-tools. If not, see
|
|
||||||
// <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
#include "block.h"
|
|
||||||
|
|
||||||
#include "base/error_string.h"
|
|
||||||
#include "base/file_utils.h"
|
|
||||||
#include "block-cache/io_engine.h"
|
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
|
||||||
|
|
||||||
namespace persistent_data {
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::read_ref::read_ref(block_cache::block &b)
|
|
||||||
: b_(b)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::read_ref::read_ref(read_ref const &rhs)
|
|
||||||
: b_(rhs.b_)
|
|
||||||
{
|
|
||||||
b_.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::read_ref::~read_ref()
|
|
||||||
{
|
|
||||||
b_.put();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_address
|
|
||||||
block_manager<BlockSize>::read_ref::get_location() const
|
|
||||||
{
|
|
||||||
return b_.get_index();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
void const *
|
|
||||||
block_manager<BlockSize>::read_ref::data() const
|
|
||||||
{
|
|
||||||
return b_.get_data();
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::write_ref::write_ref(block_cache::block &b)
|
|
||||||
: read_ref(b),
|
|
||||||
ref_count_(NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::write_ref::write_ref(block_cache::block &b, unsigned &ref_count)
|
|
||||||
: read_ref(b),
|
|
||||||
ref_count_(&ref_count) {
|
|
||||||
if (*ref_count_)
|
|
||||||
throw std::runtime_error("superblock already locked");
|
|
||||||
(*ref_count_)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::write_ref::write_ref(write_ref const &rhs)
|
|
||||||
: read_ref(rhs),
|
|
||||||
ref_count_(rhs.ref_count_) {
|
|
||||||
if (ref_count_)
|
|
||||||
(*ref_count_)++;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::write_ref::~write_ref()
|
|
||||||
{
|
|
||||||
if (ref_count_) {
|
|
||||||
if (!*ref_count_) {
|
|
||||||
std::cerr << "write_ref ref_count going below zero";
|
|
||||||
::exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
(*ref_count_)--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
void *
|
|
||||||
block_manager<BlockSize>::write_ref::data()
|
|
||||||
{
|
|
||||||
return read_ref::b_.get_data();
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
uint64_t
|
|
||||||
block_manager<BlockSize>::choose_cache_size(block_address nr_blocks) const
|
|
||||||
{
|
|
||||||
uint64_t const DEFAULT_CACHE_SIZE = 1024 * 1024 * 16;
|
|
||||||
return std::min<uint64_t>(DEFAULT_CACHE_SIZE, BlockSize * nr_blocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_manager<BlockSize>::block_manager(std::string const &path,
|
|
||||||
block_address nr_blocks,
|
|
||||||
unsigned max_concurrent_blocks,
|
|
||||||
mode m,
|
|
||||||
bool excl)
|
|
||||||
: fd_(open_or_create_block_file(path, nr_blocks * BlockSize, m, excl)),
|
|
||||||
bc_(fd_, BlockSize >> SECTOR_SHIFT, nr_blocks, choose_cache_size(nr_blocks)),
|
|
||||||
superblock_ref_count_(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
file_utils::file_descriptor
|
|
||||||
block_manager<BlockSize>::open_or_create_block_file(std::string const &path, off_t file_size, mode m, bool excl)
|
|
||||||
{
|
|
||||||
switch (m) {
|
|
||||||
case READ_ONLY:
|
|
||||||
return file_utils::open_block_file(path, file_size, false, excl);
|
|
||||||
|
|
||||||
case READ_WRITE:
|
|
||||||
return file_utils::open_block_file(path, file_size, true, excl);
|
|
||||||
|
|
||||||
case CREATE:
|
|
||||||
return file_utils::create_block_file(path, file_size);
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw std::runtime_error("unsupported mode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
typename block_manager<BlockSize>::read_ref
|
|
||||||
block_manager<BlockSize>::read_lock(block_address location,
|
|
||||||
typename bcache::validator::ptr v) const
|
|
||||||
{
|
|
||||||
block_cache::block &b = bc_.get(location, 0, v);
|
|
||||||
return read_ref(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
typename block_manager<BlockSize>::write_ref
|
|
||||||
block_manager<BlockSize>::write_lock(block_address location,
|
|
||||||
typename bcache::validator::ptr v)
|
|
||||||
{
|
|
||||||
block_cache::block &b = bc_.get(location, block_cache::GF_DIRTY, v);
|
|
||||||
return write_ref(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
typename block_manager<BlockSize>::write_ref
|
|
||||||
block_manager<BlockSize>::write_lock_zero(block_address location,
|
|
||||||
typename bcache::validator::ptr v)
|
|
||||||
{
|
|
||||||
block_cache::block &b = bc_.get(location, block_cache::GF_ZERO, v);
|
|
||||||
return write_ref(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
typename block_manager<BlockSize>::write_ref
|
|
||||||
block_manager<BlockSize>::superblock(block_address location,
|
|
||||||
typename bcache::validator::ptr v)
|
|
||||||
{
|
|
||||||
if (bc_.get_nr_locked() > 0)
|
|
||||||
throw std::runtime_error("attempt to lock superblock while other locks are still held");
|
|
||||||
|
|
||||||
block_cache::block &b = bc_.get(location, block_cache::GF_DIRTY | block_cache::GF_BARRIER, v);
|
|
||||||
return write_ref(b, superblock_ref_count_);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
typename block_manager<BlockSize>::write_ref
|
|
||||||
block_manager<BlockSize>::superblock_zero(block_address location,
|
|
||||||
typename bcache::validator::ptr v)
|
|
||||||
{
|
|
||||||
if (bc_.get_nr_locked() > 0)
|
|
||||||
throw std::runtime_error("attempt to lock superblock while other locks are still held");
|
|
||||||
|
|
||||||
block_cache::block &b = bc_.get(location, block_cache::GF_ZERO | block_cache::GF_BARRIER, v);
|
|
||||||
return write_ref(b, superblock_ref_count_);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
block_address
|
|
||||||
block_manager<BlockSize>::get_nr_blocks() const
|
|
||||||
{
|
|
||||||
return bc_.get_nr_blocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
void
|
|
||||||
block_manager<BlockSize>::prefetch(block_address b) const
|
|
||||||
{
|
|
||||||
bc_.prefetch(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
|
||||||
void
|
|
||||||
block_manager<BlockSize>::flush() const
|
|
||||||
{
|
|
||||||
bc_.flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
|
@ -216,11 +216,11 @@ namespace persistent_data {
|
|||||||
unsigned entries_per_block_;
|
unsigned entries_per_block_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
|
|
||||||
typedef array_block<ValueTraits, block_manager<>::write_ref> wblock;
|
typedef array_block<ValueTraits, block_manager::write_ref> wblock;
|
||||||
typedef array_block<ValueTraits, block_manager<>::read_ref> rblock;
|
typedef array_block<ValueTraits, block_manager::read_ref> rblock;
|
||||||
|
|
||||||
typedef boost::shared_ptr<array<ValueTraits> > ptr;
|
typedef boost::shared_ptr<array<ValueTraits> > ptr;
|
||||||
typedef typename ValueTraits::value_type value_type;
|
typedef typename ValueTraits::value_type value_type;
|
||||||
|
@ -152,7 +152,7 @@ namespace persistent_data {
|
|||||||
//
|
//
|
||||||
template <typename ValueTraits>
|
template <typename ValueTraits>
|
||||||
node_ref<ValueTraits>
|
node_ref<ValueTraits>
|
||||||
to_node(typename block_manager<>::read_ref &b)
|
to_node(typename block_manager::read_ref &b)
|
||||||
{
|
{
|
||||||
// FIXME: this should return a const read_ref somehow.
|
// FIXME: this should return a const read_ref somehow.
|
||||||
return node_ref<ValueTraits>(
|
return node_ref<ValueTraits>(
|
||||||
@ -163,7 +163,7 @@ namespace persistent_data {
|
|||||||
|
|
||||||
template <typename ValueTraits>
|
template <typename ValueTraits>
|
||||||
node_ref<ValueTraits>
|
node_ref<ValueTraits>
|
||||||
to_node(typename block_manager<>::write_ref &b)
|
to_node(typename block_manager::write_ref &b)
|
||||||
{
|
{
|
||||||
return node_ref<ValueTraits>(
|
return node_ref<ValueTraits>(
|
||||||
b.get_location(),
|
b.get_location(),
|
||||||
@ -188,7 +188,7 @@ namespace persistent_data {
|
|||||||
private:
|
private:
|
||||||
transaction_manager &tm_;
|
transaction_manager &tm_;
|
||||||
bcache::validator::ptr validator_;
|
bcache::validator::ptr validator_;
|
||||||
std::list<block_manager<>::read_ref> spine_;
|
std::list<block_manager::read_ref> spine_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class shadow_spine : private boost::noncopyable {
|
class shadow_spine : private boost::noncopyable {
|
||||||
@ -252,7 +252,7 @@ namespace persistent_data {
|
|||||||
private:
|
private:
|
||||||
transaction_manager &tm_;
|
transaction_manager &tm_;
|
||||||
bcache::validator::ptr validator_;
|
bcache::validator::ptr validator_;
|
||||||
std::list<block_manager<>::write_ref> spine_;
|
std::list<block_manager::write_ref> spine_;
|
||||||
maybe_block root_;
|
maybe_block root_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -304,8 +304,8 @@ namespace persistent_data {
|
|||||||
typedef typename ValueTraits::value_type value_type;
|
typedef typename ValueTraits::value_type value_type;
|
||||||
typedef boost::optional<value_type> maybe_value;
|
typedef boost::optional<value_type> maybe_value;
|
||||||
typedef boost::optional<std::pair<unsigned, value_type> > maybe_pair;
|
typedef boost::optional<std::pair<unsigned, value_type> > maybe_pair;
|
||||||
typedef typename block_manager<>::read_ref read_ref;
|
typedef typename block_manager::read_ref read_ref;
|
||||||
typedef typename block_manager<>::write_ref write_ref;
|
typedef typename block_manager::write_ref write_ref;
|
||||||
typedef typename btree_detail::node_ref<ValueTraits> leaf_node;
|
typedef typename btree_detail::node_ref<ValueTraits> leaf_node;
|
||||||
typedef typename btree_detail::node_ref<block_traits> internal_node;
|
typedef typename btree_detail::node_ref<block_traits> internal_node;
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ using namespace std;
|
|||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
bool
|
bool
|
||||||
persistent_data::check_for_xml(block_manager<>::ptr bm) {
|
persistent_data::check_for_xml(block_manager::ptr bm) {
|
||||||
block_manager<>::read_ref b = bm->read_lock(0);
|
block_manager::read_ref b = bm->read_lock(0);
|
||||||
const char *data = reinterpret_cast<const char *>(b.data());
|
const char *data = reinterpret_cast<const char *>(b.data());
|
||||||
return (!strncmp(data, "<superblock", 11) || !strncmp(data, "<?xml", 5)
|
return (!strncmp(data, "<superblock", 11) || !strncmp(data, "<?xml", 5)
|
||||||
|| !strncmp(data, "<!DOCTYPE", 9));
|
|| !strncmp(data, "<!DOCTYPE", 9));
|
||||||
@ -39,22 +39,22 @@ persistent_data::get_nr_metadata_blocks(std::string const &path)
|
|||||||
return get_nr_blocks(path, MD_BLOCK_SIZE);
|
return get_nr_blocks(path, MD_BLOCK_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
persistent_data::block_manager<>::ptr
|
persistent_data::block_manager::ptr
|
||||||
persistent_data::open_bm(std::string const &dev_path, block_manager<>::mode m, bool excl)
|
persistent_data::open_bm(std::string const &dev_path, block_manager::mode m, bool excl)
|
||||||
{
|
{
|
||||||
block_address nr_blocks = get_nr_metadata_blocks(dev_path);
|
block_address nr_blocks = get_nr_metadata_blocks(dev_path);
|
||||||
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m, excl));
|
return block_manager::ptr(new block_manager(dev_path, nr_blocks, 1, m, excl));
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr
|
block_manager::ptr
|
||||||
persistent_data::open_bm(std::string const &path) {
|
persistent_data::open_bm(std::string const &path) {
|
||||||
block_address nr_blocks = get_nr_metadata_blocks(path);
|
block_address nr_blocks = get_nr_metadata_blocks(path);
|
||||||
block_manager<>::mode m = block_manager<>::READ_ONLY;
|
block_manager::mode m = block_manager::READ_ONLY;
|
||||||
return block_manager<>::ptr(new block_manager<>(path, nr_blocks, 1, m));
|
return block_manager::ptr(new block_manager(path, nr_blocks, 1, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
persistent_data::open_tm(block_manager<>::ptr bm, block_address superblock_location) {
|
persistent_data::open_tm(block_manager::ptr bm, block_address superblock_location) {
|
||||||
auto nr_blocks = bm->get_nr_blocks();
|
auto nr_blocks = bm->get_nr_blocks();
|
||||||
if (!nr_blocks)
|
if (!nr_blocks)
|
||||||
throw runtime_error("Metadata is not large enough for superblock.");
|
throw runtime_error("Metadata is not large enough for superblock.");
|
||||||
|
@ -10,15 +10,15 @@
|
|||||||
|
|
||||||
// FIXME: move to a different unit
|
// FIXME: move to a different unit
|
||||||
namespace persistent_data {
|
namespace persistent_data {
|
||||||
bool check_for_xml(block_manager<>::ptr bm);
|
bool check_for_xml(block_manager::ptr bm);
|
||||||
persistent_data::block_address get_nr_blocks(std::string const &path, sector_t block_size = MD_BLOCK_SIZE);
|
persistent_data::block_address get_nr_blocks(std::string const &path, sector_t block_size = MD_BLOCK_SIZE);
|
||||||
block_address get_nr_metadata_blocks(std::string const &path);
|
block_address get_nr_metadata_blocks(std::string const &path);
|
||||||
|
|
||||||
block_manager<>::ptr open_bm(std::string const &dev_path,
|
block_manager::ptr open_bm(std::string const &dev_path,
|
||||||
block_manager<>::mode m, bool excl = true);
|
block_manager::mode m, bool excl = true);
|
||||||
|
|
||||||
block_manager<>::ptr open_bm(std::string const &path);
|
block_manager::ptr open_bm(std::string const &path);
|
||||||
transaction_manager::ptr open_tm(block_manager<>::ptr bm,
|
transaction_manager::ptr open_tm(block_manager::ptr bm,
|
||||||
block_address superblock_location);
|
block_address superblock_location);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,7 @@ namespace {
|
|||||||
|
|
||||||
metadata_index_store(transaction_manager &tm)
|
metadata_index_store(transaction_manager &tm)
|
||||||
: tm_(tm) {
|
: tm_(tm) {
|
||||||
block_manager<>::write_ref wr = tm_.new_block(index_validator());
|
block_manager::write_ref wr = tm_.new_block(index_validator());
|
||||||
bitmap_root_ = wr.get_location();
|
bitmap_root_ = wr.get_location();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -753,7 +753,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void commit_ies() {
|
virtual void commit_ies() {
|
||||||
std::pair<block_manager<>::write_ref, bool> p =
|
std::pair<block_manager::write_ref, bool> p =
|
||||||
tm_.shadow(bitmap_root_, index_validator());
|
tm_.shadow(bitmap_root_, index_validator());
|
||||||
|
|
||||||
bitmap_root_ = p.first.get_location();
|
bitmap_root_ = p.first.get_location();
|
||||||
@ -787,7 +787,7 @@ namespace {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void load_ies() {
|
void load_ies() {
|
||||||
block_manager<>::read_ref rr =
|
block_manager::read_ref rr =
|
||||||
tm_.read_lock(bitmap_root_, index_validator());
|
tm_.read_lock(bitmap_root_, index_validator());
|
||||||
|
|
||||||
metadata_index const *mdi = reinterpret_cast<metadata_index const *>(rr.data());
|
metadata_index const *mdi = reinterpret_cast<metadata_index const *>(rr.data());
|
||||||
|
@ -26,7 +26,7 @@ using namespace std;
|
|||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
transaction_manager::transaction_manager(block_manager<>::ptr bm,
|
transaction_manager::transaction_manager(block_manager::ptr bm,
|
||||||
space_map::ptr sm)
|
space_map::ptr sm)
|
||||||
: bm_(bm),
|
: bm_(bm),
|
||||||
sm_(sm)
|
sm_(sm)
|
||||||
|
@ -31,15 +31,15 @@ namespace persistent_data {
|
|||||||
class transaction_manager : boost::noncopyable {
|
class transaction_manager : boost::noncopyable {
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<transaction_manager> ptr;
|
typedef boost::shared_ptr<transaction_manager> ptr;
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
typedef bcache::validator::ptr validator;
|
typedef bcache::validator::ptr validator;
|
||||||
|
|
||||||
// If the space map is persistent, then the caller should
|
// If the space map is persistent, then the caller should
|
||||||
// hold onto a reference and remember to call sm_->commit()
|
// hold onto a reference and remember to call sm_->commit()
|
||||||
// and update the superblock before dropping the superblock
|
// and update the superblock before dropping the superblock
|
||||||
// reference.
|
// reference.
|
||||||
transaction_manager(block_manager<>::ptr bm,
|
transaction_manager(block_manager::ptr bm,
|
||||||
space_map::ptr sm);
|
space_map::ptr sm);
|
||||||
~transaction_manager();
|
~transaction_manager();
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ namespace persistent_data {
|
|||||||
sm_ = sm;
|
sm_ = sm;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr get_bm() {
|
block_manager::ptr get_bm() {
|
||||||
return bm_;
|
return bm_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ namespace persistent_data {
|
|||||||
bool is_shadow(block_address b) const;
|
bool is_shadow(block_address b) const;
|
||||||
void wipe_shadow_table();
|
void wipe_shadow_table();
|
||||||
|
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
|
|
||||||
std::set<block_address> shadows_;
|
std::set<block_address> shadows_;
|
||||||
|
@ -50,7 +50,7 @@ namespace {
|
|||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, open_type ot,
|
metadata::metadata(block_manager::ptr bm, open_type ot,
|
||||||
sector_t data_block_size,
|
sector_t data_block_size,
|
||||||
block_address nr_data_blocks)
|
block_address nr_data_blocks)
|
||||||
{
|
{
|
||||||
@ -102,7 +102,7 @@ metadata::metadata(block_manager<>::ptr bm, open_type ot,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, bool read_space_maps)
|
metadata::metadata(block_manager::ptr bm, bool read_space_maps)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
||||||
sb_ = read_superblock(tm_->get_bm(), SUPERBLOCK_LOCATION);
|
sb_ = read_superblock(tm_->get_bm(), SUPERBLOCK_LOCATION);
|
||||||
@ -113,7 +113,7 @@ metadata::metadata(block_manager<>::ptr bm, bool read_space_maps)
|
|||||||
open_btrees();
|
open_btrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm,
|
metadata::metadata(block_manager::ptr bm,
|
||||||
boost::optional<block_address> metadata_snap)
|
boost::optional<block_address> metadata_snap)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
||||||
@ -132,7 +132,7 @@ metadata::metadata(block_manager<>::ptr bm,
|
|||||||
open_btrees();
|
open_btrees();
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata::metadata(block_manager<>::ptr bm, superblock_detail::superblock const &sb)
|
metadata::metadata(block_manager::ptr bm, superblock_detail::superblock const &sb)
|
||||||
{
|
{
|
||||||
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
tm_ = open_tm(bm, SUPERBLOCK_LOCATION);
|
||||||
sb_ = sb;
|
sb_ = sb;
|
||||||
|
@ -55,11 +55,11 @@ namespace thin_provisioning {
|
|||||||
OPEN
|
OPEN
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
typedef boost::shared_ptr<metadata> ptr;
|
typedef boost::shared_ptr<metadata> ptr;
|
||||||
|
|
||||||
metadata(block_manager<>::ptr bm, open_type ot,
|
metadata(block_manager::ptr bm, open_type ot,
|
||||||
sector_t data_block_size = 128,
|
sector_t data_block_size = 128,
|
||||||
block_address nr_data_blocks = 0); // Only used if CREATE
|
block_address nr_data_blocks = 0); // Only used if CREATE
|
||||||
|
|
||||||
@ -74,12 +74,12 @@ namespace thin_provisioning {
|
|||||||
// ii) Read the metadata snap as given in the superblock
|
// ii) Read the metadata snap as given in the superblock
|
||||||
// iii) Read the metadata snap given on command line, checking it matches superblock.
|
// iii) Read the metadata snap given on command line, checking it matches superblock.
|
||||||
//
|
//
|
||||||
metadata(block_manager<>::ptr bm, bool read_space_maps = true); // (i)
|
metadata(block_manager::ptr bm, bool read_space_maps = true); // (i)
|
||||||
metadata(block_manager<>::ptr,
|
metadata(block_manager::ptr,
|
||||||
boost::optional<block_address> metadata_snap); // (ii) and (iii)
|
boost::optional<block_address> metadata_snap); // (ii) and (iii)
|
||||||
|
|
||||||
// This is used by repair, when we rebuild the superblock
|
// This is used by repair, when we rebuild the superblock
|
||||||
metadata(block_manager<>::ptr bm, superblock_detail::superblock const &sb);
|
metadata(block_manager::ptr bm, superblock_detail::superblock const &sb);
|
||||||
|
|
||||||
void commit();
|
void commit();
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ namespace {
|
|||||||
|
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
error_state examine_superblock(block_manager<>::ptr bm,
|
error_state examine_superblock(block_manager::ptr bm,
|
||||||
nested_output &out) {
|
nested_output &out) {
|
||||||
out << "examining superblock" << end_message();
|
out << "examining superblock" << end_message();
|
||||||
nested_output::nest _ = out.push();
|
nested_output::nest _ = out.push();
|
||||||
@ -240,7 +240,7 @@ namespace {
|
|||||||
|
|
||||||
class base_metadata_checker : public metadata_checker {
|
class base_metadata_checker : public metadata_checker {
|
||||||
public:
|
public:
|
||||||
base_metadata_checker(block_manager<>::ptr bm,
|
base_metadata_checker(block_manager::ptr bm,
|
||||||
check_options check_opts,
|
check_options check_opts,
|
||||||
output_options output_opts)
|
output_options output_opts)
|
||||||
: bm_(bm),
|
: bm_(bm),
|
||||||
@ -322,7 +322,7 @@ namespace {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
check_options options_;
|
check_options options_;
|
||||||
nested_output out_;
|
nested_output out_;
|
||||||
nested_output info_out_;
|
nested_output info_out_;
|
||||||
@ -351,7 +351,7 @@ void check_options::set_override_mapping_root(block_address b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metadata_checker::ptr
|
metadata_checker::ptr
|
||||||
thin_provisioning::create_base_checker(block_manager<>::ptr bm,
|
thin_provisioning::create_base_checker(block_manager::ptr bm,
|
||||||
check_options const &check_opts,
|
check_options const &check_opts,
|
||||||
output_options output_opts)
|
output_options output_opts)
|
||||||
{
|
{
|
||||||
|
@ -64,7 +64,7 @@ namespace thin_provisioning {
|
|||||||
};
|
};
|
||||||
|
|
||||||
metadata_checker::ptr
|
metadata_checker::ptr
|
||||||
create_base_checker(persistent_data::block_manager<>::ptr bm,
|
create_base_checker(persistent_data::block_manager::ptr bm,
|
||||||
check_options const &check_opts,
|
check_options const &check_opts,
|
||||||
output_options output_opts);
|
output_options output_opts);
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ namespace {
|
|||||||
|
|
||||||
class gatherer {
|
class gatherer {
|
||||||
public:
|
public:
|
||||||
gatherer(block_manager<> &bm)
|
gatherer(block_manager &bm)
|
||||||
: bm_(bm),
|
: bm_(bm),
|
||||||
referenced_(bm.get_nr_blocks(), false),
|
referenced_(bm.get_nr_blocks(), false),
|
||||||
examined_(bm.get_nr_blocks(), false) {
|
examined_(bm.get_nr_blocks(), false) {
|
||||||
@ -471,7 +471,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
node_info get_internal_info(block_manager<>::read_ref &rr) {
|
node_info get_internal_info(block_manager::read_ref &rr) {
|
||||||
node_info info;
|
node_info info;
|
||||||
info.b = rr.get_location();
|
info.b = rr.get_location();
|
||||||
|
|
||||||
@ -520,7 +520,7 @@ namespace {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
node_info get_leaf_info(block_manager<>::read_ref &rr, node_header const &hdr) {
|
node_info get_leaf_info(block_manager::read_ref &rr, node_header const &hdr) {
|
||||||
node_info info;
|
node_info info;
|
||||||
info.b = rr.get_location();
|
info.b = rr.get_location();
|
||||||
|
|
||||||
@ -631,7 +631,7 @@ namespace {
|
|||||||
return optional<node_info>(it->second);
|
return optional<node_info>(it->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<> &bm_;
|
block_manager &bm_;
|
||||||
vector<bool> referenced_;
|
vector<bool> referenced_;
|
||||||
vector<bool> examined_;
|
vector<bool> examined_;
|
||||||
map<block_address, node_info> infos_;
|
map<block_address, node_info> infos_;
|
||||||
@ -778,7 +778,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
emit_trees_(block_manager<>::ptr bm, superblock_detail::superblock const &sb,
|
emit_trees_(block_manager::ptr bm, superblock_detail::superblock const &sb,
|
||||||
emitter::ptr e, override_options const &ropts)
|
emitter::ptr e, override_options const &ropts)
|
||||||
{
|
{
|
||||||
metadata md(bm, sb);
|
metadata md(bm, sb);
|
||||||
@ -805,7 +805,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
find_better_roots_(block_manager<>::ptr bm, superblock_detail::superblock &sb)
|
find_better_roots_(block_manager::ptr bm, superblock_detail::superblock &sb)
|
||||||
{
|
{
|
||||||
// We assume the superblock is wrong, and find the best roots
|
// We assume the superblock is wrong, and find the best roots
|
||||||
// for ourselves. We've had a few cases where people have
|
// for ourselves. We've had a few cases where people have
|
||||||
@ -847,7 +847,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
optional<superblock_detail::superblock>
|
optional<superblock_detail::superblock>
|
||||||
maybe_read_superblock(block_manager<>::ptr bm)
|
maybe_read_superblock(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto sb = read_superblock(bm);
|
auto sb = read_superblock(bm);
|
||||||
@ -859,7 +859,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
metadata_repair_(block_manager<>::ptr bm, emitter::ptr e, override_options const &opts)
|
metadata_repair_(block_manager::ptr bm, emitter::ptr e, override_options const &opts)
|
||||||
{
|
{
|
||||||
auto msb = maybe_read_superblock(bm);
|
auto msb = maybe_read_superblock(bm);
|
||||||
if (!msb)
|
if (!msb)
|
||||||
@ -902,7 +902,7 @@ thin_provisioning::metadata_dump(metadata::ptr md, emitter::ptr e, dump_options
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
thin_provisioning::metadata_repair(block_manager<>::ptr bm, emitter::ptr e, override_options const &opts)
|
thin_provisioning::metadata_repair(block_manager::ptr bm, emitter::ptr e, override_options const &opts)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
metadata_repair_(bm, e, opts);
|
metadata_repair_(bm, e, opts);
|
||||||
|
@ -63,7 +63,7 @@ namespace thin_provisioning {
|
|||||||
// We have to provide a different interface for repairing, since
|
// We have to provide a different interface for repairing, since
|
||||||
// the superblock itself may be corrupt, so we wont be able
|
// the superblock itself may be corrupt, so we wont be able
|
||||||
// to create the metadata object.
|
// to create the metadata object.
|
||||||
void metadata_repair(block_manager<>::ptr bm, emitter::ptr e, override_options const &opts);
|
void metadata_repair(block_manager::ptr bm, emitter::ptr e, override_options const &opts);
|
||||||
|
|
||||||
// Only used by ll_restore, so we leave the repair arg
|
// Only used by ll_restore, so we leave the repair arg
|
||||||
void metadata_dump_subtree(metadata::ptr md, emitter::ptr e, bool repair, uint64_t subtree_root);
|
void metadata_dump_subtree(metadata::ptr md, emitter::ptr e, bool repair, uint64_t subtree_root);
|
||||||
|
@ -159,41 +159,41 @@ namespace thin_provisioning {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
superblock_detail::superblock read_superblock(block_manager<> const &bm, block_address location)
|
superblock_detail::superblock read_superblock(block_manager const &bm, block_address location)
|
||||||
{
|
{
|
||||||
using namespace superblock_detail;
|
using namespace superblock_detail;
|
||||||
|
|
||||||
superblock sb;
|
superblock sb;
|
||||||
block_manager<>::read_ref 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
superblock_detail::superblock read_superblock(block_manager<>::ptr bm, block_address location)
|
superblock_detail::superblock read_superblock(block_manager::ptr bm, block_address location)
|
||||||
{
|
{
|
||||||
return read_superblock(*bm, location);
|
return read_superblock(*bm, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
superblock_detail::superblock read_superblock(block_manager<>::ptr bm)
|
superblock_detail::superblock read_superblock(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
superblock_detail::superblock read_superblock(block_manager<> const &bm)
|
superblock_detail::superblock read_superblock(block_manager const &bm)
|
||||||
{
|
{
|
||||||
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
return read_superblock(bm, SUPERBLOCK_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_superblock(block_manager<>::ptr bm, superblock_detail::superblock const &sb)
|
void write_superblock(block_manager::ptr bm, superblock_detail::superblock const &sb)
|
||||||
{
|
{
|
||||||
block_manager<>::write_ref w = bm->write_lock(SUPERBLOCK_LOCATION, superblock_validator());
|
block_manager::write_ref w = bm->write_lock(SUPERBLOCK_LOCATION, superblock_validator());
|
||||||
superblock_disk *disk = reinterpret_cast<superblock_disk *>(w.data());
|
superblock_disk *disk = reinterpret_cast<superblock_disk *>(w.data());
|
||||||
superblock_traits::pack(sb, *disk);
|
superblock_traits::pack(sb, *disk);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
check_superblock(block_manager<>::ptr bm,
|
check_superblock(block_manager::ptr bm,
|
||||||
superblock_detail::damage_visitor &visitor) {
|
superblock_detail::damage_visitor &visitor) {
|
||||||
using namespace superblock_detail;
|
using namespace superblock_detail;
|
||||||
|
|
||||||
|
@ -130,15 +130,15 @@ namespace thin_provisioning {
|
|||||||
// FIXME: should we put init_superblock in here too?
|
// FIXME: should we put init_superblock in here too?
|
||||||
|
|
||||||
// FIXME: make the bm const, and pass by reference rather than ptr
|
// FIXME: make the bm const, and pass by reference rather than ptr
|
||||||
superblock_detail::superblock read_superblock(persistent_data::block_manager<> const &bm);
|
superblock_detail::superblock read_superblock(persistent_data::block_manager const &bm);
|
||||||
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm);
|
superblock_detail::superblock read_superblock(persistent_data::block_manager::ptr bm);
|
||||||
superblock_detail::superblock read_superblock(persistent_data::block_manager<>::ptr bm,
|
superblock_detail::superblock read_superblock(persistent_data::block_manager::ptr bm,
|
||||||
persistent_data::block_address location);
|
persistent_data::block_address location);
|
||||||
|
|
||||||
void write_superblock(persistent_data::block_manager<>::ptr bm,
|
void write_superblock(persistent_data::block_manager::ptr bm,
|
||||||
superblock_detail::superblock const &sb);
|
superblock_detail::superblock const &sb);
|
||||||
|
|
||||||
void check_superblock(persistent_data::block_manager<>::ptr bm,
|
void check_superblock(persistent_data::block_manager::ptr bm,
|
||||||
superblock_detail::damage_visitor &visitor);
|
superblock_detail::damage_visitor &visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ namespace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void clear_needs_check(string const &path) {
|
void clear_needs_check(string const &path) {
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_WRITE);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_WRITE);
|
||||||
|
|
||||||
superblock_detail::superblock sb = read_superblock(bm);
|
superblock_detail::superblock sb = read_superblock(bm);
|
||||||
sb.set_needs_check_flag(false);
|
sb.set_needs_check_flag(false);
|
||||||
@ -76,7 +76,7 @@ namespace {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr bm = open_bm(path);
|
block_manager::ptr bm = open_bm(path);
|
||||||
output_options output_opts = !fs.quiet ? OUTPUT_NORMAL : OUTPUT_QUIET;
|
output_options output_opts = !fs.quiet ? OUTPUT_NORMAL : OUTPUT_QUIET;
|
||||||
metadata_checker::ptr checker = create_base_checker(bm, fs.check_opts, output_opts);
|
metadata_checker::ptr checker = create_base_checker(bm, fs.check_opts, output_opts);
|
||||||
error_state err = checker->check();
|
error_state err = checker->check();
|
||||||
|
@ -548,7 +548,7 @@ namespace local {
|
|||||||
block_address nr_data_blocks = 0ull;
|
block_address nr_data_blocks = 0ull;
|
||||||
|
|
||||||
{
|
{
|
||||||
block_manager<>::ptr bm = open_bm(*fs.dev, block_manager<>::READ_ONLY, !fs.use_metadata_snap);
|
block_manager::ptr bm = open_bm(*fs.dev, block_manager::READ_ONLY, !fs.use_metadata_snap);
|
||||||
metadata::ptr md(fs.use_metadata_snap ? new metadata(bm, fs.metadata_snap) : new metadata(bm));
|
metadata::ptr md(fs.use_metadata_snap ? new metadata(bm, fs.metadata_snap) : new metadata(bm));
|
||||||
sb = md->sb_;
|
sb = md->sb_;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
metadata::ptr open_metadata(string const &path, struct flags &flags) {
|
metadata::ptr open_metadata(string const &path, struct flags &flags) {
|
||||||
block_manager<>::ptr bm = open_bm(path, block_manager<>::READ_ONLY, !flags.use_metadata_snap);
|
block_manager::ptr bm = open_bm(path, block_manager::READ_ONLY, !flags.use_metadata_snap);
|
||||||
metadata::ptr md(flags.use_metadata_snap ? new metadata(bm, flags.snap_location) : new metadata(bm, false));
|
metadata::ptr md(flags.use_metadata_snap ? new metadata(bm, flags.snap_location) : new metadata(bm, false));
|
||||||
|
|
||||||
return md;
|
return md;
|
||||||
@ -91,7 +91,7 @@ namespace {
|
|||||||
emitter::ptr e = create_override_emitter(inner, flags.opts.overrides_);
|
emitter::ptr e = create_override_emitter(inner, flags.opts.overrides_);
|
||||||
|
|
||||||
if (flags.repair) {
|
if (flags.repair) {
|
||||||
auto bm = open_bm(path, block_manager<>::READ_ONLY, true);
|
auto bm = open_bm(path, block_manager::READ_ONLY, true);
|
||||||
metadata_repair(bm, e, flags.opts.overrides_);
|
metadata_repair(bm, e, flags.opts.overrides_);
|
||||||
} else {
|
} else {
|
||||||
metadata::ptr md = open_metadata(path, flags);
|
metadata::ptr md = open_metadata(path, flags);
|
||||||
|
@ -319,7 +319,7 @@ namespace {
|
|||||||
void ls_(string const &path, ostream &out, struct flags &flags) {
|
void ls_(string const &path, ostream &out, struct flags &flags) {
|
||||||
grid_layout grid;
|
grid_layout grid;
|
||||||
|
|
||||||
block_manager<>::ptr bm(open_bm(path, block_manager<>::READ_ONLY,
|
block_manager::ptr bm(open_bm(path, block_manager::READ_ONLY,
|
||||||
!flags.use_metadata_snap));
|
!flags.use_metadata_snap));
|
||||||
metadata::ptr md;
|
metadata::ptr md;
|
||||||
|
|
||||||
|
@ -22,13 +22,13 @@ namespace {
|
|||||||
bool metadata_touched = false;
|
bool metadata_touched = false;
|
||||||
try {
|
try {
|
||||||
// block size gets updated by the restorer
|
// block size gets updated by the restorer
|
||||||
block_manager<>::ptr new_bm = open_bm(new_path, block_manager<>::READ_WRITE);
|
block_manager::ptr new_bm = open_bm(new_path, block_manager::READ_WRITE);
|
||||||
file_utils::check_file_exists(old_path, false);
|
file_utils::check_file_exists(old_path, false);
|
||||||
metadata_touched = true;
|
metadata_touched = true;
|
||||||
metadata::ptr new_md(new metadata(new_bm, metadata::CREATE, 128, 0));
|
metadata::ptr new_md(new metadata(new_bm, metadata::CREATE, 128, 0));
|
||||||
emitter::ptr inner = create_restore_emitter(new_md);
|
emitter::ptr inner = create_restore_emitter(new_md);
|
||||||
emitter::ptr e = create_override_emitter(inner, opts);
|
emitter::ptr e = create_override_emitter(inner, opts);
|
||||||
block_manager<>::ptr old_bm = open_bm(old_path, block_manager<>::READ_ONLY);
|
block_manager::ptr old_bm = open_bm(old_path, block_manager::READ_ONLY);
|
||||||
metadata_repair(old_bm, e, opts);
|
metadata_repair(old_bm, e, opts);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
|
@ -49,7 +49,7 @@ namespace {
|
|||||||
bool metadata_touched = false;
|
bool metadata_touched = false;
|
||||||
try {
|
try {
|
||||||
// The block size gets updated by the restorer.
|
// The block size gets updated by the restorer.
|
||||||
block_manager<>::ptr bm(open_bm(dev, block_manager<>::READ_WRITE));
|
block_manager::ptr bm(open_bm(dev, block_manager::READ_WRITE));
|
||||||
file_utils::check_file_exists(backup_file);
|
file_utils::check_file_exists(backup_file);
|
||||||
metadata_touched = true;
|
metadata_touched = true;
|
||||||
metadata::ptr md(new metadata(bm, metadata::CREATE, 128, 0));
|
metadata::ptr md(new metadata(bm, metadata::CREATE, 128, 0));
|
||||||
|
@ -56,7 +56,7 @@ namespace {
|
|||||||
for (it = regions.begin(); it != regions.end(); ++it)
|
for (it = regions.begin(); it != regions.end(); ++it)
|
||||||
rv.add_data_region(*it);
|
rv.add_data_region(*it);
|
||||||
|
|
||||||
block_manager<>::ptr bm = open_bm(path);
|
block_manager::ptr bm = open_bm(path);
|
||||||
transaction_manager::ptr tm =
|
transaction_manager::ptr tm =
|
||||||
open_tm(bm, superblock_detail::SUPERBLOCK_LOCATION);
|
open_tm(bm, superblock_detail::SUPERBLOCK_LOCATION);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ namespace {
|
|||||||
|
|
||||||
// We can trim any block that has zero count in the data
|
// We can trim any block that has zero count in the data
|
||||||
// space map.
|
// space map.
|
||||||
block_manager<>::ptr bm = open_bm(metadata_dev, block_manager<>::READ_ONLY);
|
block_manager::ptr bm = open_bm(metadata_dev, block_manager::READ_ONLY);
|
||||||
metadata md(bm);
|
metadata md(bm);
|
||||||
|
|
||||||
if (!md.data_sm_->get_nr_free()) {
|
if (!md.data_sm_->get_nr_free()) {
|
||||||
|
@ -36,8 +36,8 @@ namespace {
|
|||||||
uint64_t MAX_VALUE = 1000ull;
|
uint64_t MAX_VALUE = 1000ull;
|
||||||
block_address const NR_BLOCKS = 1024;
|
block_address const NR_BLOCKS = 1024;
|
||||||
typedef bcache::noop_validator noop_validator;
|
typedef bcache::noop_validator noop_validator;
|
||||||
typedef block_manager<>::read_ref read_ref;
|
typedef block_manager::read_ref read_ref;
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
|
|
||||||
// FIXME: lift to utils?
|
// FIXME: lift to utils?
|
||||||
class simple_ref_counter {
|
class simple_ref_counter {
|
||||||
@ -86,7 +86,7 @@ namespace {
|
|||||||
|
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
create_tm() {
|
create_tm() {
|
||||||
block_manager<>::ptr bm = create_bm<4096>(NR_BLOCKS);
|
block_manager::ptr bm = create_bm(NR_BLOCKS);
|
||||||
space_map::ptr sm(new core_map(NR_BLOCKS));
|
space_map::ptr sm(new core_map(NR_BLOCKS));
|
||||||
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
||||||
return tm;
|
return tm;
|
||||||
|
@ -37,7 +37,7 @@ namespace {
|
|||||||
class ArrayTests : public Test {
|
class ArrayTests : public Test {
|
||||||
public:
|
public:
|
||||||
ArrayTests()
|
ArrayTests()
|
||||||
: bm_(new block_manager<>("./test.data", NR_BLOCKS, 4, block_manager<>::READ_WRITE)),
|
: bm_(new block_manager("./test.data", NR_BLOCKS, 4, block_manager::READ_WRITE)),
|
||||||
sm_(new core_map(NR_BLOCKS)),
|
sm_(new core_map(NR_BLOCKS)),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ namespace {
|
|||||||
array64::ptr a_;
|
array64::ptr a_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ namespace {
|
|||||||
class BitsetTests : public Test {
|
class BitsetTests : public Test {
|
||||||
public:
|
public:
|
||||||
BitsetTests()
|
BitsetTests()
|
||||||
: bm_(new block_manager<>("./test.data", NR_BLOCKS, 4, block_manager<>::READ_WRITE)),
|
: bm_(new block_manager("./test.data", NR_BLOCKS, 4, block_manager::READ_WRITE)),
|
||||||
sm_(new core_map(NR_BLOCKS)),
|
sm_(new core_map(NR_BLOCKS)),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
};
|
};
|
||||||
|
@ -29,7 +29,7 @@ using namespace testing;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <uint32_t BlockSize>
|
template <uint32_t BlockSize>
|
||||||
void check_all_bytes(typename block_manager<BlockSize>::read_ref const &rr, int v) {
|
void check_all_bytes(typename block_manager::read_ref const &rr, int v) {
|
||||||
unsigned char const *data = reinterpret_cast<unsigned char const *>(rr.data());
|
unsigned char const *data = reinterpret_cast<unsigned char const *>(rr.data());
|
||||||
for (unsigned b = 0; b < BlockSize; b++)
|
for (unsigned b = 0; b < BlockSize; b++)
|
||||||
ASSERT_THAT(data[b], Eq(static_cast<unsigned char>(v)));
|
ASSERT_THAT(data[b], Eq(static_cast<unsigned char>(v)));
|
||||||
@ -68,27 +68,27 @@ namespace {
|
|||||||
MOCK_CONST_METHOD2(prepare, void(void *, block_address));
|
MOCK_CONST_METHOD2(prepare, void(void *, block_address));
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef block_manager<4096> bm4096;
|
typedef block_manager bm4096;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
TEST(BlockTests, bad_path)
|
TEST(BlockTests, bad_path)
|
||||||
{
|
{
|
||||||
ASSERT_THROW(bm4096("/bogus/bogus/bogus", 1234, 4, block_manager<>::READ_WRITE),
|
ASSERT_THROW(bm4096("/bogus/bogus/bogus", 1234, 4, block_manager::READ_WRITE),
|
||||||
runtime_error);
|
runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, out_of_range_access)
|
TEST(BlockTests, out_of_range_access)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>(1024);
|
bm4096::ptr bm = create_bm(1024);
|
||||||
ASSERT_THROW(bm->read_lock(1024), runtime_error);
|
ASSERT_THROW(bm->read_lock(1024), runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, read_lock_all_blocks)
|
TEST(BlockTests, read_lock_all_blocks)
|
||||||
{
|
{
|
||||||
block_address const nr = 64;
|
block_address const nr = 64;
|
||||||
bm4096::ptr bm = create_bm<4096>(nr);
|
bm4096::ptr bm = create_bm(nr);
|
||||||
for (unsigned i = 0; i < nr; i++)
|
for (unsigned i = 0; i < nr; i++)
|
||||||
bm->read_lock(i);
|
bm->read_lock(i);
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ TEST(BlockTests, read_lock_all_blocks)
|
|||||||
TEST(BlockTests, write_lock_all_blocks)
|
TEST(BlockTests, write_lock_all_blocks)
|
||||||
{
|
{
|
||||||
block_address const nr = 64;
|
block_address const nr = 64;
|
||||||
bm4096::ptr bm = create_bm<4096>(nr);
|
bm4096::ptr bm = create_bm(nr);
|
||||||
for (unsigned i = 0; i < nr; i++)
|
for (unsigned i = 0; i < nr; i++)
|
||||||
bm->write_lock(i);
|
bm->write_lock(i);
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ TEST(BlockTests, write_lock_all_blocks)
|
|||||||
TEST(BlockTests, writes_persist)
|
TEST(BlockTests, writes_persist)
|
||||||
{
|
{
|
||||||
block_address const nr = 64;
|
block_address const nr = 64;
|
||||||
bm4096::ptr bm = create_bm<4096>(nr);
|
bm4096::ptr bm = create_bm(nr);
|
||||||
for (unsigned i = 0; i < nr; i++) {
|
for (unsigned i = 0; i < nr; i++) {
|
||||||
bm4096::write_ref wr = bm->write_lock(i);
|
bm4096::write_ref wr = bm->write_lock(i);
|
||||||
::memset(wr.data(), i, 4096);
|
::memset(wr.data(), i, 4096);
|
||||||
@ -118,52 +118,21 @@ TEST(BlockTests, writes_persist)
|
|||||||
|
|
||||||
TEST(BlockTests, write_lock_zero_zeroes)
|
TEST(BlockTests, write_lock_zero_zeroes)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>(64);
|
bm4096::ptr bm = create_bm(64);
|
||||||
check_all_bytes<4096>(bm->write_lock_zero(23), 0);
|
check_all_bytes<4096>(bm->write_lock_zero(23), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, different_block_sizes)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
bm4096::ptr bm = create_bm<4096>(64);
|
|
||||||
|
|
||||||
{
|
|
||||||
bm4096::write_ref wr = bm->write_lock(0);
|
|
||||||
memset(wr.data(), 23, 4096);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
bm4096::write_ref wr = bm->write_lock_zero(0);
|
|
||||||
check_all_bytes<4096>(wr, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
block_manager<64 * 1024>::ptr bm = create_bm<64 * 1024>(64);
|
|
||||||
|
|
||||||
{
|
|
||||||
block_manager<64 * 1024>::write_ref wr = bm->write_lock(0);
|
|
||||||
memset(wr.data(), 72, 64 * 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
block_manager<64 * 1024>::write_ref wr = bm->write_lock_zero(0);
|
|
||||||
check_all_bytes<64 * 1024>(wr, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(BlockTests, read_validator_works)
|
TEST(BlockTests, read_validator_works)
|
||||||
{
|
{
|
||||||
bcache::validator::ptr v(new zero_validator<4096>());
|
bcache::validator::ptr v(new zero_validator<4096>());
|
||||||
bm4096::ptr bm = create_bm<4096>(64);
|
bm4096::ptr bm = create_bm(64);
|
||||||
bm->write_lock_zero(0);
|
bm->write_lock_zero(0);
|
||||||
bm->read_lock(0, v);
|
bm->read_lock(0, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, write_validator_works)
|
TEST(BlockTests, write_validator_works)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>(64);
|
bm4096::ptr bm = create_bm(64);
|
||||||
bcache::validator::ptr v(new zero_validator<4096>());
|
bcache::validator::ptr v(new zero_validator<4096>());
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -177,21 +146,21 @@ TEST(BlockTests, write_validator_works)
|
|||||||
|
|
||||||
TEST(BlockTests, cannot_have_two_superblocks)
|
TEST(BlockTests, cannot_have_two_superblocks)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm4096::write_ref superblock = bm->superblock(0);
|
bm4096::write_ref superblock = bm->superblock(0);
|
||||||
ASSERT_THROW(bm->superblock(1), runtime_error);
|
ASSERT_THROW(bm->superblock(1), runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, can_have_subsequent_superblocks)
|
TEST(BlockTests, can_have_subsequent_superblocks)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
{ bm4096::write_ref superblock = bm->superblock(0); }
|
{ bm4096::write_ref superblock = bm->superblock(0); }
|
||||||
{ bm4096::write_ref superblock = bm->superblock(0); }
|
{ bm4096::write_ref superblock = bm->superblock(0); }
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, superblocks_can_change_address)
|
TEST(BlockTests, superblocks_can_change_address)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
{ bm4096::write_ref superblock = bm->superblock(0); }
|
{ bm4096::write_ref superblock = bm->superblock(0); }
|
||||||
{ bm4096::write_ref superblock = bm->superblock(1); }
|
{ bm4096::write_ref superblock = bm->superblock(1); }
|
||||||
}
|
}
|
||||||
@ -203,7 +172,7 @@ TEST(BlockTests, superblocks_can_change_address)
|
|||||||
// correct thing to do is (log the error? put the tm into a 'bad' state?).
|
// correct thing to do is (log the error? put the tm into a 'bad' state?).
|
||||||
TEST(BlockTests, superblock_must_be_last)
|
TEST(BlockTests, superblock_must_be_last)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
{
|
{
|
||||||
bm4096::read_ref rr = bm->read_lock(63);
|
bm4096::read_ref rr = bm->read_lock(63);
|
||||||
{
|
{
|
||||||
@ -214,21 +183,21 @@ TEST(BlockTests, superblock_must_be_last)
|
|||||||
|
|
||||||
TEST(BlockTests, references_can_be_copied)
|
TEST(BlockTests, references_can_be_copied)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm4096::write_ref wr1 = bm->write_lock(0);
|
bm4096::write_ref wr1 = bm->write_lock(0);
|
||||||
bm4096::write_ref wr2(wr1);
|
bm4096::write_ref wr2(wr1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, no_concurrent_write_locks)
|
TEST(BlockTests, no_concurrent_write_locks)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm4096::write_ref wr = bm->write_lock(0);
|
bm4096::write_ref wr = bm->write_lock(0);
|
||||||
ASSERT_THROW(bm->write_lock(0), runtime_error);
|
ASSERT_THROW(bm->write_lock(0), runtime_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, concurrent_read_locks)
|
TEST(BlockTests, concurrent_read_locks)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm4096::read_ref rr = bm->read_lock(0);
|
bm4096::read_ref rr = bm->read_lock(0);
|
||||||
bm->read_lock(0);
|
bm->read_lock(0);
|
||||||
}
|
}
|
||||||
@ -238,7 +207,7 @@ TEST(BlockTests, concurrent_read_locks)
|
|||||||
// think I'm ever going to add the extra checking to the C++ code.
|
// think I'm ever going to add the extra checking to the C++ code.
|
||||||
TEST(BlockTests, no_concurrent_read_and_write_locks)
|
TEST(BlockTests, no_concurrent_read_and_write_locks)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm4096::write_ref wr = bm->write_lock(0);
|
bm4096::write_ref wr = bm->write_lock(0);
|
||||||
ASSERT_THROW(bm->read_lock(0), runtime_error);
|
ASSERT_THROW(bm->read_lock(0), runtime_error);
|
||||||
}
|
}
|
||||||
@ -246,14 +215,14 @@ TEST(BlockTests, no_concurrent_read_and_write_locks)
|
|||||||
|
|
||||||
TEST(BlockTests, read_then_write)
|
TEST(BlockTests, read_then_write)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm->read_lock(0);
|
bm->read_lock(0);
|
||||||
bm->write_lock(0);
|
bm->write_lock(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BlockTests, write_then_read)
|
TEST(BlockTests, write_then_read)
|
||||||
{
|
{
|
||||||
bm4096::ptr bm = create_bm<4096>();
|
bm4096::ptr bm = create_bm();
|
||||||
bm->write_lock(0);
|
bm->write_lock(0);
|
||||||
bm->read_lock(0);
|
bm->read_lock(0);
|
||||||
}
|
}
|
||||||
@ -264,7 +233,7 @@ namespace {
|
|||||||
class ValidatorTests : public Test {
|
class ValidatorTests : public Test {
|
||||||
public:
|
public:
|
||||||
ValidatorTests()
|
ValidatorTests()
|
||||||
: bm(create_bm<4096>()),
|
: bm(create_bm()),
|
||||||
vmock(new validator_mock),
|
vmock(new validator_mock),
|
||||||
vmock2(new validator_mock) {
|
vmock2(new validator_mock) {
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace {
|
|||||||
class BTreeCounterTests : public Test {
|
class BTreeCounterTests : public Test {
|
||||||
public:
|
public:
|
||||||
BTreeCounterTests()
|
BTreeCounterTests()
|
||||||
: bm_(create_bm<BLOCK_SIZE>(NR_BLOCKS)),
|
: bm_(create_bm(NR_BLOCKS)),
|
||||||
sm_(setup_core_map()),
|
sm_(setup_core_map()),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
with_temp_directory dir_;
|
with_temp_directory dir_;
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
uint64_traits::ref_counter rc_;
|
uint64_traits::ref_counter rc_;
|
||||||
@ -51,7 +51,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void commit() {
|
void commit() {
|
||||||
block_manager<>::write_ref superblock(bm_->superblock(SUPERBLOCK));
|
block_manager::write_ref superblock(bm_->superblock(SUPERBLOCK));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -256,7 +256,7 @@ namespace {
|
|||||||
class DamageTests : public Test {
|
class DamageTests : public Test {
|
||||||
public:
|
public:
|
||||||
DamageTests()
|
DamageTests()
|
||||||
: bm_(create_bm<BLOCK_SIZE>(NR_BLOCKS)),
|
: bm_(create_bm(NR_BLOCKS)),
|
||||||
sm_(setup_core_map()),
|
sm_(setup_core_map()),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ namespace {
|
|||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
with_temp_directory dir_;
|
with_temp_directory dir_;
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
thing_traits::ref_counter rc_;
|
thing_traits::ref_counter rc_;
|
||||||
@ -308,7 +308,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void commit() {
|
void commit() {
|
||||||
block_manager<>::write_ref superblock(bm_->superblock(SUPERBLOCK));
|
block_manager::write_ref superblock(bm_->superblock(SUPERBLOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void discover_layout() = 0;
|
virtual void discover_layout() = 0;
|
||||||
|
@ -34,7 +34,7 @@ namespace {
|
|||||||
class BtreeTests : public Test {
|
class BtreeTests : public Test {
|
||||||
public:
|
public:
|
||||||
BtreeTests()
|
BtreeTests()
|
||||||
: bm_(new block_manager<>("./test.data", NR_BLOCKS, 4, block_manager<>::READ_WRITE)),
|
: bm_(new block_manager("./test.data", NR_BLOCKS, 4, block_manager::READ_WRITE)),
|
||||||
sm_(new core_map(NR_BLOCKS)),
|
sm_(new core_map(NR_BLOCKS)),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,7 @@ namespace {
|
|||||||
class SpaceMapTests : public Test {
|
class SpaceMapTests : public Test {
|
||||||
public:
|
public:
|
||||||
SpaceMapTests()
|
SpaceMapTests()
|
||||||
: bm_(new block_manager<>("./test.data", NR_BLOCKS, MAX_LOCKS, block_manager<>::READ_WRITE)),
|
: bm_(new block_manager("./test.data", NR_BLOCKS, MAX_LOCKS, block_manager::READ_WRITE)),
|
||||||
sm_(new core_map(NR_BLOCKS)),
|
sm_(new core_map(NR_BLOCKS)),
|
||||||
tm_(bm_, sm_) {
|
tm_(bm_, sm_) {
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
block_manager<>::ptr bm_;
|
block_manager::ptr bm_;
|
||||||
space_map::ptr sm_;
|
space_map::ptr sm_;
|
||||||
transaction_manager tm_;
|
transaction_manager tm_;
|
||||||
};
|
};
|
||||||
@ -277,8 +277,8 @@ TEST_F(SpaceMapTests, test_sm_metadata)
|
|||||||
|
|
||||||
TEST_F(SpaceMapTests, test_metadata_and_disk)
|
TEST_F(SpaceMapTests, test_metadata_and_disk)
|
||||||
{
|
{
|
||||||
block_manager<>::ptr bm(
|
block_manager::ptr bm(
|
||||||
new block_manager<>("./test.data", NR_BLOCKS, MAX_LOCKS, block_manager<>::READ_WRITE));
|
new block_manager("./test.data", NR_BLOCKS, MAX_LOCKS, block_manager::READ_WRITE));
|
||||||
space_map::ptr core_sm(new core_map(NR_BLOCKS));
|
space_map::ptr core_sm(new core_map(NR_BLOCKS));
|
||||||
transaction_manager::ptr tm(new transaction_manager(bm, core_sm));
|
transaction_manager::ptr tm(new transaction_manager(bm, core_sm));
|
||||||
persistent_space_map::ptr metadata_sm = persistent_data::create_metadata_sm(*tm, NR_BLOCKS);
|
persistent_space_map::ptr metadata_sm = persistent_data::create_metadata_sm(*tm, NR_BLOCKS);
|
||||||
|
@ -12,14 +12,14 @@ using namespace test;
|
|||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
|
|
||||||
void test::zero_block(block_manager<>::ptr bm, block_address b)
|
void test::zero_block(block_manager::ptr bm, block_address b)
|
||||||
{
|
{
|
||||||
block_manager<>::write_ref wr = bm->write_lock(b);
|
block_manager::write_ref wr = bm->write_lock(b);
|
||||||
memset(wr.data(), 0, 4096);
|
memset(wr.data(), 0, 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
test::open_temporary_tm(block_manager<>::ptr bm)
|
test::open_temporary_tm(block_manager::ptr bm)
|
||||||
{
|
{
|
||||||
space_map::ptr sm(new core_map(bm->get_nr_blocks()));
|
space_map::ptr sm(new core_map(bm->get_nr_blocks()));
|
||||||
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
||||||
|
@ -28,23 +28,22 @@ namespace test {
|
|||||||
|
|
||||||
unsigned const MAX_HELD_LOCKS = 16;
|
unsigned const MAX_HELD_LOCKS = 16;
|
||||||
|
|
||||||
template <uint32_t BlockSize>
|
inline block_manager::ptr
|
||||||
typename block_manager<BlockSize>::ptr
|
|
||||||
create_bm(block_address nr = 1024) {
|
create_bm(block_address nr = 1024) {
|
||||||
std::string const path("./test.data");
|
std::string const path("./test.data");
|
||||||
int r = system("rm -f ./test.data");
|
int r = system("rm -f ./test.data");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
throw std::runtime_error("couldn't rm -f ./test.data");
|
throw std::runtime_error("couldn't rm -f ./test.data");
|
||||||
|
|
||||||
return typename block_manager<BlockSize>::ptr(
|
return typename block_manager::ptr(
|
||||||
new block_manager<BlockSize>(path, nr, MAX_HELD_LOCKS,
|
new block_manager(path, nr, MAX_HELD_LOCKS,
|
||||||
block_manager<BlockSize>::CREATE));
|
block_manager::CREATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't use this to update the metadata.
|
// Don't use this to update the metadata.
|
||||||
transaction_manager::ptr open_temporary_tm(block_manager<>::ptr bm);
|
transaction_manager::ptr open_temporary_tm(block_manager::ptr bm);
|
||||||
|
|
||||||
void zero_block(block_manager<>::ptr bm, block_address b);
|
void zero_block(block_manager::ptr bm, block_address b);
|
||||||
|
|
||||||
//--------------------------------
|
//--------------------------------
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ namespace {
|
|||||||
|
|
||||||
transaction_manager::ptr
|
transaction_manager::ptr
|
||||||
create_tm() {
|
create_tm() {
|
||||||
block_manager<>::ptr bm(
|
block_manager::ptr bm(
|
||||||
new block_manager<>("./test.data", NR_BLOCKS, MAX_HELD_LOCKS, block_manager<>::READ_WRITE));
|
new block_manager("./test.data", NR_BLOCKS, MAX_HELD_LOCKS, block_manager::READ_WRITE));
|
||||||
space_map::ptr sm(new core_map(NR_BLOCKS));
|
space_map::ptr sm(new core_map(NR_BLOCKS));
|
||||||
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
||||||
tm->get_sm()->inc(0);
|
tm->get_sm()->inc(0);
|
||||||
@ -47,7 +47,7 @@ namespace {
|
|||||||
new bcache::noop_validator);
|
new bcache::noop_validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef block_manager<>::write_ref write_ref;
|
typedef block_manager::write_ref write_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------
|
//----------------------------------------------------------------
|
||||||
@ -61,7 +61,7 @@ TEST(TransactionManagerTests, commit_succeeds)
|
|||||||
TEST(TransactionManagerTests, shadowing)
|
TEST(TransactionManagerTests, shadowing)
|
||||||
{
|
{
|
||||||
transaction_manager::ptr tm = create_tm();
|
transaction_manager::ptr tm = create_tm();
|
||||||
block_manager<>::write_ref superblock = tm->begin(0, mk_noop_validator());
|
block_manager::write_ref superblock = tm->begin(0, mk_noop_validator());
|
||||||
|
|
||||||
space_map::ptr sm = tm->get_sm();
|
space_map::ptr sm = tm->get_sm();
|
||||||
sm->inc(1);
|
sm->inc(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user