]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: generate friendly name for client sessions
authorJohn Spray <john.spray@redhat.com>
Wed, 10 Sep 2014 13:44:36 +0000 (14:44 +0100)
committerJohn Spray <john.spray@redhat.com>
Wed, 17 Sep 2014 12:21:49 +0000 (13:21 +0100)
...from the client metadata, for use in health messages.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mds/Server.cc
src/mds/SessionMap.cc
src/mds/SessionMap.h

index 664a3e5f62fb7bc0fa03f9ac4d80c0da7fe3d39d..5a50ccc9713ea4823f690f2aefdbdb989b5a1b4b 100644 (file)
@@ -225,7 +225,7 @@ void Server::handle_client_session(MClientSession *m)
     assert(session->is_closed() ||
           session->is_closing());
 
-    session->info.client_metadata = m->client_meta;
+    session->set_client_metadata(m->client_meta);
     dout(20) << __func__ << " CEPH_SESSION_REQUEST_OPEN "
       << session->info.client_metadata.size() << " metadata entries:" << dendl;
     for (map<string, string>::iterator i = session->info.client_metadata.begin();
index bf53badf3c3c3528702d383108909c8f12697e0f..289e80ac02b2c096d7872b56c44485098414226f 100644 (file)
@@ -21,6 +21,7 @@
 #include "common/config.h"
 #include "common/errno.h"
 #include "include/assert.h"
+#include "include/stringify.h"
 
 #define dout_subsys ceph_subsys_mds
 #undef dout_prefix
@@ -200,7 +201,7 @@ void SessionMap::decode(bufferlist::iterator& p)
       Session *s = get_or_add_session(inst);
       if (s->is_closed())
        set_state(s, Session::STATE_OPEN);
-      s->info.decode(p);
+      s->decode(p);
     }
 
     DECODE_FINISH(p);
@@ -377,3 +378,45 @@ void Session::notify_recall_sent(int const new_limit)
   }
 }
 
+void Session::set_client_metadata(map<string, string> const &meta)
+{
+  info.client_metadata = meta;
+
+  _update_human_name();
+}
+
+/**
+ * Use client metadata to generate a somewhat-friendlier
+ * name for the client than its session ID.
+ *
+ * This is *not* guaranteed to be unique, and any machine
+ * consumers of session-related output should always use
+ * the session ID as a primary capacity and use this only
+ * as a presentation hint.
+ */
+void Session::_update_human_name()
+{
+  if (info.client_metadata.count("hostname")) {
+    // Happy path, refer to clients by hostname
+    human_name = info.client_metadata["hostname"];
+    if (info.client_metadata.count("entity_id")) {
+      EntityName entity;
+      entity.set_id(info.client_metadata["entity_id"]);
+      if (!entity.has_default_id()) {
+        // When a non-default entity ID is set by the user, assume they
+        // would like to see it in references to the client
+        human_name += std::string(":") + entity.get_id();
+      }
+    }
+  } else {
+    // Fallback, refer to clients by ID e.g. client.4567
+    human_name = stringify(info.inst.name.num());
+  }
+}
+
+void Session::decode(bufferlist::iterator &p)
+{
+  info.decode(p);
+
+  _update_human_name();
+}
index 45f7e8264f31bf6c710644e328dd4d701aa945bc..283955890ae18d2a0b33bf12225e884e8e26eee2 100644 (file)
@@ -81,8 +81,16 @@ private:
   int importing_count;
   friend class SessionMap;
 
+  // Human (friendly) name is soft state generated from client metadata
+  void _update_human_name();
+  std::string human_name;
+
 public:
 
+  void decode(bufferlist::iterator &p);
+  void set_client_metadata(std::map<std::string, std::string> const &meta);
+  std::string get_human_name() const {return human_name;}
+
   // Ephemeral state for tracking progress of capability recalls
   utime_t recalled_at;  // When was I asked to SESSION_RECALL?
   uint32_t recall_count;  // How many caps was I asked to SESSION_RECALL?