]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: osd crush rule create-erasure
authorLoic Dachary <loic@dachary.org>
Sun, 26 Jan 2014 17:52:50 +0000 (18:52 +0100)
committerLoic Dachary <loic@dachary.org>
Tue, 4 Feb 2014 07:06:26 +0000 (08:06 +0100)
Delegates the creation of the rule to the erasure code plugin associated
with the specified pool.

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

index bff1f2e7b5aeece54d2dde7f6a99b62620c07990..39191d1d55e5929a735c1d80fdaf592aa8ac204d 100644 (file)
@@ -434,6 +434,11 @@ COMMAND("osd crush rule create-simple " \
        "name=mode,type=CephChoices,strings=firstn|indep,req=false",
        "create crush rule <name> to start from <root>, replicate across buckets of type <type>, using a choose mode of <firstn|indep> (default firstn; indep best for erasure pools)", \
        "osd", "rw", "cli,rest")
+COMMAND("osd crush rule create-erasure " \
+       "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] " \
+       "name=properties,type=CephString,n=N,req=false,goodchars=[A-Za-z0-9-_.=]", \
+       "create crush rule <name> suitable for erasure coded pool created with <properties>", \
+       "osd", "rw", "cli,rest")
 COMMAND("osd crush rule rm " \
        "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] ",  \
        "remove crush rule <name>", "osd", "rw", "cli,rest")
index 597f9f6cecc20ba8a32812478c8ee43100e9490f..b481a5809c666fed72f915a7de3953702f3240d2 100644 (file)
@@ -44,6 +44,8 @@
 #include "common/config.h"
 #include "common/errno.h"
 
+#include "osd/ErasureCodePlugin.h"
+
 #include "include/compat.h"
 #include "include/assert.h"
 #include "include/stringify.h"
@@ -3639,6 +3641,55 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
                                              get_last_committed() + 1));
     return true;
 
+  } else if (prefix == "osd crush rule create-erasure") {
+    string name, poolstr;
+    cmd_getval(g_ceph_context, cmdmap, "name", name);
+    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;
+      goto reply;
+    } 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));
+    return true;
+
   } else if (prefix == "osd crush rule rm") {
     string name;
     cmd_getval(g_ceph_context, cmdmap, "name", name);