]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: SessionMap now uses modern encoding
authorGreg Farnum <greg@inktank.com>
Tue, 5 Feb 2013 20:15:51 +0000 (12:15 -0800)
committerGreg Farnum <greg@inktank.com>
Fri, 8 Feb 2013 21:17:54 +0000 (13:17 -0800)
Signed-off-by: Greg Farnum <greg@inktank.com>
src/mds/SessionMap.cc
src/mds/SessionMap.h
src/test/encoding/types.h

index 87429ba139f82a8e03d9db8c06833c377adbdcae..53fe90c10ba057a5ce09a18d09c4b009f7782f60 100644 (file)
@@ -140,19 +140,17 @@ void SessionMap::_save_finish(version_t v)
 
 // -------------------
 
-void SessionMap::encode(bufferlist& bl)
+void SessionMap::encode(bufferlist& bl) const
 {
   uint64_t pre = -1;     // for 0.19 compatibility; we forgot an encoding prefix.
   ::encode(pre, bl);
 
-  __u8 struct_v = 2;
-  ::encode(struct_v, bl);
-
+  ENCODE_START(3, 3, bl);
   ::encode(version, bl);
 
-  for (hash_map<entity_name_t,Session*>::iterator p = session_map.begin(); 
+  for (hash_map<entity_name_t,Session*>::const_iterator p = session_map.begin(); 
        p != session_map.end(); 
-       ++p) 
+       ++p) {
     if (p->second->is_open() ||
        p->second->is_closing() ||
        p->second->is_stale() ||
@@ -160,6 +158,8 @@ void SessionMap::encode(bufferlist& bl)
       ::encode(p->first, bl);
       p->second->info.encode(bl);
     }
+  }
+  ENCODE_FINISH(bl);
 }
 
 void SessionMap::decode(bufferlist::iterator& p)
@@ -168,12 +168,11 @@ void SessionMap::decode(bufferlist::iterator& p)
   uint64_t pre;
   ::decode(pre, p);
   if (pre == (uint64_t)-1) {
-    __u8 struct_v;
-    ::decode(struct_v, p);
-    assert(struct_v == 2);
-
+    DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, p);
+    assert(struct_v >= 2);
+    
     ::decode(version, p);
-
+    
     while (!p.end()) {
       entity_inst_t inst;
       ::decode(inst.name, p);
@@ -183,6 +182,7 @@ void SessionMap::decode(bufferlist::iterator& p)
       s->info.decode(p);
     }
 
+    DECODE_FINISH(p);
   } else {
     // --- old format ----
     version = pre;
@@ -212,7 +212,29 @@ void SessionMap::decode(bufferlist::iterator& p)
   }
 }
 
+void SessionMap::dump(Formatter *f) const
+{
+  f->open_array_section("Sessions");
+  for (hash_map<entity_name_t,Session*>::const_iterator p = session_map.begin();
+       p != session_map.end();
+       ++p)  {
+    f->open_object_section("Session");
+    f->open_object_section("entity name");
+    p->first.dump(f);
+    f->close_section(); // entity name
+    f->open_object_section("Session info");
+    p->second->info.dump(f);
+    f->close_section(); // Session info
+    f->close_section(); // Session
+  }
+  f->close_section(); // Sessions
+}
 
+void SessionMap::generate_test_instances(list<SessionMap*>& ls)
+{
+  // pretty boring for now
+  ls.push_back(new SessionMap(NULL));
+}
 
 void SessionMap::wipe()
 {
index ed94621a6fe2f352a4aeab96cb0e2fde4775f2b4..702a0b5dec8fa1812a3b025a3ae65ef0bacb1535 100644 (file)
@@ -228,6 +228,10 @@ public:
   SessionMap(MDS *m) : mds(m), 
                       version(0), projected(0), committing(0), committed(0) 
   { }
+  
+  //for the dencoder
+  SessionMap() : mds(NULL), version(0), projected(0),
+                committing(0), committed(0) {}
     
   // sessions
   bool empty() { return session_map.empty(); }
@@ -367,8 +371,10 @@ public:
   inodeno_t ino;
   list<Context*> waiting_for_load;
 
-  void encode(bufferlist& bl);
+  void encode(bufferlist& bl) const;
   void decode(bufferlist::iterator& blp);
+  void dump(Formatter *f) const;
+  static void generate_test_instances(list<SessionMap*>& ls);
 
   object_t get_object_name();
 
index d3451fec4288033e4b5254a94c3da9eb44d94ea1..799231a39f01c63735cb716b66a221f16ac53bce 100644 (file)
@@ -126,6 +126,9 @@ TYPE(Capability)
 #include "mds/AnchorServer.h"
 TYPE(AnchorServer)
 
+#include "mds/SessionMap.h"
+TYPE(SessionMap)
+
 #include "mds/events/ECommitted.h"
 TYPE(ECommitted)
 #include "mds/events/EExport.h"