]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/OSDMonitor: add location option for "crush add-bucket" command 17125/head
authorxie xingguo <xie.xingguo@zte.com.cn>
Mon, 21 Aug 2017 09:04:27 +0000 (17:04 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Tue, 22 Aug 2017 02:39:03 +0000 (10:39 +0800)
So we can combine "crush add-bucket" with "crush move" command,
and hence avoid making two separate changes to the osdmap,
and hence slow down map-epoch generation.

Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
qa/workunits/mon/crush_ops.sh
src/mon/MonCommands.h
src/mon/OSDMonitor.cc
src/test/pybind/test_ceph_argparse.py

index 1ef6e5cc1eddd7fbba9758890d7719201c72deb1..d720349c3d1efd8196fe41b4b22bfbeebaf82a76 100755 (executable)
@@ -78,6 +78,14 @@ ceph osd tree | grep -c host1 | grep -q 0
 expect_false ceph osd crush rm bar   # not empty
 ceph osd crush unlink host2
 
+ceph osd crush add-bucket host-for-test host root=root-for-test rack=rack-for-test
+ceph osd tree | grep host-for-test
+ceph osd tree | grep rack-for-test
+ceph osd tree | grep root-for-test
+ceph osd crush rm host-for-test
+ceph osd crush rm rack-for-test
+ceph osd crush rm root-for-test
+
 # reference foo and bar with a rule
 ceph osd crush rule create-simple foo-rule foo host firstn
 expect_false ceph osd crush rm foo
index b0aeff8ed10b854e1bf9bd8af87110b3dfb51974..82df7de3bc3c82efeb8a4d6e6ef7a1b3fa2c1187 100644 (file)
@@ -524,8 +524,10 @@ COMMAND("osd crush set name=prior_version,type=CephInt,req=false", \
        "osd", "rw", "cli,rest")
 COMMAND("osd crush add-bucket " \
        "name=name,type=CephString,goodchars=[A-Za-z0-9-_.] " \
-       "name=type,type=CephString", \
-       "add no-parent (probably root) crush bucket <name> of type <type>", \
+        "name=type,type=CephString " \
+        "name=args,type=CephString,n=N,goodchars=[A-Za-z0-9-_.=],req=false", \
+       "add no-parent (probably root) crush bucket <name> of type <type> " \
+        "to location <args>", \
        "osd", "rw", "cli,rest")
 COMMAND("osd crush rename-bucket " \
        "name=srcname,type=CephString,goodchars=[A-Za-z0-9-_.] " \
index 164899aed2e6d0098cd3f96af8e1c5bab3522541..0bb9b87da71f97377c987aa252ad2c2bcee0f492 100644 (file)
@@ -7578,8 +7578,16 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
   } else if (prefix == "osd crush add-bucket") {
     // os crush add-bucket <name> <type>
     string name, typestr;
+    vector<string> argvec;
     cmd_getval(g_ceph_context, cmdmap, "name", name);
     cmd_getval(g_ceph_context, cmdmap, "type", typestr);
+    cmd_getval(g_ceph_context, cmdmap, "args", argvec);
+    map<string,string> loc;
+    if (!argvec.empty()) {
+      CrushWrapper::parse_loc_map(argvec, &loc);
+      dout(0) << "will create and move bucket '" << name
+              << "' to location " << loc << dendl;
+    }
 
     if (!_have_pending_crush() &&
        _get_stable_crush().name_exists(name)) {
@@ -7619,10 +7627,29 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op,
       goto reply;
     }
 
+    if (!loc.empty()) {
+      if (!newcrush.check_item_loc(g_ceph_context, bucketno, loc,
+          (int *)NULL)) {
+        err = newcrush.move_bucket(g_ceph_context, bucketno, loc);
+        if (err < 0) {
+          ss << "error moving bucket '" << name << "' to location " << loc;
+          goto reply;
+        }
+      } else {
+        ss << "no need to move item id " << bucketno << " name '" << name
+           << "' to location " << loc << " in crush map";
+      }
+    }
+
     pending_inc.crush.clear();
     newcrush.encode(pending_inc.crush, mon->get_quorum_con_features());
-    ss << "added bucket " << name << " type " << typestr
-       << " to crush map";
+    if (loc.empty()) {
+      ss << "added bucket " << name << " type " << typestr
+         << " to crush map";
+    } else {
+      ss << "added bucket " << name << " type " << typestr
+         << " to location " << loc;
+    }
     goto update;
   } else if (prefix == "osd crush rename-bucket") {
     string srcname, dstname;
index bc9f2d929fc9f5e77232edc604b2b01f3f32934a..9759b87d73dfa739330e5ce69c22b020422bc5a1 100755 (executable)
@@ -613,13 +613,11 @@ class TestOSD(TestArgparse):
     def test_crush_add_bucket(self):
         self.assert_valid_command(['osd', 'crush', 'add-bucket',
                                    'name', 'type'])
+        self.assert_valid_command(['osd', 'crush', 'add-bucket',
+                                   'name', 'type', 'root=foo-root', 'host=foo-host'])
         assert_equal({}, validate_command(sigdict, ['osd', 'crush']))
         assert_equal({}, validate_command(sigdict, ['osd', 'crush',
                                                     'add-bucket']))
-        assert_equal({}, validate_command(sigdict, ['osd', 'crush',
-                                                    'add-bucket', 'name',
-                                                    'type',
-                                                    'toomany']))
         assert_equal({}, validate_command(sigdict, ['osd', 'crush',
                                                     'add-bucket', '^^^',
                                                     'type']))