Move source into separate sub directories.

This commit is contained in:
Joe Thornber 2013-01-02 12:55:41 +00:00
parent c0d2eb9bc6
commit 282e98a6b1
55 changed files with 85 additions and 336 deletions

View File

@ -27,28 +27,28 @@ PROGRAMS=\
all: $(PROGRAMS) all: $(PROGRAMS)
SOURCE=\ SOURCE=\
checksum.cc \ persistent-data/checksum.cc \
endian_utils.cc \ persistent-data/endian_utils.cc \
error_set.cc \ persistent-data/error_set.cc \
hex_dump.cc \ persistent-data/hex_dump.cc \
human_readable_format.cc \ persistent-data/space_map.cc \
metadata.cc \ persistent-data/space_map_disk.cc \
metadata_checker.cc \ persistent-data/space_map_recursive.cc \
metadata_dumper.cc \ persistent-data/space_map_transactional.cc \
metadata_disk_structures.cc \ persistent-data/transaction_manager.cc \
restore_emitter.cc \ thin-provisioning/human_readable_format.cc \
space_map.cc \ thin-provisioning/metadata.cc \
space_map_disk.cc \ thin-provisioning/metadata_checker.cc \
space_map_recursive.cc \ thin-provisioning/metadata_disk_structures.cc \
space_map_transactional.cc \ thin-provisioning/metadata_dumper.cc \
thin_pool.cc \ thin-provisioning/restore_emitter.cc \
transaction_manager.cc \ thin-provisioning/thin_pool.cc \
xml_format.cc thin-provisioning/xml_format.cc
PROGRAM_SOURCE=\ PROGRAM_SOURCE=\
thin_check.cc \ thin-provisioning/thin_check.cc \
thin_dump.cc \ thin-provisioning/thin_dump.cc \
thin_restore.cc thin-provisioning/thin_restore.cc
CXX:=@CXX@ CXX:=@CXX@
OBJECTS:=$(subst .cc,.o,$(SOURCE)) OBJECTS:=$(subst .cc,.o,$(SOURCE))
@ -57,7 +57,7 @@ TOP_BUILDDIR:=@top_builddir@
CXXFLAGS+=-Wall -fno-strict-aliasing CXXFLAGS+=-Wall -fno-strict-aliasing
CXXFLAGS+=@CXXOPTIMISE_FLAG@ CXXFLAGS+=@CXXOPTIMISE_FLAG@
CXXFLAGS+=@CXXDEBUG_FLAG@ CXXFLAGS+=@CXXDEBUG_FLAG@
INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning
LIBS:=-lstdc++ LIBS:=-lstdc++
LIBEXPAT:=-lexpat LIBEXPAT:=-lexpat
INSTALL:=@INSTALL@ INSTALL:=@INSTALL@
@ -86,40 +86,59 @@ test-programs: $(TEST_PROGRAMS)
%.o: %.cc %.o: %.cc
$(CXX) -c $(INCLUDES) $(CXXFLAGS) -o $@ $< $(CXX) -c $(INCLUDES) $(CXXFLAGS) -o $@ $<
# CACHE_CHECK_SOURCE=\
# persistent-data/checksum.cc \
# persistent-data/endian_utils.cc \
# persistent-data/error_set.cc \
# persistent-data/hex_dump.cc \
# cacmetadata.cc \
# metadata_checker.cc \
# cache_metadata_disk_structures.cc \
# space_map.cc \
# space_map_disk.cc \
# space_map_recursive.cc \
# space_map_transactional.cc \
# transaction_manager.cc
THIN_DEBUG_SOURCE=$(SOURCE) THIN_DEBUG_SOURCE=$(SOURCE)
THIN_DUMP_SOURCE=$(SOURCE) THIN_DUMP_SOURCE=$(SOURCE)
THIN_RESTORE_SOURCE=$(SOURCE) THIN_RESTORE_SOURCE=$(SOURCE)
THIN_CHECK_SOURCE=\ THIN_CHECK_SOURCE=\
checksum.cc \ persistent-data/checksum.cc \
endian_utils.cc \ persistent-data/endian_utils.cc \
error_set.cc \ persistent-data/error_set.cc \
hex_dump.cc \ persistent-data/hex_dump.cc \
metadata.cc \ persistent-data/space_map.cc \
metadata_checker.cc \ persistent-data/space_map_disk.cc \
metadata_disk_structures.cc \ persistent-data/space_map_recursive.cc \
space_map.cc \ persistent-data/space_map_transactional.cc \
space_map_disk.cc \ persistent-data/transaction_manager.cc \
space_map_recursive.cc \ thin-provisioning/metadata.cc \
space_map_transactional.cc \ thin-provisioning/metadata_checker.cc \
transaction_manager.cc thin-provisioning/metadata_disk_structures.cc
#CACHE_CHECK_OBJECTS=$(subst .cc,.o,$(CACHE_CHECK_SOURCE))
THIN_DEBUG_OBJECTS=$(subst .cc,.o,$(THIN_DEBUG_SOURCE)) THIN_DEBUG_OBJECTS=$(subst .cc,.o,$(THIN_DEBUG_SOURCE))
THIN_DUMP_OBJECTS=$(subst .cc,.o,$(THIN_DUMP_SOURCE)) THIN_DUMP_OBJECTS=$(subst .cc,.o,$(THIN_DUMP_SOURCE))
THIN_RESTORE_OBJECTS=$(subst .cc,.o,$(THIN_RESTORE_SOURCE)) THIN_RESTORE_OBJECTS=$(subst .cc,.o,$(THIN_RESTORE_SOURCE))
THIN_CHECK_OBJECTS=$(subst .cc,.o,$(THIN_CHECK_SOURCE)) THIN_CHECK_OBJECTS=$(subst .cc,.o,$(THIN_CHECK_SOURCE))
thin_debug: $(THIN_DEBUG_OBJECTS) thin_debug.o thin_debug: $(THIN_DEBUG_OBJECTS) thin-provisioning/thin_debug.o
$(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT) $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_dump: $(THIN_DUMP_OBJECTS) thin_dump.o thin_dump: $(THIN_DUMP_OBJECTS) thin-provisioning/thin_dump.o
$(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT) $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_restore: $(THIN_RESTORE_OBJECTS) thin_restore.o thin_restore: $(THIN_RESTORE_OBJECTS) thin-provisioning/thin_restore.o
$(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT) $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_check: $(THIN_CHECK_OBJECTS) thin_check.o thin_check: $(THIN_CHECK_OBJECTS) thin-provisioning/thin_check.o
$(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS) $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS)
#cache_check: $(CACHE_CHECK_OBJECTS) cache_check.o
# $(CXX) $(CXXFLAGS) -o $@ $+ $(LIBS)
clean: clean:
$(RM) *.o unit-tests/*.o *.d unit-tests/*.d $(TEST_PROGRAMS) $(PROGRAMS) $(RM) *.o unit-tests/*.o *.d unit-tests/*.d $(TEST_PROGRAMS) $(PROGRAMS)
distclean: clean distclean: clean

270
cache.h
View File

@ -1,270 +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/>.
#ifndef CACHE_H
#define CACHE_H
#include "deleter.h"
#include <boost/intrusive/circular_list_algorithms.hpp>
#include <boost/intrusive/rbtree_algorithms.hpp>
#include <boost/optional.hpp>
#include <list>
#include <map>
#include <memory>
#include <stdexcept>
//----------------------------------------------------------------
namespace base {
// ValueTraits needs to define value_type, key_type and a get_key()
// static function. Commonly you will want value_type to be a
// shared_ptr, with any teardown specific stuff in the destructor.
template <typename ValueTraits>
class cache {
public:
typedef typename ValueTraits::value_type value_type;
typedef typename ValueTraits::key_type key_type;
cache(unsigned max_entries);
~cache();
void insert(value_type const &v);
boost::optional<value_type> get(key_type const &k);
void put(value_type const &k);
template <typename T>
void iterate_unheld(T fn) const;
private:
void make_space();
struct value_entry {
// FIXME: this means the cached object must have a
// default constructor also, which is a shame.
// so we can construct the headers.
value_entry()
: ref_count_(1) {
}
explicit value_entry(value_type v)
: ref_count_(1),
v_(v) {
}
struct {
value_entry *next_, *prev_;
} lru_;
struct {
value_entry *parent_, *left_, *right_;
int color_;
} lookup_;
unsigned ref_count_;
value_type v_;
};
struct value_ptr_cmp {
bool operator() (value_entry const *lhs, value_entry const *rhs) {
key_type k1 = ValueTraits::get_key(lhs->v_);
key_type k2 = ValueTraits::get_key(rhs->v_);
return k1 < k2;
}
};
struct key_value_ptr_cmp {
bool operator() (key_type const &k1, value_entry const *rhs) {
key_type k2 = ValueTraits::get_key(rhs->v_);
return k1 < k2;
}
bool operator() (value_entry const *lhs, key_type const &k2) {
key_type k1 = ValueTraits::get_key(lhs->v_);
return k1 < k2;
}
};
struct list_node_traits {
typedef value_entry node;
typedef value_entry *node_ptr;
typedef const value_entry *const_node_ptr;
static node_ptr get_next(const_node_ptr n) {
return n->lru_.next_;
}
static void set_next(node_ptr n, node_ptr next) {
n->lru_.next_ = next;
}
static node_ptr get_previous(const_node_ptr n) {
return n->lru_.prev_;
}
static void set_previous(node_ptr n, node_ptr prev) {
n->lru_.prev_ = prev;
}
};
struct rbtree_node_traits {
typedef value_entry node;
typedef value_entry *node_ptr;
typedef const value_entry * const_node_ptr;
typedef int color;
static node_ptr get_parent(const_node_ptr n) {
return n->lookup_.parent_;
}
static void set_parent(node_ptr n, node_ptr parent) {
n->lookup_.parent_ = parent;
}
static node_ptr get_left(const_node_ptr n) {
return n->lookup_.left_;
}
static void set_left(node_ptr n, node_ptr left) {
n->lookup_.left_ = left;
}
static node_ptr get_right(const_node_ptr n) {
return n->lookup_.right_;
}
static void set_right(node_ptr n, node_ptr right) {
n->lookup_.right_ = right;
}
static int get_color(const_node_ptr n) {
return n->lookup_.color_;
}
static void set_color(node_ptr n, color c) {
n->lookup_.color_ = c;
}
static color red() {
return 0;
}
static color black() {
return 1;
}
};
typedef boost::intrusive::circular_list_algorithms<list_node_traits> lru_algo;
typedef boost::intrusive::rbtree_algorithms<rbtree_node_traits> lookup_algo;
unsigned max_entries_;
unsigned current_entries_;
value_entry lru_header_;
value_entry lookup_header_;
};
template <typename ValueTraits>
cache<ValueTraits>::cache(unsigned max_entries)
: max_entries_(max_entries),
current_entries_(0) {
lru_algo::init_header(&lru_header_);
lookup_algo::init_header(&lookup_header_);
}
template <typename ValueTraits>
cache<ValueTraits>::~cache() {
utils::deleter<value_entry> d;
lookup_algo::clear_and_dispose(&lookup_header_, d);
}
template <typename ValueTraits>
void
cache<ValueTraits>::insert(value_type const &v) {
make_space();
std::auto_ptr<value_entry> node(new value_entry(v));
value_ptr_cmp cmp;
lookup_algo::insert_equal(&lookup_header_, &lookup_header_, node.get(), cmp);
node.release();
current_entries_++;
}
template <typename ValueTraits>
boost::optional<typename ValueTraits::value_type>
cache<ValueTraits>::get(key_type const &k) {
key_value_ptr_cmp cmp;
value_entry *node = lookup_algo::find(&lookup_header_, k, cmp);
if (node == &lookup_header_)
return boost::optional<value_type>();
if (!node->ref_count_++)
lru_algo::unlink(node);
return boost::optional<value_type>(node->v_);
}
template <typename ValueTraits>
void
cache<ValueTraits>::put(value_type const &v) {
// FIXME: the lookup will go once we use a proper hook
key_value_ptr_cmp cmp;
key_type k = ValueTraits::get_key(v);
value_entry *node = lookup_algo::find(&lookup_header_, k, cmp);
if (node == &lookup_header_)
throw std::runtime_error("invalid put");
if (node->ref_count_ == 0)
throw std::runtime_error("invalid put");
if (!--node->ref_count_)
lru_algo::link_after(&lru_header_, node);
}
template <typename ValueTraits>
void
cache<ValueTraits>::make_space() {
if (current_entries_ == max_entries_) {
value_entry *node = lru_header_.lru_.prev_;
if (node == &lru_header_)
throw std::runtime_error("cache full");
lru_algo::unlink(node);
lookup_algo::unlink(node);
delete node;
current_entries_--;
}
}
template <typename ValueTraits>
template <typename T>
void
cache<ValueTraits>::iterate_unheld(T fn) const {
value_entry *n = lru_header_.lru_.next_;
while (n != &lru_header_) {
fn(n->v_);
n = n->lru_.next_;
}
}
}
//----------------------------------------------------------------
#endif

View File

@ -19,7 +19,7 @@
#ifndef BLOCK_H #ifndef BLOCK_H
#define BLOCK_H #define BLOCK_H
#include "cache.h" #include "persistent-data/cache.h"
#include <stdint.h> #include <stdint.h>
#include <map> #include <map>

View File

@ -16,7 +16,7 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "space_map_recursive.h" #include "persistent-data/space_map_recursive.h"
using namespace persistent_data; using namespace persistent_data;

View File

@ -16,7 +16,7 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "space_map_transactional.h" #include "persistent-data/space_map_transactional.h"
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -16,7 +16,7 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "transaction_manager.h" #include "persistent-data/transaction_manager.h"
#include <string.h> #include <string.h>

View File

@ -16,11 +16,11 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "metadata.h" #include "thin-provisioning/metadata.h"
#include "math_utils.h" #include "persistent-data/math_utils.h"
#include "space_map_core.h" #include "persistent-data/space_map_core.h"
#include "space_map_disk.h" #include "persistent-data/space_map_disk.h"
#include <linux/fs.h> #include <linux/fs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>

View File

@ -19,12 +19,12 @@
#ifndef METADATA_LL_H #ifndef METADATA_LL_H
#define METADATA_LL_H #define METADATA_LL_H
#include "block.h" #include "persistent-data/block.h"
#include "btree.h" #include "persistent-data/btree.h"
#include "endian_utils.h" #include "persistent-data/endian_utils.h"
#include "metadata_disk_structures.h" #include "thin-provisioning/metadata_disk_structures.h"
#include "space_map_disk.h" #include "persistent-data/space_map_disk.h"
#include "transaction_manager.h" #include "persistent-data/transaction_manager.h"
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -16,7 +16,7 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "metadata_checker.h" #include "thin-provisioning/metadata_checker.h"
using namespace thin_provisioning; using namespace thin_provisioning;

View File

@ -19,8 +19,8 @@
#ifndef METADATA_CHECKER_H #ifndef METADATA_CHECKER_H
#define METADATA_CHECKER_H #define METADATA_CHECKER_H
#include "error_set.h" #include "persistent-data/error_set.h"
#include "metadata.h" #include "thin-provisioning/metadata.h"
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -16,7 +16,7 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "metadata_disk_structures.h" #include "thin-provisioning/metadata_disk_structures.h"
#include <string.h> #include <string.h>

View File

@ -19,8 +19,8 @@
#ifndef METADATA_DISK_STRUCTURES_H #ifndef METADATA_DISK_STRUCTURES_H
#define METADATA_DISK_STRUCTURES_H #define METADATA_DISK_STRUCTURES_H
#include "endian_utils.h" #include "persistent-data/endian_utils.h"
#include "btree.h" #include "persistent-data/btree.h"
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -19,8 +19,8 @@
#ifndef SPACE_MAP_DISK_STRUCTURES_H #ifndef SPACE_MAP_DISK_STRUCTURES_H
#define SPACE_MAP_DISK_STRUCTURES_H #define SPACE_MAP_DISK_STRUCTURES_H
#include "endian_utils.h" #include "persistent-data/endian_utils.h"
#include "btree.h" #include "persistent-data/btree.h"
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -20,8 +20,8 @@
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include "metadata.h" #include "thin-provisioning/metadata.h"
#include "metadata_checker.h" #include "thin-provisioning/metadata_checker.h"
#include "version.h" #include "version.h"
using namespace persistent_data; using namespace persistent_data;

View File

@ -28,9 +28,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "btree.h" #include "persistent-data/btree.h"
#include "metadata.h" #include "thin-provisioning/metadata.h"
#include "metadata_checker.h" #include "thin-provisioning/metadata_checker.h"
#include "version.h" #include "version.h"
using namespace boost; using namespace boost;

View File

@ -16,9 +16,9 @@
// with thin-provisioning-tools. If not, see // with thin-provisioning-tools. If not, see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "thin_pool.h" #include "thin-provisioning/thin_pool.h"
#include "btree_checker.h" #include "persistent-data/btree_checker.h"
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>