From 5b9a2b756ecf4d4968cde34807aafee0d3e5d6a3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 21 Jan 2020 15:09:01 -0600 Subject: [PATCH] mon/Session: only index osd ids >= 0 This ensures that get_random_osd_session behaves when it does int n = by_osd.rbegin()->first + 1; int r = rand() % n; Fixes: https://tracker.ceph.com/issues/43552 Signed-off-by: Sage Weil (cherry picked from commit d6f0642b82c5a1caa37b839bc8380aeb0c532143) Conflicts: src/mon/Session.h --- src/mon/Session.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mon/Session.h b/src/mon/Session.h index fba33381f75..b6d176f50cf 100644 --- a/src/mon/Session.h +++ b/src/mon/Session.h @@ -134,7 +134,8 @@ struct MonSessionMap { } s->sub_map.clear(); s->item.remove_myself(); - if (s->name.is_osd()) { + if (s->name.is_osd() && + s->name.num() >= 0) { for (multimap::iterator p = by_osd.find(s->name.num()); p->first == s->name.num(); ++p) @@ -163,7 +164,8 @@ struct MonSessionMap { void add_session(MonSession *s) { sessions.push_back(&s->item); s->get(); - if (s->name.is_osd()) { + if (s->name.is_osd() && + s->name.num() >= 0) { by_osd.insert(pair(s->name.num(), s)); } if (s->con_features) { -- 2.47.3