Put error_state into into it's own file.

This commit is contained in:
Joe Thornber 2013-08-16 14:07:04 +01:00
parent 94bd3aef3b
commit 67551d81f1
5 changed files with 48 additions and 31 deletions

View File

@ -29,7 +29,11 @@ PROGRAMS=\
all: $(PROGRAMS) all: $(PROGRAMS)
PDATA_SOURCE=\ SOURCE=\
base/error_state.cc \
\
caching/superblock.cc \
\
persistent-data/checksum.cc \ persistent-data/checksum.cc \
persistent-data/endian_utils.cc \ persistent-data/endian_utils.cc \
persistent-data/error_set.cc \ persistent-data/error_set.cc \
@ -42,13 +46,7 @@ PDATA_SOURCE=\
persistent-data/space_map.cc \ persistent-data/space_map.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-maps/careful_alloc.cc \
#PDATA_OBJECTS=$(subst .cc,.o,$(PDATA_SOURCE))
SOURCE=\
$(PDATA_SOURCE) \
\
caching/superblock.cc \
\ \
thin-provisioning/device_tree.cc \ thin-provisioning/device_tree.cc \
thin-provisioning/file_utils.cc \ thin-provisioning/file_utils.cc \
@ -66,7 +64,7 @@ SOURCE=\
PDATA_OBJECTS=$(subst .cc,.o,$(SOURCE)) PDATA_OBJECTS=$(subst .cc,.o,$(SOURCE))
CXX_PROGRAM_SOURCE=\ CXX_PROGRAM_SOURCE=\
caching/check.cc \ caching/cache_check.cc \
\ \
thin-provisioning/thin_check.cc \ thin-provisioning/thin_check.cc \
thin-provisioning/thin_dump.cc \ thin-provisioning/thin_dump.cc \
@ -140,6 +138,7 @@ THIN_DUMP_SOURCE=$(SOURCE)
THIN_REPAIR_SOURCE=$(SOURCE) THIN_REPAIR_SOURCE=$(SOURCE)
THIN_RESTORE_SOURCE=$(SOURCE) THIN_RESTORE_SOURCE=$(SOURCE)
THIN_CHECK_SOURCE=\ THIN_CHECK_SOURCE=\
base/error_state.cc \
persistent-data/checksum.cc \ persistent-data/checksum.cc \
persistent-data/endian_utils.cc \ persistent-data/endian_utils.cc \
persistent-data/error_set.cc \ persistent-data/error_set.cc \

19
base/error_state.cc Normal file
View File

@ -0,0 +1,19 @@
#include "base/error_state.h"
//----------------------------------------------------------------
base::error_state
base::combine_errors(error_state lhs, error_state rhs) {
switch (lhs) {
case NO_ERROR:
return rhs;
case NON_FATAL:
return (rhs == FATAL) ? FATAL : lhs;
default:
return lhs;
}
}
//----------------------------------------------------------------

18
base/error_state.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef BASE_ERROR_STATE_H
#define BASE_ERROR_STATE_H
//----------------------------------------------------------------
namespace base {
enum error_state {
NO_ERROR,
NON_FATAL, // eg, lost blocks
FATAL // needs fixing before pool can be activated
};
error_state combine_errors(error_state lhs, error_state rhs);
}
//----------------------------------------------------------------
#endif

View File

@ -22,6 +22,7 @@
#include "version.h" #include "version.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"
#include "thin-provisioning/device_tree.h" #include "thin-provisioning/device_tree.h"
@ -29,33 +30,13 @@
#include "thin-provisioning/mapping_tree.h" #include "thin-provisioning/mapping_tree.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
using namespace base;
using namespace std; using namespace std;
using namespace thin_provisioning; using namespace thin_provisioning;
//---------------------------------------------------------------- //----------------------------------------------------------------
namespace { namespace {
enum error_state {
NO_ERROR,
NON_FATAL, // eg, lost blocks
FATAL // needs fixing before pool can be activated
};
error_state
combine_errors(error_state lhs, error_state rhs) {
switch (lhs) {
case NO_ERROR:
return rhs;
case NON_FATAL:
return (rhs == FATAL) ? FATAL : lhs;
default:
return lhs;
}
}
//-------------------------------- //--------------------------------
block_manager<>::ptr block_manager<>::ptr
@ -91,7 +72,7 @@ namespace {
err_ = combine_errors(err_, FATAL); err_ = combine_errors(err_, FATAL);
} }
error_state get_error() const { base::error_state get_error() const {
return err_; return err_;
} }