erasure-code: implement get_profile for every plugins

The ErasureCode::init function is implemented to store the profile and
is called by the init method of each plugin. The
ErasureCode::get_profile function is implemented to return the profile
that was stored. A specialized ostream<< function is implemented to
facilitate the display of the profile.

Signed-off-by: Loic Dachary <ldachary@redhat.com>
This commit is contained in:
Loic Dachary 2015-06-01 19:50:05 +02:00
parent 0f2c556796
commit 77e5330da1
9 changed files with 32 additions and 5 deletions

View File

@ -33,9 +33,19 @@ namespace ceph {
static const unsigned SIMD_ALIGN;
vector<int> chunk_mapping;
ErasureCodeProfile _profile;
virtual ~ErasureCode() {}
virtual int init(ErasureCodeProfile &profile, ostream *ss) {
_profile = profile;
return 0;
}
virtual const ErasureCodeProfile &get_profile() const {
return _profile;
}
virtual unsigned int get_coding_chunk_count() const {
return get_chunk_count() - get_data_chunk_count();
}

View File

@ -153,6 +153,20 @@ using namespace std;
namespace ceph {
typedef map<std::string,std::string> ErasureCodeProfile;
inline ostream& operator<<(ostream& out, const ErasureCodeProfile& profile) {
out << "{";
for (ErasureCodeProfile::const_iterator it = profile.begin();
it != profile.end();
++it) {
if (it != profile.begin()) out << ",";
out << it->first << "=" << it->second;
}
out << "}";
return out;
}
class ErasureCodeInterface {
public:
virtual ~ErasureCodeInterface() {}

View File

@ -80,6 +80,7 @@ ErasureCodeIsa::init(ErasureCodeProfile &profile, ostream *ss)
if (err)
return err;
prepare();
ErasureCode::init(profile, ss);
return err;
}

View File

@ -67,6 +67,7 @@ int ErasureCodeJerasure::init(ErasureCodeProfile& profile, ostream *ss)
if (err)
return err;
prepare();
ErasureCode::init(profile, ss);
return err;
}

View File

@ -534,6 +534,7 @@ int ErasureCodeLrc::init(ErasureCodeProfile &profile,
profile.erase("mapping");
profile.erase("layers");
}
ErasureCode::init(profile, ss);
return 0;
}

View File

@ -68,6 +68,7 @@ int ErasureCodeShec::init(ErasureCodeProfile &profile,
if (err)
return err;
prepare();
ErasureCode::init(profile, ss);
return err;
}

View File

@ -39,10 +39,6 @@ class ErasureCodeExample : public ErasureCode {
public:
virtual ~ErasureCodeExample() {}
virtual int init(ErasureCodeProfile &profile, ostream *ss) {
return 0;
}
virtual int create_ruleset(const string &name,
CrushWrapper &crush,
ostream *ss) const {

View File

@ -28,6 +28,7 @@ public:
ostream *ss)
{
*erasure_code = ErasureCodeInterfaceRef(new ErasureCodeExample());
(*erasure_code)->init(profile, ss);
return 0;
}
};

View File

@ -35,7 +35,9 @@ ceph_erasure_code_LDADD += -ldl
endif
bin_DEBUGPROGRAMS += ceph_erasure_code
libec_example_la_SOURCES = test/erasure-code/ErasureCodePluginExample.cc
libec_example_la_SOURCES = \
erasure-code/ErasureCode.cc \
test/erasure-code/ErasureCodePluginExample.cc
test/erasure-code/ErasureCodePluginExample.cc: ./ceph_ver.h
libec_example_la_CFLAGS = ${AM_CFLAGS}
libec_example_la_CXXFLAGS= ${AM_CXXFLAGS}