From 32b51bb7d53c2f5363f667abbba3dc2eaefcb587 Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 10 Sep 2014 14:44:36 +0100 Subject: [PATCH] mds: generate friendly name for client sessions ...from the client metadata, for use in health messages. Signed-off-by: John Spray --- src/mds/Server.cc | 2 +- src/mds/SessionMap.cc | 45 ++++++++++++++++++++++++++++++++++++++++++- src/mds/SessionMap.h | 8 ++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 664a3e5f62fb7..5a50ccc9713ea 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -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::iterator i = session->info.client_metadata.begin(); diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index bf53badf3c3c3..289e80ac02b2c 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -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 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(); +} diff --git a/src/mds/SessionMap.h b/src/mds/SessionMap.h index 45f7e8264f31b..283955890ae18 100644 --- a/src/mds/SessionMap.h +++ b/src/mds/SessionMap.h @@ -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 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? -- 2.39.5