]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: helper for pool properties parsing
authorLoic Dachary <loic@dachary.org>
Sat, 1 Feb 2014 09:09:12 +0000 (10:09 +0100)
committerLoic Dachary <loic@dachary.org>
Tue, 4 Feb 2014 07:06:25 +0000 (08:06 +0100)
Add the prepare_pool_properties to convert the properties vector into a
properties map suitable for either initializing the pg_pool_t member or
an erasure code plugin.

Reviewed-By: Christophe Courtaut <christophe.courtaut@gmail.com>
Signed-off-by: Loic Dachary <loic@dachary.org>
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index c85a88c5f2b280a25c79f623df7c7ab62de75895..3614cadb3e101e4f66658a0e8bf5ca448f9d34a6 100644 (file)
@@ -2742,6 +2742,38 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
                             properties, pg_pool_t::TYPE_REPLICATED, ss);
 }
 
+int OSDMonitor::prepare_pool_properties(const unsigned pool_type,
+                                       const vector<string> &properties,
+                                       map<string,string> *properties_map,
+                                       stringstream &ss)
+{
+  if (pool_type == pg_pool_t::TYPE_ERASURE) {
+    int r = get_str_map(g_conf->osd_pool_default_erasure_code_properties,
+                       ss,
+                       properties_map);
+    if (r)
+      return r;
+    (*properties_map)["erasure-code-directory"] =
+      g_conf->osd_pool_default_erasure_code_directory;
+  }
+
+  for (vector<string>::const_iterator i = properties.begin();
+       i != properties.end();
+       ++i) {
+    size_t equal = i->find('=');
+    if (equal == string::npos)
+      (*properties_map)[*i] = string();
+    else {
+      const string key = i->substr(0, equal);
+      equal++;
+      const string value = i->substr(equal);
+      (*properties_map)[key] = value;
+    }
+  }
+
+  return 0;
+}
+
 /**
  * @param name The name of the new pool
  * @param auid The auid of the pool owner. Can be -1
@@ -2760,17 +2792,10 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
                                  const unsigned pool_type,
                                 stringstream &ss)
 {
-  map<string,string> default_properties;
-  if (pool_type == pg_pool_t::TYPE_ERASURE) {
-    int r = get_str_map(g_conf->osd_pool_default_erasure_code_properties,
-                       ss,
-                       &default_properties);
-    if (r)
-      return r;
-    default_properties["erasure-code-directory"] =
-      g_conf->osd_pool_default_erasure_code_directory;
-  }
-
+  map<string,string> properties_map;
+  int r = prepare_pool_properties(pool_type, properties, &properties_map, ss);
+  if (r)
+    return r;
   for (map<int64_t,string>::iterator p = pending_inc.new_pool_names.begin();
        p != pending_inc.new_pool_names.end();
        ++p) {
@@ -2808,20 +2833,7 @@ int OSDMonitor::prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
   pi->set_pgp_num(pgp_num ? pgp_num : g_conf->osd_pool_default_pgp_num);
   pi->last_change = pending_inc.epoch;
   pi->auid = auid;
-  pi->properties = default_properties;
-  for (vector<string>::const_iterator i = properties.begin();
-       i != properties.end();
-       ++i) {
-    size_t equal = i->find('=');
-    if (equal == string::npos)
-      pi->properties[*i] = string();
-    else {
-      const string key = i->substr(0, equal);
-      equal++;
-      const string value = i->substr(equal);
-      pi->properties[key] = value;
-    }
-  }
+  pi->properties = properties_map;
   pending_inc.new_pool_names[pool] = name;
   return 0;
 }
index 81ea4320d151fb0262d54fd9749b652ef10e6151..cabd680f5318064ba29d06f03af3079e4203c48f 100644 (file)
@@ -236,6 +236,10 @@ private:
   bool prepare_pool_op (MPoolOp *m);
   bool prepare_pool_op_create (MPoolOp *m);
   bool prepare_pool_op_delete(MPoolOp *m);
+  int prepare_pool_properties(const unsigned pool_type,
+                             const vector<string> &properties,
+                             map<string,string> *properties_map,
+                             stringstream &ss);
   int prepare_new_pool(string& name, uint64_t auid, int crush_ruleset,
                        unsigned pg_num, unsigned pgp_num,
                       const vector<string> &properties,