From 0810ab6de6d1d9e180bfc57a1d68a217026bcdf0 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 29 Jun 2012 19:56:07 -0700 Subject: [PATCH] osdmap: check new pool name on rename Ensure the new pool name doesn't already exist, both in the current and project map. Signed-off-by: Sage Weil --- src/mon/OSDMonitor.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index e819a112feff4..8bd48761884b3 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2287,14 +2287,20 @@ bool OSDMonitor::prepare_command(MMonCommand *m) if (pool < 0) { ss << "unrecognized pool '" << m->cmd[3] << "'"; err = -ENOENT; + } else if (osdmap.lookup_pg_pool_name(m->cmd[4].c_str()) >= 0) { + ss << "pool '" << m->cmd[4] << "' already exists"; + err = -EEXIST; } else { int ret = _prepare_rename_pool(pool, m->cmd[4]); if (ret == 0) { ss << "pool '" << m->cmd[3] << "' renamed to '" << m->cmd[4] << "'"; - getline(ss, rs); - paxos->wait_for_commit(new Monitor::C_Command(mon, m, ret, rs, paxos->get_version())); - return true; + } else { + ss << "failed to rename pool '" << m->cmd[3] << "' to '" << m->cmd[4] << "': " + << cpp_strerror(ret); } + getline(ss, rs); + paxos->wait_for_commit(new Monitor::C_Command(mon, m, ret, rs, paxos->get_version())); + return true; } } else if (m->cmd[2] == "set") { if (m->cmd.size() != 6) { @@ -2650,6 +2656,13 @@ int OSDMonitor::_prepare_rename_pool(uint64_t pool, string newname) dout(10) << "_prepare_rename_pool " << pool << " pending removal" << dendl; return -ENOENT; } + for (map::iterator p = pending_inc.new_pool_names.begin(); + p != pending_inc.new_pool_names.end(); + ++p) { + if (p->second == newname) { + return -EEXIST; + } + } pending_inc.new_pool_names[pool] = newname; return 0; -- 2.39.5