From: Sage Weil Date: Thu, 21 Mar 2013 18:04:59 +0000 (-0700) Subject: mon: add 'osd crush add-bucket ' X-Git-Tag: v0.62~177^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d8f4be6e6db954cc56e9da13c7903bc52aa6de80;p=ceph.git mon: add 'osd crush add-bucket ' This is (I think) the last missing piece to let you construct an entire map via the CLI. The add/set commands will construct intervening ancestor nodes provide there is an existing ancestor to stick them under, but this is needed to create the initial root node. Signed-off-by: Sage Weil --- diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 42d9c0ff1106..41df0d8b36ed 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2256,6 +2256,42 @@ bool OSDMonitor::prepare_command(MMonCommand *m) wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version())); return true; } + else if (m->cmd.size() == 5 && m->cmd[1] == "crush" && (m->cmd[2] == "add-bucket")) { + do { + // osd crush add-bucket + bufferlist bl; + if (pending_inc.crush.length()) + bl = pending_inc.crush; + else + osdmap.crush->encode(bl); + + CrushWrapper newcrush; + bufferlist::iterator p = bl.begin(); + newcrush.decode(p); + + if (newcrush.name_exists(m->cmd[3])) { + ss << "bucket '" << m->cmd[3] << "' already exists"; + err = 0; + break; + } + int type = newcrush.get_type_id(m->cmd[4]); + if (type <= 0) { + ss << "type '" << m->cmd[4] << "' does not exist"; + err = -EINVAL; + break; + } + int bucketno = newcrush.add_bucket(0, CRUSH_BUCKET_STRAW, CRUSH_HASH_DEFAULT, + type, 0, NULL, NULL); + newcrush.set_item_name(bucketno, m->cmd[3]); + + pending_inc.crush.clear(); + newcrush.encode(pending_inc.crush); + ss << "added bucket " << m->cmd[3] << " type " << m->cmd[4] << " to crush map"; + getline(ss, rs); + wait_for_finished_proposal(new Monitor::C_Command(mon, m, 0, rs, get_version())); + return true; + } while (false); + } else if (m->cmd.size() >= 5 && m->cmd[1] == "crush" && (m->cmd[2] == "set" || m->cmd[2] == "add")) { do { diff --git a/src/test/cli/ceph/help.t b/src/test/cli/ceph/help.t index 123a07464ebc..c3c0a984beed 100644 --- a/src/test/cli/ceph/help.t +++ b/src/test/cli/ceph/help.t @@ -49,6 +49,7 @@ ceph osd crush create-or-move [ ...] ceph osd crush move [ ...] ceph osd crush link [ ...] + ceph osd crush add-bucket ceph osd crush reweight ceph osd crush tunables ceph osd create [] diff --git a/src/tools/ceph.cc b/src/tools/ceph.cc index 1dcec2546321..3a7aa068a49b 100644 --- a/src/tools/ceph.cc +++ b/src/tools/ceph.cc @@ -92,6 +92,7 @@ static void usage() cout << " ceph osd crush create-or-move [ ...]\n"; cout << " ceph osd crush move [ ...]\n"; cout << " ceph osd crush link [ ...]\n"; + cout << " ceph osd crush add-bucket \n"; cout << " ceph osd crush reweight \n"; cout << " ceph osd crush tunables \n"; cout << " ceph osd create []\n";