[all] Build a single executable

This commit is contained in:
Joe Thornber 2014-08-27 14:01:31 +01:00
parent c1e0799367
commit 6f8b7e2914
48 changed files with 418 additions and 496 deletions

19
.gitignore vendored
View File

@ -10,24 +10,7 @@ cachegrind.*
\#*\# \#*\#
core core
thin_check bin/pdata_tools
thin_delta
thin_dump
thin_restore
thin_repair
thin_rmap
thin_metadata_size
cache_check
cache_dump
cache_restore
cache_repair
cache_metadata_size
era_check
era_dump
era_invalidate
era_restore
*.metadata *.metadata
bad-metadata bad-metadata

View File

@ -19,69 +19,54 @@
.PHONY: all .PHONY: all
V=@ V=@
PROGRAMS=\
cache_check \
cache_dump \
cache_restore \
cache_repair \
cache_metadata_size \
\
era_check \
era_dump \
era_invalidate \
era_restore \
\
thin_check \
thin_delta \
thin_dump \
thin_restore \
thin_repair \
thin_rmap \
thin_metadata_size
all: $(PROGRAMS) all: bin/pdata_tools
SOURCE=\ SOURCE=\
block-cache/block_cache.cc \ base/application.cc \
\
base/base64.cc \ base/base64.cc \
base/endian_utils.cc \ base/endian_utils.cc \
base/error_state.cc \ base/error_state.cc \
base/progress_monitor.cc \ base/progress_monitor.cc \
base/xml_utils.cc \ base/xml_utils.cc \
\ block-cache/block_cache.cc \
caching/cache_check.cc \
caching/cache_dump.cc \
caching/cache_metadata_size.cc \
caching/cache_repair.cc \
caching/cache_restore.cc \
caching/hint_array.cc \ caching/hint_array.cc \
caching/superblock.cc \
caching/mapping_array.cc \ caching/mapping_array.cc \
caching/metadata.cc \ caching/metadata.cc \
caching/metadata_dump.cc \ caching/metadata_dump.cc \
caching/restore_emitter.cc \ caching/restore_emitter.cc \
caching/superblock.cc \
caching/xml_format.cc \ caching/xml_format.cc \
\
era/era_array.cc \ era/era_array.cc \
era/era_check.cc \
era/era_detail.cc \ era/era_detail.cc \
era/superblock.cc \ era/era_dump.cc \
era/writeset_tree.cc \ era/era_invalidate.cc \
era/era_restore.cc \
era/metadata.cc \ era/metadata.cc \
era/metadata_dump.cc \ era/metadata_dump.cc \
era/restore_emitter.cc \ era/restore_emitter.cc \
era/superblock.cc \
era/writeset_tree.cc \
era/xml_format.cc \ era/xml_format.cc \
\ main.cc \
persistent-data/checksum.cc \ persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/transaction_manager.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 \
persistent-data/data-structures/btree.cc \ persistent-data/data-structures/btree.cc \
\ persistent-data/error_set.cc \
persistent-data/space_map.cc \ persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/space-maps/disk.cc \ persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \ persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \ persistent-data/space_map.cc \
\ persistent-data/transaction_manager.cc \
thin-provisioning/device_tree.cc \ thin-provisioning/device_tree.cc \
thin-provisioning/human_readable_format.cc \ thin-provisioning/human_readable_format.cc \
thin-provisioning/mapping_tree.cc \ thin-provisioning/mapping_tree.cc \
@ -91,33 +76,15 @@ SOURCE=\
thin-provisioning/restore_emitter.cc \ thin-provisioning/restore_emitter.cc \
thin-provisioning/rmap_visitor.cc \ thin-provisioning/rmap_visitor.cc \
thin-provisioning/superblock.cc \ thin-provisioning/superblock.cc \
thin-provisioning/thin_pool.cc \
thin-provisioning/xml_format.cc
PDATA_OBJECTS=$(subst .cc,.o,$(SOURCE))
CXX_PROGRAM_SOURCE=\
caching/cache_check.cc \
caching/cache_dump.cc \
caching/cache_restore.cc \
caching/cache_metadata_size.cc \
caching/cache_repair.cc \
\
era/era_check.cc \
era/era_dump.cc \
era/era_invalidate.cc \
era/era_restore.cc \
\
thin-provisioning/thin_check.cc \ thin-provisioning/thin_check.cc \
thin-provisioning/thin_delta.cc \ thin-provisioning/thin_delta.cc \
thin-provisioning/thin_dump.cc \ thin-provisioning/thin_dump.cc \
thin-provisioning/thin_restore.cc \ thin-provisioning/thin_metadata_size.cc \
thin-provisioning/thin_pool.cc \
thin-provisioning/thin_repair.cc \ thin-provisioning/thin_repair.cc \
thin-provisioning/thin_restore.cc \
thin-provisioning/thin_rmap.cc \ thin-provisioning/thin_rmap.cc \
thin-provisioning/thin_metadata_size.cc thin-provisioning/xml_format.cc
C_PROGRAM_SOURCE=\
thin-provisioning/thin_metadata_size.c
CC:=@CC@ CC:=@CC@
CXX:=@CXX@ CXX:=@CXX@
@ -129,8 +96,7 @@ CXXFLAGS+=-g -Wall -fno-strict-aliasing
CXXFLAGS+=@CXXOPTIMISE_FLAG@ CXXFLAGS+=@CXXOPTIMISE_FLAG@
CXXFLAGS+=@CXXDEBUG_FLAG@ CXXFLAGS+=@CXXDEBUG_FLAG@
INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning INCLUDES+=-I$(TOP_BUILDDIR) -I$(TOP_DIR) -I$(TOP_DIR)/thin-provisioning
LIBS:=-lstdc++ -laio LIBS:=-lstdc++ -laio -lexpat
LIBEXPAT:=-lexpat
INSTALL:=@INSTALL@ INSTALL:=@INSTALL@
PREFIX:=@prefix@ PREFIX:=@prefix@
BINDIR:=$(DESTDIR)$(PREFIX)/sbin BINDIR:=$(DESTDIR)$(PREFIX)/sbin
@ -153,14 +119,6 @@ endif
.SUFFIXES: .d .SUFFIXES: .d
%.o: %.c
@echo " [CC] $<"
$(V) $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
@echo " [DEP] $<"
$(V) $(CC) -MM -MT $(subst .c,.o,$<) $(INCLUDES) $(CFLAGS) $< > $*.$$$$; \
sed 's,\([^ :]*\)\.o[ :]*,\1.o \1.gmo $* : Makefile ,g' < $*.$$$$ > $*.d; \
$(RM) $*.$$$$
%.o: %.cc %.o: %.cc
@echo " [CXX] $<" @echo " [CXX] $<"
$(V) $(CXX) -c $(INCLUDES) $(CXXFLAGS) -o $@ $< $(V) $(CXX) -c $(INCLUDES) $(CXXFLAGS) -o $@ $<
@ -171,334 +129,14 @@ endif
#---------------------------------------------------------------- #----------------------------------------------------------------
lib/libpdata.a: $(PDATA_OBJECTS) lib/libpdata.a: $(OBJECTS)
@echo " [AR] $<" @echo " [AR] $<"
$(V)ar -rv $@ $(PDATA_OBJECTS) > /dev/null 2>&1 $(V)ar -rv $@ $(OBJECTS) > /dev/null 2>&1
#---------------------------------------------------------------- bin/pdata_tools: $(OBJECTS)
# Thin provisioning tools
THIN_DEBUG_SOURCE=$(SOURCE)
THIN_DUMP_SOURCE=$(SOURCE)
THIN_REPAIR_SOURCE=$(SOURCE)
THIN_RESTORE_SOURCE=$(SOURCE)
THIN_CHECK_SOURCE=\
block-cache/block_cache.cc \
\
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
\
thin-provisioning/device_tree.cc \
thin-provisioning/mapping_tree.cc \
thin-provisioning/metadata.cc \
thin-provisioning/metadata_checker.cc \
thin-provisioning/superblock.cc
THIN_DELTA_SOURCE=\
block-cache/block_cache.cc \
\
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
\
thin-provisioning/device_tree.cc \
thin-provisioning/mapping_tree.cc \
thin-provisioning/metadata.cc \
thin-provisioning/metadata_checker.cc \
thin-provisioning/superblock.cc
THIN_RMAP_SOURCE=\
block-cache/block_cache.cc \
\
base/endian_utils.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
thin-provisioning/device_tree.cc \
thin-provisioning/mapping_tree.cc \
thin-provisioning/metadata.cc \
thin-provisioning/metadata_checker.cc \
thin-provisioning/rmap_visitor.cc \
thin-provisioning/superblock.cc
THIN_DEBUG_OBJECTS=$(subst .cc,.o,$(THIN_DEBUG_SOURCE))
THIN_DUMP_OBJECTS=$(subst .cc,.o,$(THIN_DUMP_SOURCE))
THIN_REPAIR_OBJECTS=$(subst .cc,.o,$(THIN_REPAIR_SOURCE))
THIN_RESTORE_OBJECTS=$(subst .cc,.o,$(THIN_RESTORE_SOURCE))
THIN_CHECK_OBJECTS=$(subst .cc,.o,$(THIN_CHECK_SOURCE))
THIN_DELTA_OBJECTS=$(subst .cc,.o,$(THIN_DELTA_SOURCE))
THIN_RMAP_OBJECTS=$(subst .cc,.o,$(THIN_RMAP_SOURCE))
thin_debug: $(THIN_DEBUG_OBJECTS) thin-provisioning/thin_debug.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_repair: $(THIN_REPAIR_OBJECTS) thin-provisioning/thin_repair.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_dump: $(THIN_DUMP_OBJECTS) thin-provisioning/thin_dump.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_restore: $(THIN_RESTORE_OBJECTS) thin-provisioning/thin_restore.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_check: $(THIN_CHECK_OBJECTS) thin-provisioning/thin_check.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_delta: $(THIN_DELTA_OBJECTS) thin-provisioning/thin_delta.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
thin_rmap: $(THIN_RMAP_OBJECTS) thin-provisioning/thin_rmap.o
@echo " [LD] $@" @echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS)
thin_metadata_size: thin-provisioning/thin_metadata_size.o
@echo " [LD] $@"
$(V) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $+ -lm
#----------------------------------------------------------------
# Cache tools
CACHE_CHECK_SOURCE=\
block-cache/block_cache.cc \
\
base/base64.cc \
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/data-structures/bitset.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
\
caching/hint_array.cc \
caching/superblock.cc \
caching/mapping_array.cc \
caching/metadata.cc \
caching/metadata_dump.cc \
caching/restore_emitter.cc \
caching/xml_format.cc
CACHE_CHECK_OBJECTS=$(subst .cc,.o,$(CACHE_CHECK_SOURCE))
CACHE_DUMP_SOURCE=$(SOURCE)
CACHE_DUMP_OBJECTS=$(subst .cc,.o,$(CACHE_DUMP_SOURCE))
CACHE_REPAIR_SOURCE=$(SOURCE)
CACHE_REPAIR_OBJECTS=$(subst .cc,.o,$(CACHE_REPAIR_SOURCE))
CACHE_RESTORE_SOURCE=$(SOURCE)
CACHE_RESTORE_OBJECTS=$(subst .cc,.o,$(CACHE_RESTORE_SOURCE))
cache_check: $(CACHE_CHECK_OBJECTS) caching/cache_check.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
cache_dump: $(CACHE_DUMP_OBJECTS) caching/cache_dump.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
cache_repair: $(CACHE_REPAIR_OBJECTS) caching/cache_repair.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
cache_restore: $(CACHE_RESTORE_OBJECTS) caching/cache_restore.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
cache_metadata_size: caching/cache_metadata_size.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS)
#----------------------------------------------------------------
# Era tools
ERA_CHECK_SOURCE=\
block-cache/block_cache.cc \
\
base/base64.cc \
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
era/writeset_tree.cc \
era/era_detail.cc \
era/era_array.cc \
era/metadata.cc \
era/superblock.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/data-structures/bitset.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
ERA_CHECK_OBJECTS=$(subst .cc,.o,$(ERA_CHECK_SOURCE))
era_check: $(ERA_CHECK_OBJECTS) era/era_check.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
ERA_DUMP_SOURCE=\
block-cache/block_cache.cc \
\
base/base64.cc \
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
era/writeset_tree.cc \
era/era_detail.cc \
era/era_array.cc \
era/metadata.cc \
era/metadata_dump.cc \
era/superblock.cc \
era/xml_format.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/data-structures/bitset.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
ERA_DUMP_OBJECTS=$(subst .cc,.o,$(ERA_DUMP_SOURCE))
era_dump: $(ERA_DUMP_OBJECTS) era/era_dump.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
ERA_INVALIDATE_SOURCE=\
block-cache/block_cache.cc \
\
base/base64.cc \
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
era/writeset_tree.cc \
era/era_detail.cc \
era/era_array.cc \
era/metadata.cc \
era/metadata_dump.cc \
era/superblock.cc \
era/xml_format.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/data-structures/bitset.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
ERA_INVALIDATE_OBJECTS=$(subst .cc,.o,$(ERA_INVALIDATE_SOURCE))
era_invalidate: $(ERA_INVALIDATE_OBJECTS) era/era_invalidate.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
ERA_RESTORE_SOURCE=\
block-cache/block_cache.cc \
\
base/base64.cc \
base/error_state.cc \
base/endian_utils.cc \
base/progress_monitor.cc \
base/xml_utils.cc \
\
era/writeset_tree.cc \
era/era_detail.cc \
era/era_array.cc \
era/metadata.cc \
era/metadata_dump.cc \
era/restore_emitter.cc \
era/superblock.cc \
era/xml_format.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \
persistent-data/file_utils.cc \
persistent-data/hex_dump.cc \
persistent-data/data-structures/btree.cc \
persistent-data/data-structures/bitset.cc \
persistent-data/space_map.cc \
persistent-data/space-maps/disk.cc \
persistent-data/space-maps/recursive.cc \
persistent-data/space-maps/careful_alloc.cc \
persistent-data/transaction_manager.cc \
ERA_RESTORE_OBJECTS=$(subst .cc,.o,$(ERA_RESTORE_SOURCE))
era_restore: $(ERA_RESTORE_OBJECTS) era/era_restore.o
@echo " [LD] $@"
$(V) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $+ $(LIBS) $(LIBEXPAT)
#---------------------------------------------------------------- #----------------------------------------------------------------
DEPEND_FILES=\ DEPEND_FILES=\
@ -518,21 +156,24 @@ clean:
distclean: clean distclean: clean
$(RM) config.cache config.log config.status configure.h version.h Makefile unit-tests/Makefile $(RM) config.cache config.log config.status configure.h version.h Makefile unit-tests/Makefile
install: $(PROGRAMS) install: bin/pdata_tools
$(INSTALL_DIR) $(BINDIR) $(INSTALL_DIR) $(BINDIR)
$(INSTALL_PROGRAM) cache_check $(BINDIR) $(INSTALL_PROGRAM) bin/pdata_tools $(BINDIR)
$(INSTALL_PROGRAM) cache_dump $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/cache_check
$(INSTALL_PROGRAM) cache_repair $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/cache_dump
$(INSTALL_PROGRAM) cache_restore $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/cache_metadata_size
$(INSTALL_PROGRAM) thin_check $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/cache_repair
$(INSTALL_PROGRAM) thin_dump $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/cache_restore
$(INSTALL_PROGRAM) thin_repair $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_check
$(INSTALL_PROGRAM) thin_restore $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_dump
$(INSTALL_PROGRAM) thin_rmap $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_repair
$(INSTALL_PROGRAM) thin_metadata_size $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_restore
$(INSTALL_PROGRAM) era_check $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_rmap
$(INSTALL_PROGRAM) era_dump $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/thin_metadata_size
$(INSTALL_PROGRAM) era_invalidate $(BINDIR) ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/era_check
ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/era_dump
ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/era_invalidate
ln -s -f $(BINDIR)/pdata_tools $(BINDIR)/era_restore
$(INSTALL_DIR) $(MANPATH)/man8 $(INSTALL_DIR) $(MANPATH)/man8
$(INSTALL_DATA) man8/cache_check.8 $(MANPATH)/man8 $(INSTALL_DATA) man8/cache_check.8 $(MANPATH)/man8
$(INSTALL_DATA) man8/cache_dump.8 $(MANPATH)/man8 $(INSTALL_DATA) man8/cache_dump.8 $(MANPATH)/man8
@ -548,6 +189,8 @@ install: $(PROGRAMS)
$(INSTALL_DATA) man8/era_dump.8 $(MANPATH)/man8 $(INSTALL_DATA) man8/era_dump.8 $(MANPATH)/man8
$(INSTALL_DATA) man8/era_invalidate.8 $(MANPATH)/man8 $(INSTALL_DATA) man8/era_invalidate.8 $(MANPATH)/man8
# $(INSTALL_DATA) man8/era_restore.8 $(MANPATH)/man8
.PHONY: install .PHONY: install
ifeq ("@TESTING@", "yes") ifeq ("@TESTING@", "yes")
@ -555,7 +198,7 @@ include unit-tests/Makefile
.PHONEY: features .PHONEY: features
features: $(PROGRAMS) features: pdata_tools
cucumber --no-color --format progress cucumber --no-color --format progress
test: features unit-test test: features unit-test

62
base/application.cc Normal file
View File

@ -0,0 +1,62 @@
#include "base/application.h"
#include <linux/limits.h>
#include <string.h>
using namespace base;
using namespace std;
//----------------------------------------------------------------
int
application::run(int argc, char **argv)
{
string cmd = basename(argv[0]);
if (cmd == string("pdata-tools")) {
argc--;
argv++;
if (!argc) {
usage();
return 1;
}
cmd = argv[0];
}
std::list<command const *>::const_iterator it;
for (it = cmds_.begin(); it != cmds_.end(); ++it) {
if (cmd == (*it)->get_name())
return (*it)->run(argc, argv);
}
std::cerr << "Unknown command '" << cmd << "'\n";
usage();
return 1;
}
void
application::usage()
{
std::cerr << "Usage: <command> <args>\n"
<< "commands:\n";
std::list<command const *>::const_iterator it;
for (it = cmds_.begin(); it != cmds_.end(); ++it) {
std::cerr << " " << (*it)->get_name() << "\n";
}
}
std::string
application::basename(std::string const &path) const
{
char buffer[PATH_MAX + 1];
memset(buffer, 0, sizeof(buffer));
strncpy(buffer, path.c_str(), PATH_MAX);
return ::basename(buffer);
}
//----------------------------------------------------------------

52
base/application.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef BASE_APPLICATION_H
#define BASE_APPLICATION_H
#include <iostream>
#include <list>
#include <string>
#include <stdexcept>
//----------------------------------------------------------------
namespace base {
class command {
public:
typedef int (*cmd_fn)(int, char **);
command(std::string const &name, cmd_fn fn)
: name_(name),
fn_(fn) {
}
std::string const &get_name() const {
return name_;
}
int run(int argc, char **argv) const {
return fn_(argc, argv);
}
private:
std::string name_;
cmd_fn fn_;
};
class application {
public:
void add_cmd(command const &c) {
cmds_.push_back(&c);
}
int run(int argc, char **argv);
private:
void usage();
std::string basename(std::string const &path) const;
std::list<command const *> cmds_;
};
}
//----------------------------------------------------------------
#endif

1
bin/cache_check Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/cache_dump Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/cache_metadata_size Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/cache_repair Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/cache_restore Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/era_check Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/era_dump Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/era_invalidate Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/era_restore Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_check Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_delta Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_dump Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_metadata_size Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_repair Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_restore Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

1
bin/thin_rmap Symbolic link
View File

@ -0,0 +1 @@
pdata_tools

View File

@ -14,6 +14,7 @@
#include "base/error_state.h" #include "base/error_state.h"
#include "base/nested_output.h" #include "base/nested_output.h"
#include "caching/commands.h"
#include "caching/metadata.h" #include "caching/metadata.h"
#include "persistent-data/block.h" #include "persistent-data/block.h"
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
@ -322,7 +323,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int cache_check_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -384,4 +385,6 @@ int main(int argc, char **argv)
return check_with_exception_handling(argv[optind], fs); return check_with_exception_handling(argv[optind], fs);
} }
base::command caching::cache_check_cmd("cache_check", cache_check_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include "version.h" #include "version.h"
#include "caching/commands.h"
#include "caching/mapping_array.h" #include "caching/mapping_array.h"
#include "caching/metadata.h" #include "caching/metadata.h"
#include "caching/metadata_dump.h" #include "caching/metadata_dump.h"
@ -66,7 +67,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int cache_dump_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -114,4 +115,6 @@ int main(int argc, char **argv)
return dump(argv[optind], output, fs); return dump(argv[optind], output, fs);
} }
base::command caching::cache_dump_cmd("cache_dump", cache_dump_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -1,5 +1,7 @@
#include "version.h" #include "version.h"
#include "caching/commands.h"
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <iostream> #include <iostream>
@ -132,7 +134,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int cache_metadata_size_main(int argc, char **argv)
{ {
flags fs; flags fs;
@ -156,4 +158,6 @@ int main(int argc, char **argv)
return 0; return 0;
} }
base::command caching::cache_metadata_size_cmd("cache_metadata_size", cache_metadata_size_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -2,6 +2,7 @@
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include "caching/commands.h"
#include "caching/metadata.h" #include "caching/metadata.h"
#include "caching/metadata_dump.h" #include "caching/metadata_dump.h"
#include "caching/restore_emitter.h" #include "caching/restore_emitter.h"
@ -52,7 +53,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int cache_repair_main(int argc, char **argv)
{ {
int c; int c;
boost::optional<string> input_path, output_path; boost::optional<string> input_path, output_path;
@ -105,4 +106,6 @@ int main(int argc, char **argv)
return repair(*input_path, *output_path); return repair(*input_path, *output_path);
} }
base::command caching::cache_repair_cmd("cache_repair", cache_repair_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -1,5 +1,6 @@
#include "version.h" #include "version.h"
#include "caching/commands.h"
#include "caching/metadata.h" #include "caching/metadata.h"
#include "caching/restore_emitter.h" #include "caching/restore_emitter.h"
#include "caching/xml_format.h" #include "caching/xml_format.h"
@ -95,7 +96,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int cache_restore_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -169,4 +170,6 @@ int main(int argc, char **argv)
return restore(fs); return restore(fs);
} }
base::command caching::cache_restore_cmd("cache_restore", cache_restore_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

18
caching/commands.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef CACHING_COMMANDS_H
#define CACHING_COMMANDS_H
#include "base/application.h"
//----------------------------------------------------------------
namespace caching {
extern base::command cache_check_cmd;
extern base::command cache_dump_cmd;
extern base::command cache_metadata_size_cmd;
extern base::command cache_restore_cmd;
extern base::command cache_repair_cmd;
}
//----------------------------------------------------------------
#endif

17
era/commands.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ERA_COMMANDS_H
#define ERA_COMMANDS_H
#include "base/application.h"
//----------------------------------------------------------------
namespace era {
extern base::command era_check_cmd;
extern base::command era_dump_cmd;
extern base::command era_invalidate_cmd;
extern base::command era_restore_cmd;
}
//----------------------------------------------------------------
#endif

View File

@ -14,6 +14,7 @@
#include "base/error_state.h" #include "base/error_state.h"
#include "base/nested_output.h" #include "base/nested_output.h"
#include "era/commands.h"
#include "era/writeset_tree.h" #include "era/writeset_tree.h"
#include "era/era_array.h" #include "era/era_array.h"
#include "era/superblock.h" #include "era/superblock.h"
@ -276,7 +277,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int era_check_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -322,4 +323,6 @@ int main(int argc, char **argv)
return check_with_exception_handling(argv[optind], fs); return check_with_exception_handling(argv[optind], fs);
} }
base::command era::era_check_cmd("era_check", era_check_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include "version.h" #include "version.h"
#include "era/commands.h"
#include "era/era_array.h" #include "era/era_array.h"
#include "era/writeset_tree.h" #include "era/writeset_tree.h"
#include "era/metadata.h" #include "era/metadata.h"
@ -70,7 +71,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int era_dump_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -123,4 +124,6 @@ int main(int argc, char **argv)
return dump(argv[optind], output, fs); return dump(argv[optind], output, fs);
} }
base::command era::era_dump_cmd("era_dump", era_dump_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -5,6 +5,7 @@
#include "version.h" #include "version.h"
#include "base/indented_stream.h" #include "base/indented_stream.h"
#include "era/commands.h"
#include "era/era_array.h" #include "era/era_array.h"
#include "era/writeset_tree.h" #include "era/writeset_tree.h"
#include "era/metadata.h" #include "era/metadata.h"
@ -189,7 +190,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int era_invalidate_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -248,4 +249,6 @@ int main(int argc, char **argv)
return invalidate(argv[optind], output, fs); return invalidate(argv[optind], output, fs);
} }
base::command era::era_invalidate_cmd("era_invalidate", era_invalidate_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -1,5 +1,6 @@
#include "version.h" #include "version.h"
#include "era/commands.h"
#include "era/metadata.h" #include "era/metadata.h"
#include "era/restore_emitter.h" #include "era/restore_emitter.h"
#include "era/xml_format.h" #include "era/xml_format.h"
@ -57,7 +58,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int era_restore_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -120,4 +121,6 @@ int main(int argc, char **argv)
return restore(fs, fs.quiet); return restore(fs, fs.quiet);
} }
base::command era::era_restore_cmd("era_restore", era_restore_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -1,4 +1,4 @@
Feature: thin_restore Feature: cache_restore
Scenario: print version (-V flag) Scenario: print version (-V flag)
When I run cache_restore with -V When I run cache_restore with -V
Then it should pass with version Then it should pass with version
@ -84,15 +84,15 @@ Feature: thin_restore
Then it should pass Then it should pass
Scenario: --quiet is accepted Scenario: --quiet is accepted
Given valid metadata Given valid cache metadata
When I run thin_restore with -i metadata.xml -o metadata.bin --quiet When I run cache_restore with -i metadata.xml -o metadata.bin --quiet
Then it should pass with: Then it should pass with:
""" """
""" """
Scenario: -q is accepted Scenario: -q is accepted
Given valid metadata Given valid cache metadata
When I run thin_restore with -i metadata.xml -o metadata.bin -q When I run cache_restore with -i metadata.xml -o metadata.bin -q
Then it should pass with: Then it should pass with:
""" """
""" """

View File

@ -1,4 +1,4 @@
Feature: thin_restore Feature: era_restore
Scenario: print version (-V flag) Scenario: print version (-V flag)
When I run era_restore with -V When I run era_restore with -V
Then it should pass with version Then it should pass with version
@ -67,15 +67,15 @@ Feature: thin_restore
And the metadata should be valid And the metadata should be valid
Scenario: --quiet is accepted Scenario: --quiet is accepted
Given valid metadata Given valid era metadata
When I run thin_restore with -i metadata.xml -o metadata.bin --quiet When I run era_restore with -i metadata.xml -o metadata.bin --quiet
Then it should pass with: Then it should pass with:
""" """
""" """
Scenario: -q is accepted Scenario: -q is accepted
Given valid metadata Given valid era metadata
When I run thin_restore with -i metadata.xml -o metadata.bin -q When I run era_restore with -i metadata.xml -o metadata.bin -q
Then it should pass with: Then it should pass with:
""" """
""" """

View File

@ -29,3 +29,11 @@ Then(/^the metadata should be valid$/) do
run_simple("era_check #{dev_file}", true) run_simple("era_check #{dev_file}", true)
end end
Given(/^valid era metadata$/) do
in_current_dir do
system("era_xml create --nr-blocks 100 --nr-writesets 2 --current-era 1000 > #{xml_file}")
end
run_simple("dd if=/dev/zero of=#{dev_file} bs=4k count=1024")
run_simple("era_restore -i #{xml_file} -o #{dev_file}")
end

View File

@ -1,4 +1,4 @@
Given(/^valid metadata$/) do Given(/^valid thin metadata$/) do
in_current_dir do in_current_dir do
system("thinp_xml create --nr-thins uniform[4..9] --nr-mappings uniform[1000..10000] > #{xml_file}") system("thinp_xml create --nr-thins uniform[4..9] --nr-mappings uniform[1000..10000] > #{xml_file}")
end end
@ -58,7 +58,7 @@ Then(/^dumps ([0-9]+) and ([0-9]+) should be identical$/) do |d1, d2|
run_simple("diff -ub #{dump_files[d1.to_i]} #{dump_files[d2.to_i]}", true) run_simple("diff -ub #{dump_files[d1.to_i]} #{dump_files[d2.to_i]}", true)
end end
Given(/^small metadata$/) do Given(/^small thin metadata$/) do
in_current_dir do in_current_dir do
system("thinp_xml create --nr-thins 2 --nr-mappings 1 > #{xml_file}") system("thinp_xml create --nr-thins 2 --nr-mappings 1 > #{xml_file}")
end end

View File

@ -1,3 +1,3 @@
require 'aruba/cucumber' require 'aruba/cucumber'
ENV['PATH'] = "#{Dir::pwd}:#{ENV['PATH']}" ENV['PATH'] = "#{Dir::pwd}/bin:#{ENV['PATH']}"

View File

@ -44,7 +44,7 @@ Feature: thin_check
Then it should fail Then it should fail
Scenario: --super-block-only check passes on valid metadata Scenario: --super-block-only check passes on valid metadata
Given valid metadata Given valid thin metadata
When I run thin_check with --super-block-only When I run thin_check with --super-block-only
Then it should pass Then it should pass
@ -59,12 +59,12 @@ Feature: thin_check
""" """
Scenario: --skip-mappings check passes on valid metadata Scenario: --skip-mappings check passes on valid metadata
Given valid metadata Given valid thin metadata
When I run thin_check with --skip-mappings When I run thin_check with --skip-mappings
Then it should pass Then it should pass
Scenario: --ignore-non-fatal-errors check passes on valid metadata Scenario: --ignore-non-fatal-errors check passes on valid metadata
Given valid metadata Given valid thin metadata
When I run thin_check with --ignore-non-fatal-errors When I run thin_check with --ignore-non-fatal-errors
Then it should pass Then it should pass
@ -81,6 +81,6 @@ Feature: thin_check
And it should give no output And it should give no output
Scenario: Accepts --clear-needs-check-flag Scenario: Accepts --clear-needs-check-flag
Given valid metadata Given valid thin metadata
When I run thin_check with --clear-needs-check-flag When I run thin_check with --clear-needs-check-flag
Then it should pass Then it should pass

View File

@ -56,32 +56,32 @@ Feature: thin_restore
""" """
Scenario: --quiet is accepted Scenario: --quiet is accepted
Given valid metadata Given valid thin metadata
When I run thin_restore with -i metadata.xml -o metadata.bin --quiet When I run thin_restore with -i metadata.xml -o metadata.bin --quiet
Then it should pass with: Then it should pass with:
""" """
""" """
Scenario: -q is accepted Scenario: -q is accepted
Given valid metadata Given valid thin metadata
When I run thin_restore with -i metadata.xml -o metadata.bin -q When I run thin_restore with -i metadata.xml -o metadata.bin -q
Then it should pass with: Then it should pass with:
""" """
""" """
Scenario: dump/restore is a noop Scenario: dump/restore is a noop
Given valid metadata Given valid thin metadata
When I dump When I dump
And I restore And I restore
And I dump And I dump
Then dumps 1 and 2 should be identical Then dumps 1 and 2 should be identical
Scenario: dump matches original metadata Scenario: dump matches original metadata
Given valid metadata Given valid thin metadata
When I dump When I dump
Then dumps 0 and 1 should be identical Then dumps 0 and 1 should be identical
Scenario: dump matches original metadata (small) Scenario: dump matches original metadata (small)
Given small metadata Given small thin metadata
When I dump When I dump
Then dumps 0 and 1 should be identical Then dumps 0 and 1 should be identical

View File

@ -42,56 +42,56 @@ Feature: thin_rmap
@announce @announce
Scenario: Valid region format should pass Scenario: Valid region format should pass
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 23..7890 When I run thin_rmap with --region 23..7890
Then it should pass Then it should pass
Scenario: Invalid region format should fail (comma instean of dots) Scenario: Invalid region format should fail (comma instean of dots)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 23,7890 When I run thin_rmap with --region 23,7890
Then it should fail Then it should fail
Scenario: Invalid region format should fail (second number a word) Scenario: Invalid region format should fail (second number a word)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 23..six When I run thin_rmap with --region 23..six
Then it should fail Then it should fail
Scenario: Invalid region format should fail (first number a word) Scenario: Invalid region format should fail (first number a word)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region four..7890 When I run thin_rmap with --region four..7890
Then it should fail Then it should fail
Scenario: Invalid region format should fail (end is lower than begin) Scenario: Invalid region format should fail (end is lower than begin)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 89..88 When I run thin_rmap with --region 89..88
Then it should fail Then it should fail
Scenario: Invalid region format should fail (end is equal to begin) Scenario: Invalid region format should fail (end is equal to begin)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 89..89 When I run thin_rmap with --region 89..89
Then it should fail Then it should fail
Scenario: Invalid region format should fail (no begin) Scenario: Invalid region format should fail (no begin)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region ..89 When I run thin_rmap with --region ..89
Then it should fail Then it should fail
Scenario: Invalid region format should fail (no end) Scenario: Invalid region format should fail (no end)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 89.. When I run thin_rmap with --region 89..
Then it should fail Then it should fail
Scenario: Invalid region format should fail (no region at all) Scenario: Invalid region format should fail (no region at all)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region When I run thin_rmap with --region
Then it should fail Then it should fail
Scenario: Invalid region format should fail (three dots) Scenario: Invalid region format should fail (three dots)
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 89...99 When I run thin_rmap with --region 89...99
Then it should fail Then it should fail
Scenario: Multiple regions should pass Scenario: Multiple regions should pass
Given valid metadata Given valid thin metadata
When I run thin_rmap with --region 1..23 --region 45..78 When I run thin_rmap with --region 1..23 --region 45..78
Then it should pass Then it should pass

42
main.cc Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include "base/application.h"
#include "caching/commands.h"
#include "era/commands.h"
#include "thin-provisioning/commands.h"
//----------------------------------------------------------------
int main(int argc, char **argv)
{
using namespace base;
application app;
app.add_cmd(caching::cache_check_cmd);
app.add_cmd(caching::cache_dump_cmd);
app.add_cmd(caching::cache_metadata_size_cmd);
app.add_cmd(caching::cache_restore_cmd);
app.add_cmd(caching::cache_repair_cmd);
app.add_cmd(era::era_check_cmd);
app.add_cmd(era::era_dump_cmd);
app.add_cmd(era::era_invalidate_cmd);
app.add_cmd(era::era_restore_cmd);
app.add_cmd(thin_provisioning::thin_check_cmd);
app.add_cmd(thin_provisioning::thin_delta_cmd);
app.add_cmd(thin_provisioning::thin_dump_cmd);
app.add_cmd(thin_provisioning::thin_metadata_size_cmd);
app.add_cmd(thin_provisioning::thin_restore_cmd);
app.add_cmd(thin_provisioning::thin_repair_cmd);
app.add_cmd(thin_provisioning::thin_rmap_cmd);
// FIXME: convert thin_metadata_size to c++
//app.add_cmd(thin_provisioning::thin_metadata_size_cmd);
return app.run(argc, argv);
}
//----------------------------------------------------------------

View File

@ -0,0 +1,21 @@
#ifndef THIN_PROVISIONING_COMMANDS_H
#define THIN_PROVISIONING_COMMANDS_H
#include "base/application.h"
//----------------------------------------------------------------
namespace thin_provisioning {
extern base::command thin_check_cmd;
extern base::command thin_delta_cmd;
extern base::command thin_dump_cmd;
extern base::command thin_metadata_size_cmd;
extern base::command thin_restore_cmd;
extern base::command thin_repair_cmd;
extern base::command thin_rmap_cmd;
extern base::command thin_metadata_size_cmd;
}
//----------------------------------------------------------------
#endif

View File

@ -22,6 +22,7 @@
#include "version.h" #include "version.h"
#include "base/application.h"
#include "base/error_state.h" #include "base/error_state.h"
#include "base/nested_output.h" #include "base/nested_output.h"
#include "persistent-data/space-maps/core.h" #include "persistent-data/space-maps/core.h"
@ -29,6 +30,7 @@
#include "thin-provisioning/device_tree.h" #include "thin-provisioning/device_tree.h"
#include "thin-provisioning/mapping_tree.h" #include "thin-provisioning/mapping_tree.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "thin-provisioning/commands.h"
using namespace base; using namespace base;
using namespace std; using namespace std;
@ -272,7 +274,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int thin_check_main(int argc, char **argv)
{ {
int c; int c;
flags fs; flags fs;
@ -342,3 +344,7 @@ int main(int argc, char **argv)
return check(argv[optind], fs); return check(argv[optind], fs);
} }
base::command thin_provisioning::thin_check_cmd("thin_check", thin_check_main);
//----------------------------------------------------------------

View File

@ -12,13 +12,14 @@
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "thin-provisioning/mapping_tree.h" #include "thin-provisioning/mapping_tree.h"
#include "thin-provisioning/commands.h"
using namespace std; using namespace std;
using namespace thin_provisioning; using namespace thin_provisioning;
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace { namespace local {
class application { class application {
public: public:
application(string const &cmd) application(string const &cmd)
@ -503,11 +504,13 @@ namespace {
// FIXME: add metadata snap switch // FIXME: add metadata snap switch
int main(int argc, char **argv) int thin_delta_main(int argc, char **argv)
{ {
using namespace local;
int c; int c;
flags fs; flags fs;
application app(basename(argv[0])); local::application app(basename(argv[0]));
char const shortopts[] = "hV"; char const shortopts[] = "hV";
option const longopts[] = { option const longopts[] = {
@ -565,4 +568,6 @@ int main(int argc, char **argv)
return delta(app, fs); return delta(app, fs);
} }
base::command thin_provisioning::thin_delta_cmd("thin_delta", thin_delta_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -26,6 +26,7 @@
#include "metadata.h" #include "metadata.h"
#include "xml_format.h" #include "xml_format.h"
#include "version.h" #include "version.h"
#include "thin-provisioning/commands.h"
using namespace persistent_data; using namespace persistent_data;
using namespace std; using namespace std;
@ -95,7 +96,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int thin_dump_main(int argc, char **argv)
{ {
int c; int c;
char const *output = NULL; char const *output = NULL;
@ -165,3 +166,7 @@ int main(int argc, char **argv)
return dump(argv[optind], output, format, flags, metadata_snap); return dump(argv[optind], output, format, flags, metadata_snap);
} }
base::command thin_provisioning::thin_dump_cmd("thin_dump", thin_dump_main);
//----------------------------------------------------------------

View File

@ -23,6 +23,8 @@
* *
*/ */
#include "thin-provisioning/commands.h"
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <math.h> #include <math.h>
@ -38,8 +40,13 @@
enum numeric_options { BLOCKSIZE, POOLSIZE, MAXTHINS, NUMERIC, OPT_END}; enum numeric_options { BLOCKSIZE, POOLSIZE, MAXTHINS, NUMERIC, OPT_END};
enum return_units { RETURN_BYTES, RETURN_SECTORS }; enum return_units { RETURN_BYTES, RETURN_SECTORS };
enum numeric_type { NO_NUMBER, NUMBER, NUMBER_SHORT, NUMBER_LONG }; enum numeric_type { NO_NUMBER, NUMBER, NUMBER_SHORT, NUMBER_LONG };
typedef unsigned bool;
enum bool_value { false = 0, true = 1}; struct options_ {
unsigned unit_idx;
char *s[OPT_END];
unsigned long long n[OPT_END];
};
struct global { struct global {
char *prg; /* program name */ char *prg; /* program name */
@ -51,11 +58,7 @@ struct global {
} unit; } unit;
/* Command line option properties. */ /* Command line option properties. */
struct options { options_ options;
unsigned unit_idx;
char *s[OPT_END];
unsigned long long n[OPT_END];
} options;
}; };
static void exit_prg(struct global *g, int ret) static void exit_prg(struct global *g, int ret)
@ -80,7 +83,7 @@ static void abort_prg(struct global *g, const char *msg)
exit_prg(g, 1); exit_prg(g, 1);
} }
static int unit_index(struct global *g, char *unit_string) static int unit_index(struct global *g, char const *unit_string)
{ {
unsigned len; unsigned len;
@ -109,14 +112,14 @@ static int unit_index(struct global *g, char *unit_string)
static struct global *init_prg(char *prg_path) static struct global *init_prg(char *prg_path)
{ {
unsigned u; unsigned u;
static char *unit_chars = "bskKmMgGtTpPeEzZyY"; static char const *unit_chars = "bskKmMgGtTpPeEzZyY";
static char *unit_strings[] = { "bytes", "sectors", static char const *unit_strings[] = { "bytes", "sectors",
"kibibytes", "kilobytes", "mebibytes", "megabytes", "kibibytes", "kilobytes", "mebibytes", "megabytes",
"gibibytes", "gigabytes", "tebibytes", "terabytes", "gibibytes", "gigabytes", "tebibytes", "terabytes",
"pebibytes", "petabytes", "ebibytes", "exabytes", "pebibytes", "petabytes", "ebibytes", "exabytes",
"zebibytes", "zetabytes", "yobibytes", "yottabytes", NULL }; "zebibytes", "zetabytes", "yobibytes", "yottabytes", NULL };
static unsigned long long unit_factors[ARRAY_SIZE(unit_strings) - 1] = { 1, 512, 1024, 1000 }; static unsigned long long unit_factors[ARRAY_SIZE(unit_strings) - 1] = { 1, 512, 1024, 1000 };
struct global *r = malloc(sizeof(*r)); struct global *r = static_cast<global *>(malloc(sizeof(*r)));
if (!r) if (!r)
abort_prg(r, "failed to allocate global context!"); abort_prg(r, "failed to allocate global context!");
@ -129,8 +132,8 @@ static struct global *init_prg(char *prg_path)
} }
r->prg = basename(prg_path); r->prg = basename(prg_path);
r->unit.chars = unit_chars; r->unit.chars = const_cast<char *>(unit_chars);
r->unit.strings = unit_strings; r->unit.strings = const_cast<char **>(unit_strings);
r->unit.factors = unit_factors; r->unit.factors = unit_factors;
r->options.unit_idx = unit_index(r, NULL); r->options.unit_idx = unit_index(r, NULL);
@ -144,7 +147,7 @@ static unsigned long long bytes_per_sector(struct global *g)
static void check_opts(struct global *g) static void check_opts(struct global *g)
{ {
struct options *o = &g->options; options_ *o = &g->options;
if (!o->n[BLOCKSIZE]) if (!o->n[BLOCKSIZE])
abort_prg(g, "block size required!"); abort_prg(g, "block size required!");
@ -183,7 +186,7 @@ static unsigned long long to_bytes(struct global *g, char *sz, enum return_units
return (!us || unit == RETURN_SECTORS) ? r / bytes_per_sector(g) : r; return (!us || unit == RETURN_SECTORS) ? r / bytes_per_sector(g) : r;
} }
static void printf_aligned(struct global *g, char *a, char *b, char *c, bool units, bool mandatory) static void printf_aligned(struct global *g, char const *a, char const *b, char const *c, bool units, bool mandatory)
{ {
char buf[80]; char buf[80];
@ -254,7 +257,7 @@ static void check_size(struct global *g, enum numeric_options o, char *arg)
idx = g->options.unit_idx; idx = g->options.unit_idx;
} }
g->options.s[o] = malloc(strlen(arg) + strlen(g->unit.strings[idx]) + 1); g->options.s[o] = static_cast<char *>(malloc(strlen(arg) + strlen(g->unit.strings[idx]) + 1));
if (!g->options.s[o]) if (!g->options.s[o])
abort_prg(g, "failed to allocate string!"); abort_prg(g, "failed to allocate string!");
@ -359,7 +362,7 @@ static void print_estimated_result(struct global *g)
print_precision(g, r, g->options.unit_idx); print_precision(g, r, g->options.unit_idx);
} }
int main(int argc, char **argv) int thin_metadata_size_main(int argc, char **argv)
{ {
struct global *g = init_prg(*argv); struct global *g = init_prg(*argv);
@ -368,3 +371,5 @@ int main(int argc, char **argv)
exit_prg(g, 0); exit_prg(g, 0);
return 0; /* Doesn't get here... */ return 0; /* Doesn't get here... */
} }
base::command thin_provisioning::thin_metadata_size_cmd("thin_metadata_size", thin_metadata_size_main);

View File

@ -2,6 +2,7 @@
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include "thin-provisioning/commands.h"
#include "human_readable_format.h" #include "human_readable_format.h"
#include "metadata_dumper.h" #include "metadata_dumper.h"
#include "metadata.h" #include "metadata.h"
@ -40,7 +41,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int thin_repair_main(int argc, char **argv)
{ {
int c; int c;
boost::optional<string> input_path, output_path; boost::optional<string> input_path, output_path;
@ -92,3 +93,7 @@ int main(int argc, char **argv)
return repair(*input_path, *output_path); return repair(*input_path, *output_path);
} }
base::command thin_provisioning::thin_repair_cmd("thin_repair", thin_repair_main);
//----------------------------------------------------------------

View File

@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
#include "thin-provisioning/commands.h"
#include "thin-provisioning/emitter.h" #include "thin-provisioning/emitter.h"
#include "thin-provisioning/human_readable_format.h" #include "thin-provisioning/human_readable_format.h"
#include "thin-provisioning/metadata.h" #include "thin-provisioning/metadata.h"
@ -68,7 +69,7 @@ namespace {
} }
} }
int main(int argc, char **argv) int thin_restore_main(int argc, char **argv)
{ {
int c; int c;
char const *prog_name = basename(argv[0]); char const *prog_name = basename(argv[0]);
@ -132,4 +133,6 @@ int main(int argc, char **argv)
return restore(input, output, quiet); return restore(input, output, quiet);
} }
base::command thin_provisioning::thin_restore_cmd("thin_restore", thin_restore_main);
//---------------------------------------------------------------- //----------------------------------------------------------------

View File

@ -10,6 +10,7 @@
#include "persistent-data/run.h" #include "persistent-data/run.h"
#include "persistent-data/space-maps/core.h" #include "persistent-data/space-maps/core.h"
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
#include "thin-provisioning/commands.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "thin-provisioning/mapping_tree.h" #include "thin-provisioning/mapping_tree.h"
#include "thin-provisioning/rmap_visitor.h" #include "thin-provisioning/rmap_visitor.h"
@ -125,7 +126,7 @@ namespace {
//---------------------------------------------------------------- //----------------------------------------------------------------
int main(int argc, char **argv) int thin_rmap_main(int argc, char **argv)
{ {
int c; int c;
vector<region> regions; vector<region> regions;
@ -174,4 +175,6 @@ int main(int argc, char **argv)
return rmap(argv[optind], regions); return rmap(argv[optind], regions);
} }
base::command thin_provisioning::thin_rmap_cmd("thin_rmap", thin_rmap_main);
//---------------------------------------------------------------- //----------------------------------------------------------------