]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: send metadata in session open
authorJohn Spray <john.spray@redhat.com>
Mon, 8 Sep 2014 22:44:23 +0000 (23:44 +0100)
committerJohn Spray <john.spray@redhat.com>
Wed, 17 Sep 2014 12:21:48 +0000 (13:21 +0100)
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 <john.spray@redhat.com>
src/client/Client.cc
src/client/Client.h

index 12e52beeaf660f216914c3159c138381a1715387..b7ae2b149773ab9fd26c18157b149e04bec03467 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <fcntl.h>
+#include <sys/utsname.h>
 
 #if defined(__linux__)
 #include <linux/falloc.h>
@@ -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;
 }
 
index 7cb0e89130b740310d08a69070ba5d9d58c82080..1ac9754e767506515b949a08f78bce88e5ec2b9b 100644 (file)
@@ -242,6 +242,7 @@ public:
   map<int, MetaSession*> mds_sessions;  // mds -> push seq
   list<Cond*> waiting_for_mdsmap;
 
+  void get_session_metadata(std::map<std::string, std::string> *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<inodeno_t,SnapRealm*> snap_realms;
 
+  // Optional extra metadata about me to send to the MDS
+  std::map<std::string, std::string> metadata;
+  void populate_metadata();
+
+
   /* async block write barrier support */
   //map<uint64_t, BarrierContext* > 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();