From: Sage Weil Date: Tue, 30 May 2017 20:09:20 +0000 (-0400) Subject: mon: track connected mon client features X-Git-Tag: v12.1.0~244^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1f68cef1b98912c7d64c46f7facb5d5f0b547646;p=ceph.git mon: track connected mon client features Track counts of entities by their supported features. Signed-off-by: Sage Weil --- diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index bc8f4fb79fcb..0d5661240047 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2242,6 +2242,7 @@ void Monitor::get_mon_status(Formatter *f, ostream& ss) monmap->dump(f); f->close_section(); + f->dump_object("feature_map", session_map.feature_map); f->close_section(); // mon_status if (free_formatter) { diff --git a/src/mon/Session.h b/src/mon/Session.h index 75051bf6312f..cb5946449833 100644 --- a/src/mon/Session.h +++ b/src/mon/Session.h @@ -17,6 +17,7 @@ #include "include/xlist.h" #include "msg/msg_types.h" +#include "mon/mon_types.h" #include "auth/AuthServiceHandler.h" #include "osd/OSDMap.h" @@ -39,6 +40,8 @@ struct Subscription { struct MonSession : public RefCountedObject { ConnectionRef con; + int con_type = 0; + uint64_t con_features = 0; // zero if AnonConnection entity_inst_t inst; utime_t session_timeout; utime_t time_established; @@ -60,13 +63,20 @@ struct MonSession : public RefCountedObject { MonSession(const entity_inst_t& i, Connection *c) : RefCountedObject(g_ceph_context), - con(c), inst(i), closed(false), item(this), + con(c), + con_type(c->get_peer_type()), + con_features(0), + inst(i), closed(false), item(this), auid(0), global_id(0), osd_epoch(0), auth_handler(NULL), proxy_con(NULL), proxy_tid(0) { time_established = ceph_clock_now(); + if (c->get_messenger()) { + // only fill in features if this is a non-anonymous connection + con_features = c->get_features(); + } } ~MonSession() override { //generic_dout(0) << "~MonSession " << this << dendl; @@ -92,6 +102,7 @@ struct MonSessionMap { xlist sessions; map* > subs; multimap by_osd; + FeatureMap feature_map; // type -> features -> count MonSessionMap() {} ~MonSessionMap() { @@ -123,6 +134,9 @@ struct MonSessionMap { break; } } + if (s->con_features) { + feature_map.rm(s->con_type, s->con_features); + } s->closed = true; s->put(); } @@ -133,6 +147,9 @@ struct MonSessionMap { sessions.push_back(&s->item); if (i.name.is_osd()) by_osd.insert(pair(i.name.num(), s)); + if (s->con_features) { + feature_map.add(s->con_type, s->con_features); + } s->get(); // caller gets a ref return s; } diff --git a/src/mon/mon_types.h b/src/mon/mon_types.h index 54bbfb336d06..ede5aac0aeba 100644 --- a/src/mon/mon_types.h +++ b/src/mon/mon_types.h @@ -15,6 +15,8 @@ #ifndef CEPH_MON_TYPES_H #define CEPH_MON_TYPES_H +#include + #include "include/utime.h" #include "include/util.h" #include "common/Formatter.h" @@ -45,6 +47,64 @@ inline const char *get_paxos_name(int p) { #define CEPH_MON_ONDISK_MAGIC "ceph mon volume v012" +// map of entity_type -> features -> count +struct FeatureMap { + std::map> m; + + void add(uint32_t type, uint64_t features) { + m[type][features]++; + } + + void rm(uint32_t type, uint64_t features) { + auto p = m.find(type); + assert(p != m.end()); + auto q = p->second.find(features); + assert(q != p->second.end()); + if (--q->second == 0) { + p->second.erase(q); + if (p->second.empty()) { + m.erase(p); + } + } + } + + FeatureMap& operator+=(const FeatureMap& o) { + for (auto& p : o.m) { + auto &v = m[p.first]; + for (auto& q : p.second) { + v[q.first] += q.second; + } + } + return *this; + } + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(m, bl); + ENCODE_FINISH(bl); + } + + void decode(bufferlist::iterator& p) { + DECODE_START(1, p); + ::decode(m, p); + DECODE_FINISH(p); + } + + void dump(Formatter *f) const { + for (auto& p : m) { + f->open_object_section(ceph_entity_type_name(p.first)); + for (auto& q : p.second) { + f->open_object_section("group"); + f->dump_unsigned("features", q.first); + f->dump_unsigned("num", q.second); + f->close_section(); + } + f->close_section(); + } + } +}; +WRITE_CLASS_ENCODER(FeatureMap) + /** * leveldb store stats *