]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon, crush: add mode to "osd crush rule create-simple ..."
authorSage Weil <sage@inktank.com>
Mon, 4 Nov 2013 11:12:45 +0000 (03:12 -0800)
committerSage Weil <sage@inktank.com>
Tue, 3 Dec 2013 22:41:25 +0000 (14:41 -0800)
Add a mode (firstn or indep) to the create-simple command.  Make it
optional and default to firstn (for compatiblity and simplicity).

Note: a "default=..." option for mon commands would be easier.

Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h
src/mon/MonCommands.h
src/mon/OSDMonitor.cc

index 9c3783029ea68b78538eee84b59e167e22beb6e2..923e8c457d73be9081db13a8f86e96c441a73f0f 100644 (file)
@@ -647,7 +647,9 @@ void CrushWrapper::reweight(CephContext *cct)
   }
 }
 
-int CrushWrapper::add_simple_rule(string name, string root_name, string failure_domain_name,
+int CrushWrapper::add_simple_rule(string name, string root_name,
+                                 string failure_domain_name,
+                                 string mode,
                                  ostream *err)
 {
   if (rule_exists(name)) {
@@ -670,6 +672,11 @@ int CrushWrapper::add_simple_rule(string name, string root_name, string failure_
       return -EINVAL;
     }
   }
+  if (mode != "firstn" && mode != "indep") {
+    if (err)
+      *err << "unknown mode " << mode;
+    return -EINVAL;
+  }
 
   int ruleset = 0;
   for (int i = 0; i < get_max_rules(); i++) {
@@ -684,12 +691,14 @@ int CrushWrapper::add_simple_rule(string name, string root_name, string failure_
   crush_rule_set_step(rule, 0, CRUSH_RULE_TAKE, root, 0);
   if (type)
     crush_rule_set_step(rule, 1,
-                       CRUSH_RULE_CHOOSE_LEAF_FIRSTN,
+                       mode == "firstn" ? CRUSH_RULE_CHOOSE_LEAF_FIRSTN :
+                       CRUSH_RULE_CHOOSE_LEAF_INDEP,
                        CRUSH_CHOOSE_N,
                        type);
   else
     crush_rule_set_step(rule, 1,
-                       CRUSH_RULE_CHOOSE_FIRSTN,
+                       mode == "firstn" ? CRUSH_RULE_CHOOSE_FIRSTN :
+                       CRUSH_RULE_CHOOSE_INDEP,
                        CRUSH_CHOOSE_N,
                        0);
   crush_rule_set_step(rule, 2, CRUSH_RULE_EMIT, 0, 0);
index c4ef1040d57aeb3f3deafccc86d14265e76d9d13..dec61b4d3fa25b2b17e527665ecca2a0671430d7 100644 (file)
@@ -580,7 +580,7 @@ public:
   }
 
   int add_simple_rule(string name, string root_name, string failure_domain_type,
-                     ostream *err = 0);
+                     string mode, ostream *err = 0);
 
   int remove_rule(int ruleno);
 
index 1f72dfcb9fd0121acb2f1cc3744e1f0395db6e4e..73805c82e4fe6e1c35b895e58ab2f4b84b7c41f5 100644 (file)
@@ -432,8 +432,9 @@ COMMAND("osd crush tunables " \
 COMMAND("osd crush rule create-simple " \
        "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] " \
        "name=root,type=CephString,goodchars=[A-Za-z0-9-_.] " \
-       "name=type,type=CephString,goodchars=[A-Za-z0-9-_.]",
-       "create crush rule <name> to 'take' from bucket <root> and 'chooseleaf_first' a bucket <type>", \
+       "name=type,type=CephString,goodchars=[A-Za-z0-9-_.] " \
+       "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 rm " \
        "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] ",  \
index 47f1c82d3cb65668939e1ae82e37f92f2ee8702c..f59756303cef153f2710699db98c8b05bd4106d0 100644 (file)
@@ -3377,10 +3377,13 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
     return true;
 
   } else if (prefix == "osd crush rule create-simple") {
-    string name, root, type;
+    string name, root, type, mode;
     cmd_getval(g_ceph_context, cmdmap, "name", name);
     cmd_getval(g_ceph_context, cmdmap, "root", root);
     cmd_getval(g_ceph_context, cmdmap, "type", type);
+    cmd_getval(g_ceph_context, cmdmap, "mode", mode);
+    if (mode == "")
+      mode = "firstn";
 
     if (osdmap.crush->rule_exists(name)) {
       ss << "rule " << name << " already exists";
@@ -3395,7 +3398,7 @@ bool OSDMonitor::prepare_command(MMonCommand *m)
       ss << "rule " << name << " already exists";
       err = 0;
     } else {
-      int rule = newcrush.add_simple_rule(name, root, type, &ss);
+      int rule = newcrush.add_simple_rule(name, root, type, mode, &ss);
       if (rule < 0) {
        err = rule;
        goto reply;