From bd8c441351b8a20211c9e4f2be67f043423e9aa7 Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 8 Sep 2014 23:44:23 +0100 Subject: [PATCH] client: send metadata in session open Populated with hostname and entity_id by default, with interface for outer layers like ceph_fuse, libcephfs to inject their own metadata. Signed-off-by: John Spray --- src/client/Client.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- src/client/Client.h | 8 ++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 12e52beeaf660..b7ae2b149773a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -21,6 +21,7 @@ #include #include #include +#include #if defined(__linux__) #include @@ -421,6 +422,8 @@ int Client::init() << cpp_strerror(-ret) << dendl; } + populate_metadata(); + client_lock.Lock(); initialized = true; client_lock.Unlock(); @@ -1611,6 +1614,42 @@ MetaSession *Client::_get_or_open_mds_session(int mds) return _open_mds_session(mds); } +/** + * Populate a map of strings with client-identifying metadata, + * such as the hostname. Call this once at initialization. + */ +void Client::populate_metadata() +{ + // Hostname + struct utsname u; + int r = uname(&u); + if (r >= 0) { + metadata["hostname"] = u.nodename; + ldout(cct, 20) << __func__ << " read hostname '" << u.nodename << "'" << dendl; + } else { + ldout(cct, 1) << __func__ << " failed to read hostname (" << cpp_strerror(r) << ")" << dendl; + } + + // Ceph entity id (the '0' in "client.0") + metadata["entity_id"] = cct->_conf->name.get_id(); +} + +/** + * Optionally add or override client metadata fields. + */ +void Client::update_metadata(std::string const &k, std::string const &v) +{ + Mutex::Locker l(client_lock); + assert(initialized); + + if (metadata.count(k)) { + ldout(cct, 1) << __func__ << " warning, overriding metadata field '" << k + << "' from '" << metadata[k] << "' to '" << v << "'" << dendl; + } + + metadata[k] = v; +} + MetaSession *Client::_open_mds_session(int mds) { ldout(cct, 10) << "_open_mds_session mds." << mds << dendl; @@ -1622,7 +1661,9 @@ MetaSession *Client::_open_mds_session(int mds) session->con = messenger->get_connection(session->inst); session->state = MetaSession::STATE_OPENING; mds_sessions[mds] = session; - session->con->send_message(new MClientSession(CEPH_SESSION_REQUEST_OPEN)); + MClientSession *m = new MClientSession(CEPH_SESSION_REQUEST_OPEN); + m->client_meta = metadata; + session->con->send_message(m); return session; } diff --git a/src/client/Client.h b/src/client/Client.h index 7cb0e89130b74..1ac9754e76750 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -242,6 +242,7 @@ public: map mds_sessions; // mds -> push seq list waiting_for_mdsmap; + void get_session_metadata(std::map *meta) const; bool have_open_session(int mds); void got_mds_push(MetaSession *s); MetaSession *_get_mds_session(int mds, Connection *con); ///< return session for mds *and* con; null otherwise @@ -314,6 +315,11 @@ protected: int num_flushing_caps; ceph::unordered_map snap_realms; + // Optional extra metadata about me to send to the MDS + std::map metadata; + void populate_metadata(); + + /* async block write barrier support */ //map barriers; @@ -426,6 +432,8 @@ protected: ~Client(); void tear_down_cache(); + void update_metadata(std::string const &k, std::string const &v); + client_t get_nodeid() { return whoami; } inodeno_t get_root_ino(); -- 2.39.5