]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: ErasureCode default value is a string
authorLoic Dachary <ldachary@redhat.com>
Sun, 17 May 2015 15:53:55 +0000 (17:53 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sat, 30 May 2015 22:01:34 +0000 (00:01 +0200)
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 <ldachary@redhat.com>
src/erasure-code/ErasureCode.cc
src/erasure-code/ErasureCode.h

index 29d920c66690d4125cede846a8cfee4a9664f49a..570677d19cc3a501e196d505194e5f0c0e52a7d3 100644 (file)
@@ -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<int, bufferlist> &chunks,
                               bufferlist *decoded)
 {
index 2d61fa59967cc49f96754f23415c635cff089d6d..8622e7b79909dc8f30eb3342327d3da0a0620787 100644 (file)
@@ -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<int, bufferlist> &chunks,
                              bufferlist *decoded);