From 6cba563f5f5079ea81ec4e936a818dc4ed887509 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 20 Mar 2013 08:00:12 -0700 Subject: [PATCH] mon: 'ceph osd crush link ...' to add a link to an existing bucket Allow a second reference to an existing bucket to be added. This lets you create a DAG instead of a tree using the CLI. Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/test/cli/ceph/help.t | 3 ++- src/tools/ceph.cc | 3 ++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 47c6c1d8f6922..4f90345ec37cb 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2409,6 +2409,46 @@ bool OSDMonitor::prepare_command(MMonCommand *m) } } while (false); } + else if (m->cmd.size() >= 5 && m->cmd[1] == "crush" && m->cmd[2] == "link") { + do { + // osd crush link [ ...] + string name = m->cmd[3]; + map loc; + parse_loc_map(m->cmd, 4, &loc); + + dout(0) << "linking crush item name '" << name << "' at location " << loc << dendl; + 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(name.c_str())) { + err = -ENOENT; + ss << "item " << name << " does not exist"; + break; + } + int id = newcrush.get_item_id(name.c_str()); + + if (!newcrush.check_item_loc(g_ceph_context, id, loc, (int *)NULL)) { + err = newcrush.link_bucket(g_ceph_context, id, loc); + if (err >= 0) { + ss << "linked item id " << id << " name '" << name << "' to location " << loc << " in crush map"; + 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_version())); + return true; + } + } else { + ss << "no need to move item id " << id << " name '" << name << "' to location " << loc << " in crush map"; + } + } while (false); + } else if (m->cmd.size() > 3 && m->cmd[1] == "crush" && (m->cmd[2] == "rm" || m->cmd[2] == "remove")) { do { // osd crush rm diff --git a/src/test/cli/ceph/help.t b/src/test/cli/ceph/help.t index ca93dba39c432..123a07464ebc1 100644 --- a/src/test/cli/ceph/help.t +++ b/src/test/cli/ceph/help.t @@ -46,8 +46,9 @@ ceph osd getmap -o ceph osd crush set [ ...] ceph osd crush add [ ...] - ceph osd crush move [ ...] ceph osd crush create-or-move [ ...] + ceph osd crush move [ ...] + ceph osd crush link [ ...] ceph osd crush reweight ceph osd crush tunables ceph osd create [] diff --git a/src/tools/ceph.cc b/src/tools/ceph.cc index f93d445d61224..1dcec25463211 100644 --- a/src/tools/ceph.cc +++ b/src/tools/ceph.cc @@ -89,8 +89,9 @@ static void usage() cout << " ceph osd getmap -o \n"; cout << " ceph osd crush set [ ...]\n"; cout << " ceph osd crush add [ ...]\n"; - cout << " ceph osd crush move [ ...]\n"; cout << " ceph osd crush create-or-move [ ...]\n"; + cout << " ceph osd crush move [ ...]\n"; + cout << " ceph osd crush link [ ...]\n"; cout << " ceph osd crush reweight \n"; cout << " ceph osd crush tunables \n"; cout << " ceph osd create []\n"; -- 2.39.5