From 6a21da59837ea3b80c1ac2820b03b49e68a1df07 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 19 May 2017 12:05:08 -0400 Subject: [PATCH] mon/OSDMonitor: handle sparse type names It's possible a type id isn't defined/used by crush. Use the max id instead and skip types without names. Signed-off-by: Sage Weil --- src/crush/CrushWrapper.h | 5 +++++ src/mon/OSDMonitor.cc | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 57aa001cfb57b..8a5f4a4112323 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -356,6 +356,11 @@ public: int get_num_type_names() const { return type_map.size(); } + int get_max_type_id() const { + if (type_map.empty()) + return 0; + return type_map.rbegin()->first; + } int get_type_id(const string& name) const { build_rmaps(); if (type_rmap.count(name)) diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index b271855f019a8..e28621cffafda 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3486,7 +3486,7 @@ void OSDMonitor::get_health(list >& summary, set subtree_up; unordered_map > subtree_type_down; unordered_map num_osds_subtree; - int max_type = osdmap.crush->get_num_type_names() - 1; + int max_type = osdmap.crush->get_max_type_id(); for (int i = 0; i < osdmap.get_max_osd(); i++) { if (!osdmap.exists(i)) { @@ -3505,6 +3505,8 @@ void OSDMonitor::get_health(list >& summary, int parent_id = 0; int current = i; for (int type = 0; type <= max_type; type++) { + if (!osdmap.crush->get_type_name(type)) + continue; int r = osdmap.crush->get_immediate_parent_id(current, &parent_id); if (r == -ENOENT) break; @@ -3524,6 +3526,8 @@ void OSDMonitor::get_health(list >& summary, // calculate the number of down osds in each down subtree and // store it in num_osds_subtree for (int type = 1; type <= max_type; type++) { + if (!osdmap.crush->get_type_name(type)) + continue; for (auto j = subtree_type_down[type].begin(); j != subtree_type_down[type].end(); ++j) { @@ -3551,6 +3555,8 @@ void OSDMonitor::get_health(list >& summary, if (num_down_in_osds > 0) { // summary of down subtree types and osds for (int type = max_type; type > 0; type--) { + if (!osdmap.crush->get_type_name(type)) + continue; if (subtree_type_down[type].size() > 0) { ostringstream ss; ss << subtree_type_down[type].size() << " " @@ -3575,6 +3581,8 @@ void OSDMonitor::get_health(list >& summary, if (detail) { // details of down subtree types for (int type = max_type; type > 0; type--) { + if (!osdmap.crush->get_type_name(type)) + continue; for (auto j = subtree_type_down[type].rbegin(); j != subtree_type_down[type].rend(); ++j) { -- 2.39.5