]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: create crush_ruleset_create_erasure helper
authorLoic Dachary <loic@dachary.org>
Mon, 3 Mar 2014 13:36:50 +0000 (14:36 +0100)
committerLoic Dachary <loic@dachary.org>
Mon, 17 Mar 2014 08:48:02 +0000 (09:48 +0100)
Move the code bloc verbatim, from "osd crush rule create-erasure" to the
new crush_ruleset_create_erasure() method helper. This step helps
separate the code changes from the code moving around unmodified.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/mon/OSDMonitor.cc
src/mon/OSDMonitor.h

index 7733809ffbdf427691e9df0301ad26592800dce3..beb92a9a3203c980f0208e73fa7ee6b25d88589a 100644 (file)
@@ -2807,6 +2807,44 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
                             properties, pg_pool_t::TYPE_REPLICATED, ss);
 }
 
+int OSDMonitor::crush_ruleset_create_erasure(const string &name,
+                                            const map<string,string> &properties,
+                                            int *ruleset,
+                                            stringstream &ss)
+{
+    if (osdmap.crush->rule_exists(name)) {
+      ss << "rule " << name << " already exists";
+      err = 0;
+      goto reply;
+    }
+
+    CrushWrapper newcrush;
+    _get_pending_crush(newcrush);
+
+    if (newcrush.rule_exists(name)) {
+      ss << "rule " << name << " already exists";
+      err = 0;
+    } else {
+      ErasureCodeInterfaceRef erasure_code;
+      err = get_erasure_code(properties_map, &erasure_code, ss);
+      if (err) {
+       ss << "failed to load plugin using properties " << properties_map;
+       goto reply;
+      }
+
+      int rule = erasure_code->create_ruleset(name, newcrush, &ss);
+      erasure_code.reset();
+      if (rule < 0) {
+       err = rule;
+       goto reply;
+      }
+      ss << "created rule " << name << " at " << rule;
+      pending_inc.crush.clear();
+      newcrush.encode(pending_inc.crush);
+    }
+
+}
+
 int OSDMonitor::get_erasure_code(const map<string,string> &properties,
                                 ErasureCodeInterfaceRef *erasure_code,
                                 stringstream &ss)
@@ -3860,43 +3898,12 @@ bool OSDMonitor::prepare_command_impl(MMonCommand *m,
     vector<string> properties;
     cmd_getval(g_ceph_context, cmdmap, "properties", properties);
 
-    if (osdmap.crush->rule_exists(name)) {
-      ss << "rule " << name << " already exists";
-      err = 0;
-      goto reply;
-    }
-
     map<string,string> properties_map;
     err = prepare_pool_properties(pg_pool_t::TYPE_ERASURE,
                                  properties, &properties_map, ss);
     if (err)
       goto reply;
 
-    CrushWrapper newcrush;
-    _get_pending_crush(newcrush);
-
-    if (newcrush.rule_exists(name)) {
-      ss << "rule " << name << " already exists";
-      err = 0;
-    } else {
-      ErasureCodeInterfaceRef erasure_code;
-      err = get_erasure_code(properties_map, &erasure_code, ss);
-      if (err) {
-       ss << "failed to load plugin using properties " << properties_map;
-       goto reply;
-      }
-
-      int rule = erasure_code->create_ruleset(name, newcrush, &ss);
-      erasure_code.reset();
-      if (rule < 0) {
-       err = rule;
-       goto reply;
-      }
-      ss << "created rule " << name << " at " << rule;
-      pending_inc.crush.clear();
-      newcrush.encode(pending_inc.crush);
-    }
-
     getline(ss, rs);
     wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs,
                                                       get_last_committed() + 1));
index 8a87374739b0bda5396efc65133142b937635da0..4734549f6347810ec5d3ee8711df4be1655055fc 100644 (file)
@@ -240,6 +240,10 @@ private:
   bool prepare_pool_op (MPoolOp *m);
   bool prepare_pool_op_create (MPoolOp *m);
   bool prepare_pool_op_delete(MPoolOp *m);
+  int crush_ruleset_create_erasure(const string &name,
+                                  const map<string,string> &properties,
+                                  int *ruleset,
+                                  stringstream &ss);
   int get_erasure_code(const map<string,string> &properties,
                       ErasureCodeInterfaceRef *erasure_code,
                       stringstream &ss);