]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/SessionMap: track socket_addr for each Session
authorSage Weil <sage@redhat.com>
Fri, 3 Aug 2018 19:36:14 +0000 (14:36 -0500)
committerSage Weil <sage@redhat.com>
Sun, 12 Aug 2018 22:01:05 +0000 (17:01 -0500)
Make sure socket_addr is populated when connection is set.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mds/MDSDaemon.cc
src/mds/SessionMap.cc
src/mds/SessionMap.h
src/test/mds/TestSessionFilter.cc

index ac3242ce917598b4b05cc1fbf3b4154e9c281395..1228f63a8dfba1afe3311e631dece1c52e827f23 100644 (file)
@@ -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()) {
index 90f590ad4a64a07f8b0b62eb3e602c6297ff15d8..13b9a924b62c0da175cc9f559606641212735087 100644 (file)
@@ -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.
index 0ce4dad90b8fc6f6ca8cfbfb4e0b734cef0e1e20..04b6f483d9e968d10ef1f578ac5dce15c56a172d 100644 (file)
@@ -139,6 +139,7 @@ public:
   MDSAuthCaps auth_caps;
 
   ConnectionRef connection;
+  entity_addr_t socket_addr;
   xlist<Session*>::item item_session_list;
 
   list<Message*> preopen_out_queue;  ///< messages for client, queued before they connect
@@ -321,7 +322,7 @@ public:
                   const vector<uint64_t> *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) {
index 39970a76df3371042a9a7eba8c97692b5e7bb386..150663da0e74f9a4b4294f41d3e63f7ef389cfdd 100644 (file)
@@ -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;}));