From 224cc235ede66f0e2a9b686d440449acd8aace9d Mon Sep 17 00:00:00 2001 From: Prashant D Date: Thu, 25 May 2023 18:09:02 -0400 Subject: [PATCH] mon: Fix ceph versions command The commit-id d3cca1d has introduced a bug where mgr/osd/mds version information goes missing during the cluster upgrade. Collect version information before checking the emptiness of the map. Fixes: https://tracker.ceph.com/issues/61453 Signed-off-by: Prashant D (cherry picked from commit 3fbebe315f25a4d1ce8cb460710ba6da23dc40f4) --- src/mon/Monitor.cc | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 3325fbd5cd4..ca63b96d06e 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -3946,28 +3946,34 @@ void Monitor::handle_command(MonOpRequestRef op) f->close_section(); mgrmon()->count_metadata("ceph_version", &mgr); - f->open_object_section("mgr"); - for (auto& p : mgr) { - f->dump_int(p.first.c_str(), p.second); - overall[p.first] += p.second; + if (!mgr.empty()) { + f->open_object_section("mgr"); + for (auto& p : mgr) { + f->dump_int(p.first.c_str(), p.second); + overall[p.first] += p.second; + } + f->close_section(); } - f->close_section(); osdmon()->count_metadata("ceph_version", &osd); - f->open_object_section("osd"); - for (auto& p : osd) { - f->dump_int(p.first.c_str(), p.second); - overall[p.first] += p.second; + if (!osd.empty()) { + f->open_object_section("osd"); + for (auto& p : osd) { + f->dump_int(p.first.c_str(), p.second); + overall[p.first] += p.second; + } + f->close_section(); } - f->close_section(); mdsmon()->count_metadata("ceph_version", &mds); - f->open_object_section("mds"); - for (auto& p : mds) { - f->dump_int(p.first.c_str(), p.second); - overall[p.first] += p.second; + if (!mds.empty()) { + f->open_object_section("mds"); + for (auto& p : mds) { + f->dump_int(p.first.c_str(), p.second); + overall[p.first] += p.second; + } + f->close_section(); } - f->close_section(); for (auto& p : mgrstatmon()->get_service_map().services) { auto &service = p.first; -- 2.47.3