From: Sage Weil Date: Fri, 3 Aug 2018 19:36:14 +0000 (-0500) Subject: mds/SessionMap: track socket_addr for each Session X-Git-Tag: v14.0.1~601^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=37568982e31f6315b3931d1b4c19ae22d36e3422;p=ceph.git mds/SessionMap: track socket_addr for each Session Make sure socket_addr is populated when connection is set. Signed-off-by: Sage Weil --- diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index ac3242ce9175..1228f63a8dfb 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -1352,13 +1352,12 @@ bool MDSDaemon::ms_verify_authorizer(Connection *con, int peer_type, // It doesn't go into a SessionMap instance until it sends an explicit // request to open a session (initial state of Session is `closed`) if (!s) { - s = new Session; + s = new Session(con); s->info.auth_name = name; s->info.inst.addr = con->get_peer_addr(); s->info.inst.name = n; dout(10) << " new session " << s << " for " << s->info.inst << " con " << con << dendl; con->set_priv(RefCountedPtr{s, false}); - s->connection = con; if (mds_rank) { mds_rank->kick_waiters_for_any_client_connection(); } @@ -1427,7 +1426,7 @@ void MDSDaemon::ms_handle_accept(Connection *con) if (s) { if (s->connection != con) { dout(10) << " session connection " << s->connection << " -> " << con << dendl; - s->connection = con; + s->set_connection(con); // send out any queued messages while (!s->preopen_out_queue.empty()) { diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index 90f590ad4a64..13b9a924b62c 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -518,7 +518,7 @@ void SessionMapStore::decode_legacy(bufferlist::const_iterator& p) while (n-- && !p.end()) { auto p2 = p; - Session *s = new Session; + Session *s = new Session(nullptr); s->info.decode(p); if (session_map.count(s->info.inst.name)) { // eager client connected too fast! aie. diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index 0ce4dad90b8f..04b6f483d9e9 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -139,6 +139,7 @@ public: MDSAuthCaps auth_caps; ConnectionRef connection; + entity_addr_t socket_addr; xlist::item item_session_list; list preopen_out_queue; ///< messages for client, queued before they connect @@ -321,7 +322,7 @@ public: const vector *gid_list, int new_uid, int new_gid); - Session() : + Session(Connection *con) : state(STATE_CLOSED), state_seq(0), importing_count(0), recall_count(0), recall_release_count(0), auth_caps(g_ceph_context), @@ -331,7 +332,11 @@ public: lease_seq(0), completed_requests_dirty(false), num_trim_flushes_warnings(0), - num_trim_requests_warnings(0) { } + num_trim_requests_warnings(0) { + if (con) { + set_connection(con); + } + } ~Session() override { if (state == STATE_CLOSED) { item_session_list.remove_myself(); @@ -344,6 +349,11 @@ public: } } + void set_connection(Connection *con) { + connection = con; + socket_addr = con->get_peer_socket_addr(); + } + void clear() { pending_prealloc_inos.clear(); info.clear_meta(); @@ -418,7 +428,7 @@ public: if (session_map_entry != session_map.end()) { s = session_map_entry->second; } else { - s = session_map[i.name] = new Session; + s = session_map[i.name] = new Session(nullptr); s->info.inst = i; s->last_cap_renew = ceph_clock_now(); if (logger) { diff --git a/src/test/mds/TestSessionFilter.cc b/src/test/mds/TestSessionFilter.cc index 39970a76df33..150663da0e74 100644 --- a/src/test/mds/TestSessionFilter.cc +++ b/src/test/mds/TestSessionFilter.cc @@ -74,8 +74,8 @@ TEST(MDSSessionFilter, IdEquality) SessionFilter filter; std::stringstream ss; filter.parse({"id=123"}, &ss); - Session *a = new Session();; - Session *b = new Session();; + Session *a = new Session(nullptr);; + Session *b = new Session(nullptr);; a->info.inst.name.parse("client.123"); b->info.inst.name.parse("client.456"); @@ -90,9 +90,9 @@ TEST(MDSSessionFilter, StateEquality) SessionFilter filter; std::stringstream ss; filter.parse({"state=closing"}, &ss); - Session *a = new Session(); + Session *a = new Session(nullptr); a->set_state(Session::STATE_CLOSING); - Session *b = new Session(); + Session *b = new Session(nullptr); b->set_state(Session::STATE_OPENING); ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;})); @@ -106,9 +106,9 @@ TEST(MDSSessionFilter, AuthEquality) SessionFilter filter; std::stringstream ss; filter.parse({"auth_name=rhubarb"}, &ss); - Session *a = new Session(); + Session *a = new Session(nullptr); a->info.auth_name.set_id("rhubarb"); - Session *b = new Session(); + Session *b = new Session(nullptr); b->info.auth_name.set_id("custard"); ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;})); @@ -124,10 +124,10 @@ TEST(MDSSessionFilter, MetadataEquality) int r = filter.parse({"client_metadata.root=/rhubarb"}, &ss); ASSERT_EQ(r, 0); client_metadata_t meta; - Session *a = new Session(); + Session *a = new Session(nullptr); meta.kv_map = {{"root", "/rhubarb"}}; a->set_client_metadata(meta); - Session *b = new Session(); + Session *b = new Session(nullptr); meta.kv_map = {{"root", "/custard"}}; b->set_client_metadata(meta); @@ -143,7 +143,7 @@ TEST(MDSSessionFilter, ReconnectingEquality) std::stringstream ss; int r = filter.parse({"reconnecting=true"}, &ss); ASSERT_EQ(r, 0); - Session *a = new Session(); + Session *a = new Session(nullptr); ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return true;})); ASSERT_FALSE(filter.match(*a, [](client_t c) -> bool {return false;}));