From 395eba9b38e8f8e301910531dc2934c6e4cfed69 Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 17 May 2015 18:08:31 +0200 Subject: [PATCH] erasure-code: ErasureCodeLrc update default values to string Update the ErasureCodeLrc::init function to use string default values and update the profile accordingly. If the k,m,l values are set and generate mappings and layers entries, those are not stored in the profile. The details of what k,m,l create are private and not exposed to the caller. http://tracker.ceph.com/issues/9589 Fixes: #9589 Signed-off-by: Loic Dachary --- src/erasure-code/lrc/ErasureCodeLrc.cc | 42 ++++++++++++++++++-------- src/erasure-code/lrc/ErasureCodeLrc.h | 2 ++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/erasure-code/lrc/ErasureCodeLrc.cc b/src/erasure-code/lrc/ErasureCodeLrc.cc index 41a9c3400e857..56a6412efd92d 100644 --- a/src/erasure-code/lrc/ErasureCodeLrc.cc +++ b/src/erasure-code/lrc/ErasureCodeLrc.cc @@ -279,21 +279,23 @@ int ErasureCodeLrc::parse(ErasureCodeProfile &profile, return parse_ruleset(profile, ss); } +const string ErasureCodeLrc::DEFAULT_KML("-1"); + int ErasureCodeLrc::parse_kml(ErasureCodeProfile &profile, ostream *ss) { int err = ErasureCode::parse(profile, ss); - const int DEFAULT = -1; + const int DEFAULT_INT = -1; int k, m, l; - err |= to_int("k", profile, &k, DEFAULT, ss); - err |= to_int("m", profile, &m, DEFAULT, ss); - err |= to_int("l", profile, &l, DEFAULT, ss); + err |= to_int("k", profile, &k, DEFAULT_KML, ss); + err |= to_int("m", profile, &m, DEFAULT_KML, ss); + err |= to_int("l", profile, &l, DEFAULT_KML, ss); - if (k == DEFAULT && m == DEFAULT && l == DEFAULT) - return 0; + if (k == DEFAULT_INT && m == DEFAULT_INT && l == DEFAULT_INT) + return err; - if ((k != DEFAULT || m != DEFAULT || l != DEFAULT) && - (k == DEFAULT || m == DEFAULT || l == DEFAULT)) { + if ((k != DEFAULT_INT || m != DEFAULT_INT || l != DEFAULT_INT) && + (k == DEFAULT_INT || m == DEFAULT_INT || l == DEFAULT_INT)) { *ss << "All of k, m, l must be set or none of them in " << profile << std::endl; return ERROR_LRC_ALL_OR_NOTHING; @@ -388,10 +390,10 @@ int ErasureCodeLrc::parse_kml(ErasureCodeProfile &profile, int ErasureCodeLrc::parse_ruleset(ErasureCodeProfile &profile, ostream *ss) { - ErasureCodeProfile::const_iterator parameter; - parameter = profile.find("ruleset-root"); - if (parameter != profile.end()) - ruleset_root = parameter->second; + int err = 0; + err |= to_string("ruleset-root", profile, + &ruleset_root, + "default", ss); if (profile.count("ruleset-steps") != 0) { ruleset_steps.clear(); @@ -518,7 +520,21 @@ int ErasureCodeLrc::init(ErasureCodeProfile &profile, } chunk_count = mapping.length(); - return layers_sanity_checks(description_string, ss); + r = layers_sanity_checks(description_string, ss); + if (r) + return r; + + // + // When initialized with kml, the profile parameters + // that were generated should not be stored because + // they would otherwise be exposed to the caller. + // + if (profile.find("l") != profile.end() && + profile.find("l")->second != DEFAULT_KML) { + profile.erase("mapping"); + profile.erase("layers"); + } + return 0; } set ErasureCodeLrc::get_erasures(const set &want, diff --git a/src/erasure-code/lrc/ErasureCodeLrc.h b/src/erasure-code/lrc/ErasureCodeLrc.h index 221c1676fd69b..0dbbde9b6c25a 100644 --- a/src/erasure-code/lrc/ErasureCodeLrc.h +++ b/src/erasure-code/lrc/ErasureCodeLrc.h @@ -46,6 +46,8 @@ class ErasureCodeLrc : public ErasureCode { public: + static const string DEFAULT_KML; + struct Layer { Layer(string _chunks_map) : chunks_map(_chunks_map) { } ErasureCodeInterfaceRef erasure_code; -- 2.39.5