From: Loic Dachary Date: Sun, 17 May 2015 15:53:55 +0000 (+0200) Subject: erasure-code: ErasureCode default value is a string X-Git-Tag: v9.0.2~78^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4b3ba2abc4eb94bf09422090d6b6c357fced1fb9;p=ceph.git erasure-code: ErasureCode default value is a string The to_int, to_bool prototypes are modified and the default values are changed to string instead of int. If a default value is set, the profile is modified to contain the default value. The to_string helper is added so it can be used to set the default value of a string, in a way that is consistent with to_int and to_bool. http://tracker.ceph.com/issues/9589 Fixes: #9589 Signed-off-by: Loic Dachary --- diff --git a/src/erasure-code/ErasureCode.cc b/src/erasure-code/ErasureCode.cc index 29d920c66690..570677d19cc3 100644 --- a/src/erasure-code/ErasureCode.cc +++ b/src/erasure-code/ErasureCode.cc @@ -197,14 +197,12 @@ int ErasureCode::to_mapping(const ErasureCodeProfile &profile, int ErasureCode::to_int(const std::string &name, ErasureCodeProfile &profile, int *value, - int default_value, + const std::string &default_value, ostream *ss) { if (profile.find(name) == profile.end() || - profile.find(name)->second.size() == 0) { - *value = default_value; - return 0; - } + profile.find(name)->second.size() == 0) + profile[name] = default_value; std::string p = profile.find(name)->second; std::string err; int r = strict_strtol(p.c_str(), 10, &err); @@ -212,7 +210,7 @@ int ErasureCode::to_int(const std::string &name, *ss << "could not convert " << name << "=" << p << " to int because " << err << ", set to default " << default_value << std::endl; - *value = default_value; + *value = strict_strtol(default_value.c_str(), 10, &err); return -EINVAL; } *value = r; @@ -222,19 +220,30 @@ int ErasureCode::to_int(const std::string &name, int ErasureCode::to_bool(const std::string &name, ErasureCodeProfile &profile, bool *value, - bool default_value, + const std::string &default_value, ostream *ss) { if (profile.find(name) == profile.end() || - profile.find(name)->second.size() == 0) { - *value = default_value; - return 0; - } + profile.find(name)->second.size() == 0) + profile[name] = default_value; const std::string p = profile.find(name)->second; *value = (p == "yes") || (p == "true"); return 0; } +int ErasureCode::to_string(const std::string &name, + ErasureCodeProfile &profile, + std::string *value, + const std::string &default_value, + ostream *ss) +{ + if (profile.find(name) == profile.end() || + profile.find(name)->second.size() == 0) + profile[name] = default_value; + *value = profile[name]; + return 0; +} + int ErasureCode::decode_concat(const map &chunks, bufferlist *decoded) { diff --git a/src/erasure-code/ErasureCode.h b/src/erasure-code/ErasureCode.h index 2d61fa59967c..8622e7b79909 100644 --- a/src/erasure-code/ErasureCode.h +++ b/src/erasure-code/ErasureCode.h @@ -77,15 +77,21 @@ namespace ceph { static int to_int(const std::string &name, ErasureCodeProfile &profile, int *value, - int default_value, + const std::string &default_value, ostream *ss); static int to_bool(const std::string &name, ErasureCodeProfile &profile, bool *value, - bool default_value, + const std::string &default_value, ostream *ss); + static int to_string(const std::string &name, + ErasureCodeProfile &profile, + std::string *value, + const std::string &default_value, + ostream *ss); + virtual int decode_concat(const map &chunks, bufferlist *decoded);