From 0b62c6b8ab854aeb0890dcc0f44e0f458b6d5387 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Mon, 10 Jul 2017 18:51:38 +0800 Subject: [PATCH] mon/OSDMonitor: dedup pg-upmap[-items] Signed-off-by: xie xingguo --- src/mon/OSDMonitor.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 92c9b9ddba776..7196783bcc41a 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -9047,9 +9047,20 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, err = -ENOENT; goto reply; } + auto it = std::find(new_pg_upmap.begin(), new_pg_upmap.end(), osd); + if (it != new_pg_upmap.end()) { + ss << "osd." << osd << " already exists, "; + continue; + } new_pg_upmap.push_back(osd); } + if (new_pg_upmap.empty()) { + ss << "no valid upmap items(pairs) is specified"; + err = -EINVAL; + goto reply; + } + pending_inc.new_pg_upmap[pgid] = mempool::osdmap::vector( new_pg_upmap.begin(), new_pg_upmap.end()); ss << "set " << pgid << " pg_upmap mapping to " << new_pg_upmap; @@ -9093,6 +9104,10 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, for (auto p = id_vec.begin(); p != id_vec.end(); ++p) { int from = *p++; int to = *p; + if (from == to) { + ss << "from osd." << from << " == to osd." << to << ", "; + continue; + } if (!osdmap.exists(from)) { ss << "osd." << from << " does not exist"; err = -ENOENT; @@ -9110,6 +9125,12 @@ bool OSDMonitor::prepare_command_impl(MonOpRequestRef op, out.resize(out.size() - 1); // drop last ',' out += "]"; + if (new_pg_upmap_items.empty()) { + ss << "no valid upmap items(pairs) is specified"; + err = -EINVAL; + goto reply; + } + pending_inc.new_pg_upmap_items[pgid] = mempool::osdmap::vector>( new_pg_upmap_items.begin(), new_pg_upmap_items.end()); -- 2.39.5