]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: ErasureCodeLrc update default values to string
authorLoic Dachary <ldachary@redhat.com>
Sun, 17 May 2015 16:08:31 +0000 (18:08 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sat, 30 May 2015 22:01:34 +0000 (00:01 +0200)
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 <ldachary@redhat.com>
src/erasure-code/lrc/ErasureCodeLrc.cc
src/erasure-code/lrc/ErasureCodeLrc.h

index 41a9c3400e857d2e50af293419792d1bdc3ccd2d..56a6412efd92d42b36624799eb715b3cf037d247 100644 (file)
@@ -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<int> ErasureCodeLrc::get_erasures(const set<int> &want,
index 221c1676fd69b88ff267dfebc84cdf1012c33d2d..0dbbde9b6c25ad24a7671a119736da3d91339f8a 100644 (file)
@@ -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;