]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/Session: separate session creation, peer ident, and registration
authorSage Weil <sage@redhat.com>
Sun, 20 Jan 2019 23:09:56 +0000 (17:09 -0600)
committerSage Weil <sage@redhat.com>
Thu, 7 Feb 2019 12:53:03 +0000 (06:53 -0600)
- We can now construct a session before we know who it is
- We can later call _ident to identify it
- and also later register it in the session map

Signed-off-by: Sage Weil <sage@redhat.com>
src/mon/Monitor.cc
src/mon/Session.h

index 1d481ee9b89f8047777e060456c0a4df1ae6f60f..0c16a482012917bac9b49800fd646373be6ad4c9 100644 (file)
@@ -3898,9 +3898,9 @@ void Monitor::handle_forward(MonOpRequestRef op)
     ceph_assert(req != NULL);
 
     ConnectionRef c(new AnonConnection(cct, m->client_socket_addr));
-    MonSession *s = new MonSession(req->get_source(),
-                                  req->get_source_addrs(),
-                                  static_cast<Connection*>(c.get()));
+    MonSession *s = new MonSession(static_cast<Connection*>(c.get()));
+    s->_ident(req->get_source(),
+             req->get_source_addrs());
     c->set_priv(RefCountedPtr{s, false});
     c->set_peer_addrs(m->client_addrs);
     c->set_peer_type(m->client_type);
index 8d7bbcf2ff131e4fc046f47a299b6666999afcfe..8981599573ad679865bc99132b9d23820f7b0427 100644 (file)
@@ -67,19 +67,22 @@ struct MonSession : public RefCountedObject {
   map<string,string> last_config;    ///< most recently shared config
   bool any_config = false;
 
-  MonSession(const entity_name_t& n, const entity_addrvec_t& av, Connection *c) :
-    RefCountedObject(g_ceph_context),
-    con(c),
-    con_type(c->get_peer_type()),
-    name(n),
-    addrs(av),
-    socket_addr(c->get_peer_socket_addr()),
-    item(this) {
-    if (c->get_messenger()) {
+  MonSession(Connection *c)
+    : RefCountedObject(g_ceph_context),
+      con(c),
+      item(this) { }
+
+  void _ident(const entity_name_t& n, const entity_addrvec_t& av) {
+    con_type = con->get_peer_type();
+    name = n;
+    addrs = av;
+    socket_addr = con->get_peer_socket_addr();
+    if (con->get_messenger()) {
       // only fill in features if this is a non-anonymous connection
-      con_features = c->get_features();
+      con_features = con->get_features();
     }
   }
+
   ~MonSession() override {
     //generic_dout(0) << "~MonSession " << this << dendl;
     // we should have been removed before we get destructed; see MonSessionMap::remove_session()
@@ -151,16 +154,22 @@ struct MonSessionMap {
   MonSession *new_session(const entity_name_t& n,
                          const entity_addrvec_t& av,
                          Connection *c) {
-    MonSession *s = new MonSession(n, av, c);
+    MonSession *s = new MonSession(c);
     ceph_assert(s);
+    s->_ident(n, av);
+    add_session(s);
+    return s;
+  }
+
+  void add_session(MonSession *s) {
     sessions.push_back(&s->item);
-    if (n.is_osd())
-      by_osd.insert(pair<int,MonSession*>(n.num(), s));
+    s->get();
+    if (s->name.is_osd()) {
+      by_osd.insert(pair<int,MonSession*>(s->name.num(), s));
+    }
     if (s->con_features) {
       feature_map.add(s->con_type, s->con_features);
     }
-    s->get();  // caller gets a ref
-    return s;
   }
 
   MonSession *get_random_osd_session(OSDMap *osdmap) {