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();
#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
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);
}
}
+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();
+}
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?