]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: tons of encoding changes
authorSage Weil <sage@newdream.net>
Fri, 9 May 2008 03:30:04 +0000 (20:30 -0700)
committerSage Weil <sage@newdream.net>
Fri, 9 May 2008 03:30:04 +0000 (20:30 -0700)
37 files changed:
src/include/encoding.h
src/include/frag.h
src/include/triple.h
src/include/types.h
src/mds/Anchor.h
src/mds/AnchorTable.cc
src/mds/CDentry.h
src/mds/CDir.cc
src/mds/CDir.h
src/mds/CInode.cc
src/mds/CInode.h
src/mds/LogEvent.cc
src/mds/LogEvent.h
src/mds/MDCache.cc
src/mds/MDLog.cc
src/mds/Server.cc
src/mds/events/EAnchor.h
src/mds/events/EAnchorClient.h
src/mds/events/EExport.h
src/mds/events/EFragment.h
src/mds/events/EImportFinish.h
src/mds/events/EImportStart.h
src/mds/events/EMetaBlob.h
src/mds/events/EOpen.h
src/mds/events/EPurgeFinish.h
src/mds/events/ESession.h
src/mds/events/ESessions.h
src/mds/events/ESlaveUpdate.h
src/mds/events/EString.h
src/mds/events/ESubtreeMap.h
src/mds/events/EUpdate.h
src/messages/MAnchor.h
src/messages/MCacheExpire.h
src/messages/MDentryUnlink.h
src/messages/MDiscoverReply.h
src/messages/MExportDirPrep.h
src/messages/MMDSCacheRejoin.h

index f86797a5100ca65858d2d0c9a42a703dc6a16a59..44ab89cbc1ad667ff81781d9080e73c0c4f8d2a4 100644 (file)
@@ -19,7 +19,6 @@
 #include "byteorder.h"
 #include "buffer.h"
 
-
 // --------------------------------------
 // base types
 
@@ -90,6 +89,69 @@ WRITE_INTTYPE_ENCODER(s16, le16)
 #include <vector>
 #include <string>
 #include <ext/hash_map>
+#include "triple.h"
+
+// pair
+template<class A, class B>
+inline void encode(const std::pair<A,B> &p, bufferlist &bl)
+{
+  encode(p.first, bl);
+  encode(p.second, bl);
+}
+template<class A, class B>
+inline void decode(std::pair<A,B> &pa, bufferlist::iterator &p)
+{
+  decode(pa.first, p);
+  decode(pa.second, p);
+}
+
+// triple
+template<class A, class B, class C>
+inline void encode(const triple<A,B,C> &t, bufferlist &bl)
+{
+  encode(t.first, bl);
+  encode(t.second, bl);
+  encode(t.third, bl);
+}
+template<class A, class B, class C>
+inline void decode(triple<A,B,C> &t, bufferlist::iterator &p)
+{
+  decode(t.first, p);
+  decode(t.second, p);
+  decode(t.third, p);
+}
+
+
+// list (pointers)
+template<class T>
+inline void encode(const std::list<T*>& ls, bufferlist& bl)
+{
+  // should i pre- or post- count?
+  if (!ls.empty()) {
+    unsigned pos = bl.length();
+    __u32 n = 0;
+    encode(n, bl);
+    for (typename std::list<T*>::const_iterator p = ls.begin(); p != ls.end(); ++p) {
+      n++;
+      encode(**p, bl);
+    }
+    bl.copy_in(pos, sizeof(n), (char*)&n);
+  } else {
+    __u32 n = ls.size();    // FIXME: this is slow on a list.
+    encode(n, bl);
+    for (typename std::list<T*>::const_iterator p = ls.begin(); p != ls.end(); ++p)
+      encode(**p, bl);
+  }
+}
+template<class T>
+inline void decode(std::list<T*>& ls, bufferlist::iterator& p)
+{
+  __u32 n;
+  decode(n, p);
+  ls.clear();
+  while (n--)
+    ls.push_back(new T(p));
+}
 
 
 // list
@@ -170,6 +232,25 @@ inline void decode(std::set<T>& s, bufferlist::iterator& p)
   }
 }
 
+// vector (pointers)
+template<class T>
+inline void encode(const std::vector<T*>& v, bufferlist& bl)
+{
+  __u32 n = v.size();
+  encode(n, bl);
+  for (typename std::vector<T*>::const_iterator p = v.begin(); p != v.end(); ++p)
+    encode(**p, bl);
+}
+template<class T>
+inline void decode(std::vector<T*>& v, bufferlist::iterator& p)
+{
+  __u32 n;
+  decode(n, p);
+  v.resize(n);
+  for (__u32 i=0; i<n; i++) 
+    v[i] = new T(p);
+}
+
 // vector
 template<class T>
 inline void encode(const std::vector<T>& v, bufferlist& bl)
@@ -189,6 +270,30 @@ inline void decode(std::vector<T>& v, bufferlist::iterator& p)
     decode(v[i], p);
 }
 
+// map (pointers)
+template<class T, class U>
+inline void encode(const std::map<T,U*>& m, bufferlist& bl)
+{
+  __u32 n = m.size();
+  encode(n, bl);
+  for (typename std::map<T,U*>::const_iterator p = m.begin(); p != m.end(); ++p) {
+    encode(p->first, bl);
+    encode(*p->second, bl);
+  }
+}
+template<class T, class U>
+inline void decode(std::map<T,U*>& m, bufferlist::iterator& p)
+{
+  __u32 n;
+  decode(n, p);
+  m.clear();
+  while (n--) {
+    T k;
+    decode(k, p);
+    m[k] = new U(p);
+  }
+}
+
 // map
 template<class T, class U>
 inline void encode(const std::map<T,U>& m, bufferlist& bl)
index 5392ea12c296834e8111ba2e34c57a393ba95bdf..e6ac64df80b3684a6d0c77ab70267d137f125d86 100644 (file)
@@ -465,13 +465,10 @@ public:
   }
   
   // encoding
-  void _encode(bufferlist& bl) const {
+  void encode(bufferlist& bl) const {
     ::encode(_splits, bl);
   }
-  void _decode(bufferlist& bl, int& off) {
-    ::_decode(_splits, bl, off);
-  }
-  void _decode(bufferlist::iterator& p) {
+  void decode(bufferlist::iterator& p) {
     ::decode(_splits, p);
   }
 
@@ -498,6 +495,7 @@ public:
     out << ")";
   }
 };
+WRITE_CLASS_ENCODERS(fragtree_t)
 
 inline std::ostream& operator<<(std::ostream& out, fragtree_t& ft)
 {
index e9f43b9315d21b746ffe4a2f82e084f47a2f597d..a6dc8ac5de656901ff97b80ffab0795468d2558a 100644 (file)
@@ -21,6 +21,7 @@ class triple {
   A first;
   B second;
   C third;
+
   triple() {}
   triple(A f, B s, C t) : first(f), second(s), third(t) {}
 };
index ceb28d7978dc56995359d71830c28f30fb6f076c..277d7585fca250c268db078098d5656a297459d2 100644 (file)
@@ -228,9 +228,9 @@ struct inode_t {
   version_t file_data_version; // auth only
 
   // file type
-  bool is_symlink() { return (mode & S_IFMT) == S_IFLNK; }
-  bool is_dir()     { return (mode & S_IFMT) == S_IFDIR; }
-  bool is_file()    { return (mode & S_IFMT) == S_IFREG; }
+  bool is_symlink() const { return (mode & S_IFMT) == S_IFLNK; }
+  bool is_dir()     const { return (mode & S_IFMT) == S_IFDIR; }
+  bool is_file()    const { return (mode & S_IFMT) == S_IFREG; }
 };
 
 static inline void encode(const inode_t &i, bufferlist &bl) {
index c659b17ebcc52ca05e0a61ac67d0a3e1387412b2..d01f1de27922b7ba74845c0a421e768a0d5e22ef 100644 (file)
@@ -22,7 +22,6 @@ using std::string;
 #include "mdstypes.h"
 #include "include/buffer.h"
 
-
 // anchor ops
 #define ANCHOR_OP_LOOKUP          1
 #define ANCHOR_OP_LOOKUP_REPLY    -2
@@ -83,22 +82,18 @@ public:
     //ref_dn(rd), 
     nref(nr) { }
   
-  void _encode(bufferlist &bl) {
-    bl.append((char*)&ino, sizeof(ino));
-    bl.append((char*)&dirfrag, sizeof(dirfrag));
-    bl.append((char*)&nref, sizeof(nref));
-    //::_encode(ref_dn, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(ino, bl);
+    ::encode(dirfrag, bl);
+    ::encode(nref, bl);
   }
-  void _decode(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(ino), (char*)&ino);
-    off += sizeof(ino);
-    bl.copy(off, sizeof(dirfrag), (char*)&dirfrag);
-    off += sizeof(dirfrag);
-    bl.copy(off, sizeof(nref), (char*)&nref);
-    off += sizeof(nref);
-    //::_decode(ref_dn, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(ino, bl);
+    ::decode(dirfrag, bl);
+    ::decode(nref, bl);
   }
 };
+WRITE_CLASS_ENCODERS(Anchor)
 
 inline ostream& operator<<(ostream& out, Anchor& a)
 {
index fe067ede954a8cd27751e43b59e3e3200fc03f61..c26ce2282345d310cd689fbae87f40ad5dcc6180 100644 (file)
@@ -542,34 +542,14 @@ void AnchorTable::save(Context *onfinish)
   bufferlist bl;
 
   // version
-  bl.append((char*)&version, sizeof(version));
-
-  // # anchors
-  size_t size = anchor_map.size();
-  bl.append((char*)&size, sizeof(size));
-
-  // anchors
-  for (hash_map<inodeno_t, Anchor>::iterator it = anchor_map.begin();
-       it != anchor_map.end();
-       it++) {
-    it->second._encode(bl);
-    dout(15) << "save encoded " << it->second << dendl;
-  }
+  ::encode(version, bl);
+  ::encode(anchor_map, bl);
 
   // pending
-  ::_encode(pending_reqmds, bl);
-  ::_encode(pending_create, bl);
-  ::_encode(pending_destroy, bl);
-  
-  size_t s = pending_update.size();
-  bl.append((char*)&s, sizeof(s));
-  for (map<version_t, pair<inodeno_t, vector<Anchor> > >::iterator p = pending_update.begin();
-       p != pending_update.end();
-       ++p) {
-    bl.append((char*)&p->first, sizeof(p->first));
-    bl.append((char*)&p->second.first, sizeof(p->second.first));
-    ::_encode(p->second.second, bl);
-  }
+  ::encode(pending_reqmds, bl);
+  ::encode(pending_create, bl);
+  ::encode(pending_destroy, bl);
+  ::encode(pending_update, bl);
 
   // write!
   object_t oid = object_t(MDS_INO_ANCHORTABLE+mds->get_nodeid(), 0);
@@ -625,41 +605,17 @@ void AnchorTable::_loaded(bufferlist& bl)
 {
   dout(10) << "_loaded got " << bl.length() << " bytes" << dendl;
 
-  int off = 0;
-  bl.copy(off, sizeof(version), (char*)&version);
-  off += sizeof(version);
+  bufferlist::iterator p = bl.begin();
 
-  size_t size;
-  bl.copy(off, sizeof(size), (char*)&size);
-  off += sizeof(size);
+  ::decode(version, p);
+  ::decode(anchor_map, p);
 
-  for (size_t n=0; n<size; n++) {
-    Anchor a;
-    a._decode(bl, off);
-    anchor_map[a.ino] = a;   
-    dout(15) << "load_2 decoded " << a << dendl;
-  }
-
-  ::_decode(pending_reqmds, bl, off);
-  ::_decode(pending_create, bl, off);
-  ::_decode(pending_destroy, bl, off);
-
-  size_t s;
-  bl.copy(off, sizeof(s), (char*)&s);
-  off += sizeof(s);
-  for (size_t i=0; i<s; i++) {
-    version_t atid;
-    bl.copy(off, sizeof(atid), (char*)&atid);
-    off += sizeof(atid);
-    inodeno_t ino;
-    bl.copy(off, sizeof(ino), (char*)&ino);
-    off += sizeof(ino);
-
-    pending_update[atid].first = ino;
-    ::_decode(pending_update[atid].second, bl, off);
-  }
+  ::decode(pending_reqmds, p);
+  ::decode(pending_create, p);
+  ::decode(pending_destroy, p);
+  ::decode(pending_update, p);
 
-  assert(off == (int)bl.length());
+  assert(p.end());
 
   // done.
   opened = true;
index 1bf1c31dd1a2d39de8ae73fd72e783ded12a9d7b..1eabf80874b65396f17edc30b179d82864b6a318 100644 (file)
@@ -285,6 +285,7 @@ public:
     lockstate(dn->lock.get_replica_state()),
     dir_offset(dn->get_dir_offset()),
     remote_ino(dn->get_remote_ino()), remote_d_type(dn->get_remote_d_type()) { }
+  CDentryDiscover(bufferlist::iterator &p) { decode(p); }
 
   string& get_dname() { return dname; }
   int get_nonce() { return replica_nonce; }
@@ -300,26 +301,25 @@ public:
     dn->lock.set_state( lockstate );
   }
 
-  void _encode(bufferlist& bl) {
-    ::_encode(dname, bl);
-    ::_encode(dir_offset, bl);
-    ::_encode(remote_ino, bl);
-    ::_encode(remote_d_type, bl);
-    ::_encode(replica_nonce, bl);
-    ::_encode(lockstate, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(dname, bl);
+    ::encode(dir_offset, bl);
+    ::encode(remote_ino, bl);
+    ::encode(remote_d_type, bl);
+    ::encode(replica_nonce, bl);
+    ::encode(lockstate, bl);
   }
   
-  void _decode(bufferlist& bl, int& off) {
-    ::_decode(dname, bl, off);
-    ::_decode(dir_offset, bl, off);
-    ::_decode(remote_ino, bl, off);
-    ::_decode(remote_d_type, bl, off);
-    ::_decode(replica_nonce, bl, off);
-    ::_decode(lockstate, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(dname, bl);
+    ::decode(dir_offset, bl);
+    ::decode(remote_ino, bl);
+    ::decode(remote_d_type, bl);
+    ::decode(replica_nonce, bl);
+    ::decode(lockstate, bl);
   }
-
 };
-
+WRITE_CLASS_ENCODERS(CDentryDiscover)
 
 
 #endif
index bc2e17c56ca469390ec09a0eb0b14aec6b266434..2466b41976ac8b0331c058c86080771ab4f5cd26 100644 (file)
@@ -874,30 +874,30 @@ void CDir::_fetched(bufferlist &bl)
 
   // decode.
   int len = bl.length();
-  int off = 0;
+  bufferlist::iterator p = bl.begin();
   version_t got_version;
   
-  ::_decode(got_version, bl, off);
+  ::decode(got_version, p);
 
   dout(10) << "_fetched version " << got_version
           << ", " << len << " bytes"
           << dendl;
   
   int32_t n;
-  ::_decode(n, bl, off);
+  ::decode(n, p);
 
   //int num_new_inodes_loaded = 0;
 
   for (int i=0; i<n; i++) {
-    off_t dn_offset = off;
+    off_t dn_offset = p.get_off();
 
     // marker
-    char type = bl[off];
-    ++off;
+    char type;
+    ::decode(type, p);
 
     // dname
     string dname;
-    ::_decode(dname, bl, off);
+    ::decode(dname, p);
     dout(24) << "_fetched parsed marker '" << type << "' dname '" << dname << dendl;
     
     CDentry *dn = lookup(dname);  // existing dentry?
@@ -906,8 +906,8 @@ void CDir::_fetched(bufferlist &bl)
       // hard link
       inodeno_t ino;
       unsigned char d_type;
-      ::_decode(ino, bl, off);
-      ::_decode(d_type, bl, off);
+      ::decode(ino, p);
+      ::decode(d_type, p);
 
       if (dn) {
         if (dn->get_inode() == 0) {
@@ -934,14 +934,14 @@ void CDir::_fetched(bufferlist &bl)
       
       // parse out inode
       inode_t inode;
-      ::_decode(inode, bl, off);
+      ::decode(inode, p);
 
       string symlink;
       if (inode.is_symlink())
-        ::_decode(symlink, bl, off);
+        ::decode(symlink, p);
 
       fragtree_t fragtree;
-      fragtree._decode(bl, off);
+      ::decode(fragtree, p);
       
       if (dn) {
         if (dn->get_inode() == 0) {
@@ -983,8 +983,8 @@ void CDir::_fetched(bufferlist &bl)
        }
       }
     } else {
-      dout(1) << "corrupt directory, i got tag char '" << type << "' val " << (int)(type) 
-             << " at pos " << off << dendl;
+      dout(1) << "corrupt directory, i got tag char '" << type << "' val " << (int)(type)
+             << " at offset " << p.get_off() << dendl;
       assert(0);
     }
     
@@ -1017,7 +1017,7 @@ void CDir::_fetched(bufferlist &bl)
       }
     }
   }
-  //assert(off == len);   no, directories may shrink.  add this back in when we properly truncate objects on write.
+  //assert(off == len);  FIXME  no, directories may shrink.  add this back in when we properly truncate objects on write.
 
   // take the loaded version?
   // only if we are a fresh CDir* with no prior state.
@@ -1142,9 +1142,9 @@ void CDir::_commit(version_t want)
   // encode
   bufferlist bl;
 
-  ::_encode(version, bl);
+  ::encode(version, bl);
   int32_t n = nitems;
-  ::_encode(n, bl);
+  ::encode(n, bl);
 
   for (map_t::iterator it = items.begin();
        it != items.end();
@@ -1164,9 +1164,9 @@ void CDir::_commit(version_t want)
       
       // marker, name, ino
       bl.append( "L", 1 );         // remote link
-      ::_encode(it->first, bl);
-      ::_encode(ino, bl);
-      ::_encode(d_type, bl);
+      ::encode(it->first, bl);
+      ::encode(ino, bl);
+      ::encode(d_type, bl);
     } else {
       // primary link
       CInode *in = dn->get_inode();
@@ -1176,16 +1176,16 @@ void CDir::_commit(version_t want)
   
       // marker, name, inode, [symlink string]
       bl.append( "I", 1 );         // inode
-      ::_encode(it->first, bl);
-      ::_encode(in->inode, bl);
+      ::encode(it->first, bl);
+      ::encode(in->inode, bl);
       
       if (in->is_symlink()) {
         // include symlink destination!
         dout(18) << "    inlcuding symlink ptr " << in->symlink << dendl;
-       ::_encode(in->symlink, bl);
+       ::encode(in->symlink, bl);
       }
 
-      in->dirfragtree._encode(bl);
+      ::encode(in->dirfragtree, bl);
     }
   }
   assert(n == 0);
index f1c6fe8b522cd3201fb14ae3efb54dda62fc59f1..329b6f0a1c27d713ff6dcdb40c37e6086e0d2502 100644 (file)
@@ -505,6 +505,7 @@ class CDirDiscover {
     dir_rep = dir->dir_rep;
     rep_by = dir->dir_rep_by;
   }
+  CDirDiscover(bufferlist::iterator &p) { decode(p); }
 
   void update_dir(CDir *dir) {
     assert(dir->dirfrag() == dirfrag);
@@ -517,24 +518,22 @@ class CDirDiscover {
 
   dirfrag_t get_dirfrag() { return dirfrag; }
 
-  void _encode(bufferlist& bl) {
-    bl.append((char*)&dirfrag, sizeof(dirfrag));
-    bl.append((char*)&nonce, sizeof(nonce));
-    bl.append((char*)&dir_rep, sizeof(dir_rep));
-    ::_encode(rep_by, bl);
+  void encode(bufferlist& bl) const {
+    ::encode(dirfrag, bl);
+    ::encode(nonce, bl);
+    ::encode(dir_rep, bl);
+    ::encode(rep_by, bl);
   }
 
-  void _decode(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(dirfrag), (char*)&dirfrag);
-    off += sizeof(dirfrag);
-    bl.copy(off, sizeof(nonce), (char*)&nonce);
-    off += sizeof(nonce);
-    bl.copy(off, sizeof(dir_rep), (char*)&dir_rep);
-    off += sizeof(dir_rep);
-    ::_decode(rep_by, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(dirfrag, bl);
+    ::decode(nonce, bl);
+    ::decode(dir_rep, bl);
+    ::decode(rep_by, bl);
   }
 
 };
+WRITE_CLASS_ENCODERS(CDirDiscover)
 
 
 
index 4b6225f23f0e2858a8d82dcb0ac71665a5c2e80a..b8398ad41d6af1afe43a1c0b7bf9c6d946267f64 100644 (file)
@@ -496,7 +496,7 @@ void CInode::encode_lock_state(int type, bufferlist& bl)
   case CEPH_LOCK_IDFT:
     {
       // encode the raw tree
-      dirfragtree._encode(bl);
+      ::encode(dirfragtree, bl);
 
       // also specify which frags are mine
       set<frag_t> myfrags;
@@ -507,7 +507,7 @@ void CInode::encode_lock_state(int type, bufferlist& bl)
          frag_t fg = (*p)->get_frag();
          myfrags.insert(fg);
        }
-      _encode(myfrags, bl);
+      ::encode(myfrags, bl);
     }
     break;
     
@@ -539,31 +539,31 @@ void CInode::encode_lock_state(int type, bufferlist& bl)
 
 void CInode::decode_lock_state(int type, bufferlist& bl)
 {
-  int off = 0;
+  bufferlist::iterator p = bl.begin();
   utime_t tm;
 
   switch (type) {
   case CEPH_LOCK_IAUTH:
-    _decode(tm, bl, off);
+    ::decode(tm, p);
     if (inode.ctime < tm) inode.ctime = tm;
-    _decode(inode.mode, bl, off);
-    _decode(inode.uid, bl, off);
-    _decode(inode.gid, bl, off);
+    ::decode(inode.mode, p);
+    ::decode(inode.uid, p);
+    ::decode(inode.gid, p);
     break;
 
   case CEPH_LOCK_ILINK:
-    _decode(tm, bl, off);
+    ::decode(tm, p);
     if (inode.ctime < tm) inode.ctime = tm;
-    _decode(inode.nlink, bl, off);
-    _decode(inode.anchored, bl, off);
+    ::decode(inode.nlink, p);
+    ::decode(inode.anchored, p);
     break;
 
   case CEPH_LOCK_IDFT:
     {
       fragtree_t temp;
-      temp._decode(bl, off);
+      ::decode(temp, p);
       set<frag_t> authfrags;
-      _decode(authfrags, bl, off);
+      ::decode(authfrags, p);
       if (is_auth()) {
        // auth.  believe replica's auth frags only.
        for (set<frag_t>::iterator p = authfrags.begin(); p != authfrags.end(); ++p) 
@@ -576,14 +576,14 @@ void CInode::decode_lock_state(int type, bufferlist& bl)
     break;
 
   case CEPH_LOCK_IFILE:
-    _decode(inode.size, bl, off);
-    _decode(inode.mtime, bl, off);
-    _decode(inode.atime, bl, off);
+    ::decode(inode.size, p);
+    ::decode(inode.mtime, p);
+    ::decode(inode.atime, p);
     break;
 
   case CEPH_LOCK_IDIR:
-    //::_decode(inode.size, bl, off);
-    _decode(tm, bl, off);
+    //::_decode(inode.size, p);
+    ::decode(tm, p);
     if (inode.mtime < tm) {
       inode.mtime = tm;
       if (is_auth()) {
@@ -595,7 +595,7 @@ void CInode::decode_lock_state(int type, bufferlist& bl)
     }
     if (0) {
       map<frag_t,int> dfsz;
-      ::_decode(dfsz, bl, off);
+      ::decode(dfsz, p);
       // hmm which to keep?
     }
     break;
@@ -791,7 +791,7 @@ void CInode::encode_export(bufferlist& bl)
 {
   ::encode(inode, bl);
   ::encode(symlink, bl);
-  dirfragtree._encode(bl);
+  ::encode(dirfragtree, bl);
 
   bool dirty = is_dirty();
   ::encode(dirty, bl);
@@ -830,7 +830,7 @@ void CInode::decode_import(bufferlist::iterator& p,
   }
 
   ::decode(symlink, p);
-  dirfragtree._decode(p);
+  ::decode(dirfragtree, p);
 
   bool dirty;
   ::decode(dirty, p);
index 93352615f11ad8b3c4bb6987eaaea47503faf3e9..7e10ad4d55a3b69a43a1403c9e73d0bb5f59f558 100644 (file)
@@ -584,6 +584,9 @@ class CInodeDiscover {
     filelock_state = in->filelock.get_replica_state();
     dirlock_state = in->dirlock.get_replica_state();
   }
+  CInodeDiscover(bufferlist::iterator &p) {
+    decode(p);
+  }
 
   inodeno_t get_ino() { return inode.ino; }
   int get_replica_nonce() { return replica_nonce; }
@@ -602,32 +605,32 @@ class CInodeDiscover {
     in->dirlock.set_state(dirlock_state);
   }
   
-  void _encode(bufferlist& bl) {
-    ::_encode(inode, bl);
-    ::_encode(symlink, bl);
-    dirfragtree._encode(bl);
-    ::_encode(replica_nonce, bl);
-    ::_encode(authlock_state, bl);
-    ::_encode(linklock_state, bl);
-    ::_encode(dirfragtreelock_state, bl);
-    ::_encode(filelock_state, bl);
-    ::_encode(dirlock_state, bl);
-  }
-
-  void _decode(bufferlist& bl, int& off) {
-    ::_decode(inode, bl, off);
-    ::_decode(symlink, bl, off);
-    dirfragtree._decode(bl, off);
-    ::_decode(replica_nonce, bl, off);
-    ::_decode(authlock_state, bl, off);
-    ::_decode(linklock_state, bl, off);
-    ::_decode(dirfragtreelock_state, bl, off);
-    ::_decode(filelock_state, bl, off);
-    ::_decode(dirlock_state, bl, off);
+  void encode(bufferlist &bl) const {
+    ::encode(inode, bl);
+    ::encode(symlink, bl);
+    ::encode(dirfragtree, bl);
+    ::encode(replica_nonce, bl);
+    ::encode(authlock_state, bl);
+    ::encode(linklock_state, bl);
+    ::encode(dirfragtreelock_state, bl);
+    ::encode(filelock_state, bl);
+    ::encode(dirlock_state, bl);
+  }
+
+  void decode(bufferlist::iterator &p) {
+    ::decode(inode, p);
+    ::decode(symlink, p);
+    ::decode(dirfragtree, p);
+    ::decode(replica_nonce, p);
+    ::decode(authlock_state, p);
+    ::decode(linklock_state, p);
+    ::decode(dirfragtreelock_state, p);
+    ::decode(filelock_state, p);
+    ::decode(dirlock_state, p);
   }  
 
 };
-
+WRITE_CLASS_ENCODERS(CInodeDiscover)
 
 
 #endif
index 65b0bb2ec1322631dc824c512ed73541ae455829..949d400d334fc509cf6e7373de9f38a5b02327f1 100644 (file)
 LogEvent *LogEvent::decode(bufferlist& bl)
 {
   // parse type, length
-  int off = 0;
-  int type;
-  bl.copy(off, sizeof(type), (char*)&type);
-  off += sizeof(type);
+  bufferlist::iterator p = bl.begin();
+  __u32 type;
+  ::decode(type, p);
 
-  int length = bl.length() - off;
+  int length = bl.length() - p.get_off();
   generic_dout(15) << "decode_log_event type " << type << ", size " << length << dendl;
   
   assert(type > 0);
@@ -80,7 +79,7 @@ LogEvent *LogEvent::decode(bufferlist& bl)
   }
 
   // decode
-  le->decode_payload(bl, off);
+  le->decode(p);
   
   return le;
 }
index 8d36a1d515c1c03ad3a89376187de3d9b500ac09..ae806854fc1ba443122fb12adfd512b4edebc518 100644 (file)
@@ -50,7 +50,7 @@ class LogSegment;
 // generic log event
 class LogEvent {
  private:
-  int _type;
+  __u32 _type;
   off_t _start_off,_end_off;
 
   friend class MDLog;
@@ -67,8 +67,8 @@ class LogEvent {
   off_t get_end_off() { return _end_off; }
 
   // encoding
-  virtual void encode_payload(bufferlist& bl) = 0;
-  virtual void decode_payload(bufferlist& bl, int& off) = 0;
+  virtual void encode(bufferlist& bl) const = 0;
+  virtual void decode(bufferlist::iterator &bl) = 0;
   static LogEvent *decode(bufferlist &bl);
 
 
index e5dcd519c946a492899018bcc070a1bc6af97db3..064f91e978aaed4b925475d73f87f00f09eeae18 100644 (file)
@@ -5670,24 +5670,21 @@ CInode *MDCache::add_replica_inode(CInodeDiscover& dis, CDentry *dn, list<Contex
 CDentry *MDCache::add_replica_stray(bufferlist &bl, CInode *in, int from)
 {
   list<Context*> finished;
-  int off = 0;
+  bufferlist::iterator p = bl.begin();
   
   // inode
-  CInodeDiscover indis;
-  indis._decode(bl, off);
+  CInodeDiscover indis(p);
   CInode *strayin = add_replica_inode(indis, NULL, finished);
   dout(15) << "strayin " << *strayin << dendl;
   
   // dir
-  CDirDiscover dirdis;
-  dirdis._decode(bl, off);
+  CDirDiscover dirdis(p);
   CDir *straydir = add_replica_dir(strayin, dirdis.get_dirfrag().frag, dirdis,
                                            from, finished);
   dout(15) << "straydir " << *straydir << dendl;
   
   // dentry
-  CDentryDiscover dndis;
-  dndis._decode(bl, off);
+  CDentryDiscover dndis(p);
   
   string straydname;
   in->name_stray_dentry(straydname);
@@ -6198,7 +6195,7 @@ void MDCache::fragment_stored(CInode *diri, frag_t basefrag, int bits,
       // freshly replicate basedir to peer on merge
       CDir *base = resultfrags.front();
       CDirDiscover *basedis = base->replicate_to(*p);
-      basedis->_encode(notify->basebl);
+      basedis->encode(notify->basebl);
       delete basedis;
     }
     mds->send_message_mds(notify, *p);
@@ -6254,9 +6251,8 @@ void MDCache::handle_fragment_notify(MMDSFragmentNotify *notify)
     // add replica dir (for merge)?
     //  (adjust_dir_fragments expects base to already exist, if non-auth)
     if (notify->get_bits() < 0) {
-      CDirDiscover basedis;
-      int off = 0;
-      basedis._decode(notify->basebl, off);
+      bufferlist::iterator p = notify->basebl.begin();
+      CDirDiscover basedis(p);
       add_replica_dir(diri, notify->get_basefrag(), basedis,
                      notify->get_source().num(), waiters);
     }
index 3c080c871d0fffe911a77d6c96a153e86a9226f1..b9f1c0c4ef6cb4c96317c061480d6d6b1c2036bb 100644 (file)
@@ -164,8 +164,8 @@ void MDLog::submit_entry( LogEvent *le, Context *c )
   // encode it, with event type
   {
     bufferlist bl;
-    ::_encode(le->_type, bl);
-    le->encode_payload(bl);
+    ::encode(le->_type, bl);
+    le->encode(bl);
     
     // journal it.
     journaler->append_entry(bl);  // bl is destroyed.
index 379f02dd3ff64cf57c669a5409b0dc0ac8095b0a..cb21016cc492fd158d740ce9baaffd67eb28cf6b 100644 (file)
@@ -3189,9 +3189,9 @@ void Server::_rename_prepare_witness(MDRequest *mdr, int who, CDentry *srcdn, CD
     CInodeDiscover *indis = straydn->dir->inode->replicate_to(who);
     CDirDiscover *dirdis = straydn->dir->replicate_to(who);
     CDentryDiscover *dndis = straydn->replicate_to(who);
-    indis->_encode(req->stray);
-    dirdis->_encode(req->stray);
-    dndis->_encode(req->stray);
+    indis->encode(req->stray);
+    dirdis->encode(req->stray);
+    dndis->encode(req->stray);
     delete indis;
     delete dirdis;
     delete dndis;
index 97a21a36734bef39c0d894cfed6e7dc2b8ac7c66..a14dee103f1b30ae3985542cc92875c80a7c393d 100644 (file)
@@ -43,26 +43,21 @@ protected:
   void set_trace(vector<Anchor>& t) { trace = t; }
   vector<Anchor>& get_trace() { return trace; }
   
-  void encode_payload(bufferlist& bl) {
-    bl.append((char*)&op, sizeof(op));
-    bl.append((char*)&ino, sizeof(ino));
-    bl.append((char*)&atid, sizeof(atid));
-    ::_encode(trace, bl);
-    bl.append((char*)&version, sizeof(version));
-    bl.append((char*)&reqmds, sizeof(reqmds));
+  void encode(bufferlist& bl) const {
+    ::encode(op, bl);
+    ::encode(ino, bl);
+    ::encode(atid, bl);
+    ::encode(trace, bl);
+    ::encode(version, bl);
+    ::encode(reqmds, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(op), (char*)&op);
-    off += sizeof(op);
-    bl.copy(off, sizeof(ino), (char*)&ino);
-    off += sizeof(ino);
-    bl.copy(off, sizeof(atid), (char*)&atid);
-    off += sizeof(atid);
-    ::_decode(trace, bl, off);
-    bl.copy(off, sizeof(version), (char*)&version);
-    off += sizeof(version);
-    bl.copy(off, sizeof(reqmds), (char*)&reqmds);
-    off += sizeof(reqmds);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(op, bl);
+    ::decode(ino, bl);
+    ::decode(atid, bl);
+    ::decode(trace, bl);
+    ::decode(version, bl);
+    ::decode(reqmds, bl);
   }
 
   void print(ostream& out) {
index 21f78369cae72a956981892574114c81977ddcad..4fb9dd1ff5d521f73ff052b2371bac7cfbc92e9a 100644 (file)
@@ -33,15 +33,13 @@ protected:
     LogEvent(EVENT_ANCHORCLIENT),
     op(o), atid(at) { }
 
-  void encode_payload(bufferlist& bl) {
-    bl.append((char*)&op, sizeof(op));
-    bl.append((char*)&atid, sizeof(atid));
+  void encode(bufferlist &bl) const {
+    ::encode(op, bl);
+    ::encode(atid, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(op), (char*)&op);
-    off += sizeof(op);
-    bl.copy(off, sizeof(atid), (char*)&atid);
-    off += sizeof(atid);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(op, bl);
+    ::decode(atid, bl);
   }
 
   void print(ostream& out) {
index f7b247eec16e8abca2c0ea53198dbe63e4846be1..bd1392259b6a95fc8231444d69db185618731bd7 100644 (file)
@@ -42,16 +42,15 @@ public:
     out << "EExport " << base << " " << metablob;
   }
 
-  virtual void encode_payload(bufferlist& bl) {
-    metablob._encode(bl);
-    bl.append((char*)&base, sizeof(base));
-    ::_encode(bounds, bl);
+  void encode(bufferlist& bl) const {
+    ::encode(metablob, bl);
+    ::encode(base, bl);
+    ::encode(bounds, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    metablob._decode(bl, off);
-    bl.copy(off, sizeof(base), (char*)&base);
-    off += sizeof(base);
-    ::_decode(bounds, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(metablob, bl);
+    ::decode(base, bl);
+    ::decode(bounds, bl);
   }
   
   void replay(MDS *mds);
index e47fdb82be2696f975478d941b4d4358dbff68f1..56aeadb6c7bd1afb9b91df2913dca92f614f51fe 100644 (file)
@@ -33,17 +33,17 @@ public:
     out << "EFragment " << ino << " " << basefrag << " by " << bits << " " << metablob;
   }
 
-  void encode_payload(bufferlist& bl) {
-    ::_encode(ino, bl);
-    ::_encode(basefrag, bl);
-    ::_encode(bits, bl);
-    metablob._encode(bl);
+  void encode(bufferlist &bl) const {
+    ::encode(ino, bl);
+    ::encode(basefrag, bl);
+    ::encode(bits, bl);
+    ::encode(metablob, bl);
   } 
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(ino, bl, off);
-    ::_decode(basefrag, bl, off);
-    ::_decode(bits, bl, off);
-    metablob._decode(bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(ino, bl);
+    ::decode(basefrag, bl);
+    ::decode(bits, bl);
+    ::decode(metablob, bl);
   }
 
   void replay(MDS *mds);
index 91f5069514c6d877367eba96182ed549ca27436b..b4443b93812837aa52a8fac208872fbe6505cbf0 100644 (file)
@@ -40,15 +40,13 @@ class EImportFinish : public LogEvent {
       out << " failed";
   }
 
-  virtual void encode_payload(bufferlist& bl) {
-    bl.append((char*)&base, sizeof(base));
-    bl.append((char*)&success, sizeof(success));
+  void encode(bufferlist& bl) const {
+    ::encode(base, bl);
+    ::encode(success, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(base), (char*)&base);
-    off += sizeof(base);
-    bl.copy(off, sizeof(success), (char*)&success);
-    off += sizeof(success);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(base, bl);
+    ::decode(success, bl);
   }
   
   void replay(MDS *mds);
index 2c48cd5366a3a845050c49be0a810842b5fb8500..bb5be9b6fc3558b02a3899389ec255d34a82505f 100644 (file)
@@ -42,20 +42,19 @@ protected:
     out << "EImportStart " << base << " " << metablob;
   }
   
-  virtual void encode_payload(bufferlist& bl) {
-    bl.append((char*)&base, sizeof(base));
-    metablob._encode(bl);
-    ::_encode(bounds, bl);
-    ::_encode(cmapv, bl);
-    ::_encode(client_map, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(base, bl);
+    ::encode(metablob, bl);
+    ::encode(bounds, bl);
+    ::encode(cmapv, bl);
+    ::encode(client_map, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    bl.copy(off, sizeof(base), (char*)&base);
-    off += sizeof(base);
-    metablob._decode(bl, off);
-    ::_decode(bounds, bl, off);
-    ::_decode(cmapv, bl, off);
-    ::_decode(client_map, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(base, bl);
+    ::decode(metablob, bl);
+    ::decode(bounds, bl);
+    ::decode(cmapv, bl);
+    ::decode(client_map, bl);
   }
   
   void replay(MDS *mds);
index ace218020edfe74aef14446608f1ff11f7c5d95b..ea0e4a415c3d7d88b2204d90ac3963278eff3edb 100644 (file)
@@ -46,6 +46,7 @@ class LogSegment;
 
 class EMetaBlob {
 
+public:
   /* fullbit - a regular dentry + inode
    */
   struct fullbit {
@@ -60,24 +61,26 @@ class EMetaBlob {
       dn(d), dnv(v), inode(i), dirfragtree(dft), dirty(dr) { }
     fullbit(const string& d, version_t v, inode_t& i, fragtree_t dft, string& sym, bool dr) :
       dn(d), dnv(v), inode(i), dirfragtree(dft), symlink(sym), dirty(dr) { }
-    fullbit(bufferlist& bl, int& off) { _decode(bl, off); }
-    void _encode(bufferlist& bl) {
-      ::_encode(dn, bl);
-      ::_encode(dnv, bl);
-      ::_encode(inode, bl);
-      dirfragtree._encode(bl);
+    fullbit(bufferlist::iterator &p) { decode(p); }
+    fullbit() {}
+
+    void encode(bufferlist& bl) const {
+      ::encode(dn, bl);
+      ::encode(dnv, bl);
+      ::encode(inode, bl);
+      ::encode(dirfragtree, bl);
       if (inode.is_symlink())
-       ::_encode(symlink, bl);
-      ::_encode(dirty, bl);
+       ::encode(symlink, bl);
+      ::encode(dirty, bl);
     }
-    void _decode(bufferlist& bl, int& off) {
-      ::_decode(dn, bl, off);
-      ::_decode(dnv, bl, off);
-      ::_decode(inode, bl, off);
-      dirfragtree._decode(bl, off);
+    void decode(bufferlist::iterator &bl) {
+      ::decode(dn, bl);
+      ::decode(dnv, bl);
+      ::decode(inode, bl);
+      ::decode(dirfragtree, bl);
       if (inode.is_symlink())
-       ::_decode(symlink, bl, off);
-      ::_decode(dirty, bl, off);
+       ::decode(symlink, bl);
+      ::decode(dirty, bl);
     }
     void print(ostream& out) {
       out << " fullbit dn " << dn << " dnv " << dnv
@@ -85,6 +88,7 @@ class EMetaBlob {
          << " dirty=" << dirty << std::endl;
     }
   };
+  WRITE_CLASS_ENCODERS(fullbit)
   
   /* remotebit - a dentry + remote inode link (i.e. just an ino)
    */
@@ -97,20 +101,22 @@ class EMetaBlob {
 
     remotebit(const string& d, version_t v, inodeno_t i, unsigned char dt, bool dr) : 
       dn(d), dnv(v), ino(i), d_type(dt), dirty(dr) { }
-    remotebit(bufferlist& bl, int& off) { _decode(bl, off); }
-    void _encode(bufferlist& bl) {
-      ::_encode(dn, bl);
-      ::_encode(dnv, bl);
-      ::_encode(ino, bl);
-      ::_encode(d_type, bl);
-      ::_encode(dirty, bl);
+    remotebit(bufferlist::iterator &p) { decode(p); }
+    remotebit() {}
+
+    void encode(bufferlist& bl) const {
+      ::encode(dn, bl);
+      ::encode(dnv, bl);
+      ::encode(ino, bl);
+      ::encode(d_type, bl);
+      ::encode(dirty, bl);
     }
-    void _decode(bufferlist& bl, int& off) {
-      ::_decode(dn, bl, off);
-      ::_decode(dnv, bl, off);
-      ::_decode(ino, bl, off);
-      ::_decode(d_type, bl, off);
-      ::_decode(dirty, bl, off);
+    void decode(bufferlist::iterator &bl) {
+      ::decode(dn, bl);
+      ::decode(dnv, bl);
+      ::decode(ino, bl);
+      ::decode(d_type, bl);
+      ::decode(dirty, bl);
     }
     void print(ostream& out) {
       out << " remotebit dn " << dn << " dnv " << dnv
@@ -118,6 +124,7 @@ class EMetaBlob {
          << " dirty=" << dirty << std::endl;
     }
   };
+  WRITE_CLASS_ENCODERS(remotebit)
 
   /*
    * nullbit - a null dentry
@@ -126,23 +133,27 @@ class EMetaBlob {
     string dn;
     version_t dnv;
     bool dirty;
+
     nullbit(const string& d, version_t v, bool dr) : dn(d), dnv(v), dirty(dr) { }
-    nullbit(bufferlist& bl, int& off) { _decode(bl, off); }
-    void _encode(bufferlist& bl) {
-      ::_encode(dn, bl);
-      ::_encode(dnv, bl);
-      ::_encode(dirty, bl);
+    nullbit(bufferlist::iterator &p) { decode(p); }
+    nullbit() {}
+
+    void encode(bufferlist& bl) const {
+      ::encode(dn, bl);
+      ::encode(dnv, bl);
+      ::encode(dirty, bl);
     }
-    void _decode(bufferlist& bl, int& off) {
-      ::_decode(dn, bl, off);
-      ::_decode(dnv, bl, off);
-      ::_decode(dirty, bl, off);
+    void decode(bufferlist::iterator &bl) {
+      ::decode(dn, bl);
+      ::decode(dnv, bl);
+      ::decode(dirty, bl);
     }
     void print(ostream& out) {
       out << " nullbit dn " << dn << " dnv " << dnv
          << " dirty=" << dirty << std::endl;
     }
   };
+  WRITE_CLASS_ENCODERS(nullbit)
 
 
   /* dirlump - contains metadata for any dir we have contents for.
@@ -157,7 +168,7 @@ public:
     int nfull, nremote, nnull;
 
   private:
-    bufferlist dnbl;
+    mutable bufferlist dnbl;
     bool dn_decoded;
     list<fullbit>   dfull;
     list<remotebit> dremote;
@@ -189,45 +200,40 @@ public:
        p->print(out);
     }
 
-    void _encode_bits() {
-      for (list<fullbit>::iterator p = dfull.begin(); p != dfull.end(); ++p)
-       p->_encode(dnbl);
-      for (list<remotebit>::iterator p = dremote.begin(); p != dremote.end(); ++p)
-       p->_encode(dnbl);
-      for (list<nullbit>::iterator p = dnull.begin(); p != dnull.end(); ++p)
-       p->_encode(dnbl);
+    void _encode_bits() const {
+      ::encode(dfull, dnbl);
+      ::encode(dremote, dnbl);
+      ::encode(dnull, dnbl);
     }
     void _decode_bits() { 
       if (dn_decoded) return;
-      int off = 0;
-      for (int i=0; i<nfull; i++) 
-       dfull.push_back(fullbit(dnbl, off));
-      for (int i=0; i<nremote; i++) 
-       dremote.push_back(remotebit(dnbl, off));
-      for (int i=0; i<nnull; i++) 
-       dnull.push_back(nullbit(dnbl, off));
+      bufferlist::iterator p = dnbl.begin();
+      ::decode(dfull, p);
+      ::decode(dremote, p);
+      ::decode(dnull, p);
       dn_decoded = true;
     }
 
-    void _encode(bufferlist& bl) {
-      ::_encode(dirv, bl);
-      ::_encode(state, bl);
-      ::_encode(nfull, bl);
-      ::_encode(nremote, bl);
-      ::_encode(nnull, bl);
+    void encode(bufferlist& bl) const {
+      ::encode(dirv, bl);
+      ::encode(state, bl);
+      ::encode(nfull, bl);
+      ::encode(nremote, bl);
+      ::encode(nnull, bl);
       _encode_bits();
-      ::_encode_destructively(dnbl, bl);
+      ::encode(dnbl, bl);
     }
-    void _decode(bufferlist& bl, int& off) {
-      ::_decode(dirv, bl, off);
-      ::_decode(state, bl, off);
-      ::_decode(nfull, bl, off);
-      ::_decode(nremote, bl, off);
-      ::_decode(nnull, bl, off);
-      ::_decode(dnbl, bl, off);
+    void decode(bufferlist::iterator &bl) {
+      ::decode(dirv, bl);
+      ::decode(state, bl);
+      ::decode(nfull, bl);
+      ::decode(nremote, bl);
+      ::decode(nnull, bl);
+      ::decode(dnbl, bl);
       dn_decoded = false;      // don't decode bits unless we need them.
     }
   };
+  WRITE_CLASS_ENCODERS(dirlump)
 
 private:
   // my lumps.  preserve the order we added them in a list.
@@ -442,42 +448,27 @@ private:
 
   // encoding
 
-  void _encode(bufferlist& bl) {
-    int32_t n = lump_map.size();
-    ::_encode(n, bl);
-    for (list<dirfrag_t>::iterator i = lump_order.begin();
-        i != lump_order.end();
-        ++i) {
-      dirfrag_t dirfrag = *i;
-      ::_encode(dirfrag, bl);
-      lump_map[*i]._encode(bl);
-    }
-    ::_encode(atids, bl);
-    ::_encode(dirty_inode_mtimes, bl);
-    ::_encode(allocated_inos, bl);
+  void encode(bufferlist& bl) const {
+    ::encode(lump_map, bl);
+    ::encode(atids, bl);
+    ::encode(dirty_inode_mtimes, bl);
+    ::encode(allocated_inos, bl);
     if (!allocated_inos.empty())
-      ::_encode(alloc_tablev, bl);
-    ::_encode(truncated_inodes, bl);
-    ::_encode(client_reqs, bl);
+      ::encode(alloc_tablev, bl);
+    ::encode(truncated_inodes, bl);
+    ::encode(client_reqs, bl);
   } 
-  void _decode(bufferlist& bl, int& off) {
-    int32_t n;
-    ::_decode(n, bl, off);
-    for (int i=0; i<n; i++) {
-      dirfrag_t dirfrag; 
-      ::_decode(dirfrag, bl, off);
-      lump_order.push_back(dirfrag);
-      lump_map[dirfrag]._decode(bl, off);
-    }
-    ::_decode(atids, bl, off);
-    ::_decode(dirty_inode_mtimes, bl, off);
-    ::_decode(allocated_inos, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(lump_map, bl);
+    ::decode(atids, bl);
+    ::decode(dirty_inode_mtimes, bl);
+    ::decode(allocated_inos, bl);
     if (!allocated_inos.empty())
-      ::_decode(alloc_tablev, bl, off);
-    ::_decode(truncated_inodes, bl, off);
-    ::_decode(client_reqs, bl, off);
+      ::decode(alloc_tablev, bl);
+    ::decode(truncated_inodes, bl);
+    ::decode(client_reqs, bl);
   }
-  
   void print(ostream& out) const {
     out << "[metablob";
     if (!lump_order.empty()) 
@@ -492,6 +483,11 @@ private:
   void update_segment(LogSegment *ls);
   void replay(MDS *mds, LogSegment *ls=0);
 };
+WRITE_CLASS_ENCODERS(EMetaBlob)
+WRITE_CLASS_ENCODERS(EMetaBlob::fullbit)
+WRITE_CLASS_ENCODERS(EMetaBlob::remotebit)
+WRITE_CLASS_ENCODERS(EMetaBlob::nullbit)
+WRITE_CLASS_ENCODERS(EMetaBlob::dirlump)
 
 inline ostream& operator<<(ostream& out, const EMetaBlob& t) {
   t.print(out);
index ffd1848537494a39533a56385714e2ddaece0e1a..acb3bf77586eae2a8220f2a3ec16e891ff7ca71e 100644 (file)
@@ -43,13 +43,13 @@ public:
     inos.push_back(ino);
   }
 
-  void encode_payload(bufferlist& bl) {
-    metablob._encode(bl);
-    ::_encode(inos, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(metablob, bl);
+    ::encode(inos, bl);
   } 
-  void decode_payload(bufferlist& bl, int& off) {
-    metablob._decode(bl, off);
-    ::_decode(inos, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(metablob, bl);
+    ::decode(inos, bl);
   }
 
   void update_segment();
index 6f8d2543c33ea7c7073a1b113e3075afc50fb714..f666ea77816b3aaf3d6b1c7f85c6c26670bea06a 100644 (file)
@@ -34,15 +34,15 @@ class EPurgeFinish : public LogEvent {
     out << "purgefinish " << ino << " " << oldsize << " ->" << newsize;
   }
 
-  virtual void encode_payload(bufferlist& bl) {
-    bl.append((char*)&ino, sizeof(ino));
-    bl.append((char*)&newsize, sizeof(newsize));
-    bl.append((char*)&oldsize, sizeof(oldsize));
+  void encode(bufferlist &bl) const {
+    ::encode(ino, bl);
+    ::encode(newsize, bl);
+    ::encode(oldsize, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(ino, bl, off);
-    ::_decode(newsize, bl, off);
-    ::_decode(oldsize, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(ino, bl);
+    ::decode(newsize, bl);
+    ::decode(oldsize, bl);
   }
   
   void update_segment();
index b8a3b857d0e90e748ed872fd7bdf21326882d208..4e3f2d582394a100c63eba2efc962d9d2fe8bb89 100644 (file)
@@ -36,15 +36,15 @@ class ESession : public LogEvent {
     cmapv(v) {
   }
   
-  void encode_payload(bufferlist& bl) {
-    ::_encode(client_inst, bl);
-    ::_encode(open, bl);
-    ::_encode(cmapv, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(client_inst, bl);
+    ::encode(open, bl);
+    ::encode(cmapv, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(client_inst, bl, off);
-    ::_decode(open, bl, off);
-    ::_decode(cmapv, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(client_inst, bl);
+    ::decode(open, bl);
+    ::decode(cmapv, bl);
   }
 
 
index 0db175c94887709f45de8b92485c764ce52ef157..8633f41675a22f96709ee829d9914fb4832cca6c 100644 (file)
@@ -34,13 +34,13 @@ public:
     cmapv(v) {
   }
   
-  void encode_payload(bufferlist& bl) {
-    ::_encode(client_map, bl);
-    ::_encode(cmapv, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(client_map, bl);
+    ::encode(cmapv, bl);
   }
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(client_map, bl, off);
-    ::_decode(cmapv, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(client_map, bl);
+    ::decode(cmapv, bl);
   }
 
 
index 2f289ca1649f580004c646cd65f660b3e09c5beb..5410e7459bfe93e68c1d1f3f67c7972e462a1759 100644 (file)
@@ -54,21 +54,21 @@ public:
     out << commit << " " << rollback;
   }
 
-  void encode_payload(bufferlist& bl) {
-    ::_encode(type, bl);
-    ::_encode(reqid, bl);
-    ::_encode(master, bl);
-    ::_encode(op, bl);
-    commit._encode(bl);
-    rollback._encode(bl);
+  void encode(bufferlist &bl) const {
+    ::encode(type, bl);
+    ::encode(reqid, bl);
+    ::encode(master, bl);
+    ::encode(op, bl);
+    ::encode(commit, bl);
+    ::encode(rollback, bl);
   } 
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(type, bl, off);
-    ::_decode(reqid, bl, off);
-    ::_decode(master, bl, off);
-    ::_decode(op, bl, off);
-    commit._decode(bl, off);
-    rollback._decode(bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(type, bl);
+    ::decode(reqid, bl);
+    ::decode(master, bl);
+    ::decode(op, bl);
+    ::decode(commit, bl);
+    ::decode(rollback, bl);
   }
 
   void replay(MDS *mds);
index c22c22b38191e06f7e98e46a308116a412109db7..83d5d0c33fc018a0435ac0698a3555eda0ee0741 100644 (file)
@@ -36,11 +36,11 @@ class EString : public LogEvent {
     LogEvent(EVENT_STRING) {
   }
 
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(event, bl, off);
+  void encode(bufferlist& bl) const {
+    ::encode(event, bl);
   }
-  void encode_payload(bufferlist& bl) {
-    ::_encode(event, bl);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(event, bl);
   }
 
   void print(ostream& out) {
index 80838114f50f418703d5ca1cc0e54a665d0b1d4e..28a5c5cbddb9d5231a1feb71cb38d6ed7d5f2492 100644 (file)
@@ -30,13 +30,13 @@ public:
        << metablob;
   }
 
-  void encode_payload(bufferlist& bl) {
-    metablob._encode(bl);
-    ::_encode(subtrees, bl);
+  void encode(bufferlist& bl) const {
+    ::encode(metablob, bl);
+    ::encode(subtrees, bl);
   } 
-  void decode_payload(bufferlist& bl, int& off) {
-    metablob._decode(bl, off);
-    ::_decode(subtrees, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(metablob, bl);
+    ::decode(subtrees, bl);
   }
 
   void replay(MDS *mds);
index 3939527cef41ccae7c32c9bb3410c2295d89dd95..d76bde19a0bc45b41d38b85a637c1f13017ef9d9 100644 (file)
@@ -35,15 +35,15 @@ public:
     out << metablob;
   }
 
-  void encode_payload(bufferlist& bl) {
-    ::_encode(type, bl);
-    metablob._encode(bl);
-    ::_encode(client_map, bl);
+  void encode(bufferlist &bl) const {
+    ::encode(type, bl);
+    ::encode(metablob, bl);
+    ::encode(client_map, bl);
   } 
-  void decode_payload(bufferlist& bl, int& off) {
-    ::_decode(type, bl, off);
-    metablob._decode(bl, off);
-    ::_decode(client_map, bl, off);
+  void decode(bufferlist::iterator &bl) {
+    ::decode(type, bl);
+    ::decode(metablob, bl);
+    ::decode(client_map, bl);
   }
 
   void update_segment();
index e48a250a94c0c0fc4164d6d04f3c437d26ff6592..3a48f72a205ad767cd72e1d30be148dd2b96104f 100644 (file)
@@ -53,21 +53,18 @@ class MAnchor : public Message {
   version_t get_atid() { return atid; }
 
   virtual void decode_payload() {
-    int off = 0;
-    payload.copy(off, sizeof(op), (char*)&op);
-    off += sizeof(op);
-    payload.copy(off, sizeof(ino), (char*)&ino);
-    off += sizeof(ino);
-    payload.copy(off, sizeof(atid), (char*)&atid);
-    off += sizeof(atid);
-    ::_decode(trace, payload, off);
+    bufferlist::iterator p = payload.begin();
+    ::decode(op, p);
+    ::decode(ino, p);
+    ::decode(atid, p);
+    ::decode(trace, p);
   }
 
   virtual void encode_payload() {
-    payload.append((char*)&op, sizeof(op));
-    payload.append((char*)&ino, sizeof(ino));
-    payload.append((char*)&atid, sizeof(atid));
-    ::_encode(trace, payload);
+    ::encode(op, payload);
+    ::encode(ino, payload);
+    ::encode(atid, payload);
+    ::encode(trace, payload);
   }
 };
 
index ff6ad1e3ad2607c8420bbe225ed96d58db56c58f..af99f36e8b0354804d71bbea3705ef1a13936f7a 100644 (file)
@@ -27,7 +27,20 @@ public:
     map<inodeno_t, int> inodes;
     map<dirfrag_t, int> dirs;
     map<dirfrag_t, map<string,int> > dentries;
+
+    void encode(bufferlist &bl) const {
+      ::encode(inodes, bl);
+      ::encode(dirs, bl);
+      ::encode(dentries, bl);
+    }
+    void decode(bufferlist::iterator &bl) {
+      ::decode(inodes, bl);
+      ::decode(dirs, bl);
+      ::decode(dentries, bl);
+    }
   };
+  WRITE_CLASS_ENCODERS(realm)
+
   map<dirfrag_t, realm> realms;
 
   int get_from() { return from; }
@@ -69,59 +82,17 @@ public:
   }
 
   void decode_payload() {
-    int off = 0;
-
-    payload.copy(off, sizeof(from), (char*)&from);
-    off += sizeof(from);
-
-    int nr;
-    payload.copy(off, sizeof(nr), (char*)&nr);
-    off += sizeof(nr);
-
-    while (nr--) {
-      dirfrag_t r;
-      payload.copy(off, sizeof(r), (char*)&r);
-      off += sizeof(r);
-      
-      ::_decode(realms[r].inodes, payload, off);
-      ::_decode(realms[r].dirs, payload, off);
-
-      int n;
-      payload.copy(off, sizeof(int), (char*)&n);
-      off += sizeof(int);
-      for (int i=0; i<n; i++) {
-       dirfrag_t df;
-       payload.copy(off, sizeof(df), (char*)&df);
-       off += sizeof(df);
-       ::_decode(realms[r].dentries[df], payload, off);
-      }
-    }
+    bufferlist::iterator p = payload.begin();
+    ::decode(from, p);
+    ::decode(realms, p);
   }
     
   void encode_payload() {
-    payload.append((char*)&from, sizeof(from));
-
-    int nr = realms.size();
-    payload.append((char*)&nr, sizeof(nr));
-
-    for (map<dirfrag_t,realm>::iterator q = realms.begin();
-        q != realms.end();
-        ++q) {
-      payload.append((char*)&q->first, sizeof(q->first));
-
-      ::_encode(q->second.inodes, payload);
-      ::_encode(q->second.dirs, payload);
-      
-      int n = q->second.dentries.size();
-      payload.append((char*)&n, sizeof(n));
-      for (map<dirfrag_t, map<string,int> >::iterator p = q->second.dentries.begin();
-          p != q->second.dentries.end();
-          ++p) {
-       payload.append((char*)&p->first, sizeof(p->first));
-       ::_encode(p->second, payload);
-      }
-    }
+    ::encode(from, payload);
+    ::encode(realms, payload);
   }
 };
 
+WRITE_CLASS_ENCODERS(MCacheExpire::realm)
+
 #endif
index 1f79abbaff1a9aedec647e9e6cc3a7a628f90ea1..0a50487667192391534489c18a5c4b26cac80776 100644 (file)
@@ -48,33 +48,28 @@ class MDentryUnlink : public Message {
   }
   
   void decode_payload() {
-    int off = 0;
-    payload.copy(off, sizeof(dirfrag), (char*)&dirfrag);
-    off += sizeof(dirfrag);
-    ::_decode(dn, payload, off);
+    bufferlist::iterator p = payload.begin();
+    ::decode(dirfrag, p);
+    ::decode(dn, p);
 
     bool isstray;
-    payload.copy(off, sizeof(isstray), (char*)&isstray);
-    off += sizeof(isstray);
+    ::decode(isstray, p);
     if (isstray) {
-      strayin = new CInodeDiscover;
-      strayin->_decode(payload, off);
-      straydir = new CDirDiscover;
-      straydir->_decode(payload, off);
-      straydn = new CDentryDiscover;
-      straydn->_decode(payload, off);
+      strayin = new CInodeDiscover(p);
+      straydir = new CDirDiscover(p);
+      straydn = new CDentryDiscover(p);
     }
   }
   void encode_payload() {
-    payload.append((char*)&dirfrag,sizeof(dirfrag));
-    ::_encode(dn, payload);
+    ::encode(dirfrag, payload);
+    ::encode(dn, payload);
 
     bool isstray = strayin ? true:false;
-    payload.append((char*)&isstray, sizeof(isstray));
+    ::encode(isstray, payload);
     if (isstray) {
-      strayin->_encode(payload);
-      straydir->_encode(payload);
-      straydn->_encode(payload);
+      strayin->encode(payload);
+      straydir->encode(payload);
+      straydn->encode(payload);
     }
   }
 };
index 9aee1c652ce08d8cefa98baaa0a2f3065f3959af..d972ee32a629f611e864c4c8d43bc65875219084 100644 (file)
@@ -219,80 +219,39 @@ class MDiscoverReply : public Message {
 
   // ...
   virtual void decode_payload() {
-    int off = 0;
-    ::_decode(base_ino, payload, off);
-    ::_decode(base_dir_frag, payload, off);
-    ::_decode(wanted_base_dir, payload, off);
-    ::_decode(wanted_xlocked, payload, off);
-    ::_decode(flag_error_dn, payload, off);
-    ::_decode(flag_error_ino, payload, off);
-    ::_decode(flag_error_dir, payload, off);
-    ::_decode(no_base_dir, payload, off);
-    ::_decode(no_base_dentry, payload, off);
-    ::_decode(error_dentry, payload, off);
-    ::_decode(dir_auth_hint, payload, off);
+    bufferlist::iterator p = payload.begin();
+    ::decode(base_ino, p);
+    ::decode(base_dir_frag, p);
+    ::decode(wanted_base_dir, p);
+    ::decode(wanted_xlocked, p);
+    ::decode(flag_error_dn, p);
+    ::decode(flag_error_ino, p);
+    ::decode(flag_error_dir, p);
+    ::decode(no_base_dir, p);
+    ::decode(no_base_dentry, p);
+    ::decode(error_dentry, p);
+    ::decode(dir_auth_hint, p);
     
-    // dirs
-    int n;
-    payload.copy(off, sizeof(int), (char*)&n);
-    off += sizeof(int);
-    for (int i=0; i<n; i++) {
-      dirs.push_back( new CDirDiscover() );
-      dirs[i]->_decode(payload, off);
-    }
-
-    // inodes
-    payload.copy(off, sizeof(int), (char*)&n);
-    off += sizeof(int);
-    for (int i=0; i<n; i++) {
-      inodes.push_back( new CInodeDiscover() );
-      inodes[i]->_decode(payload, off);
-    }
-
-    // dentries
-    payload.copy(off, sizeof(int), (char*)&n);
-    off += sizeof(int);
-    for (int i=0; i<n; i++) {
-      dentries.push_back( new CDentryDiscover() );
-      dentries[i]->_decode(payload, off);
-    }
+    ::decode(dirs, p);
+    ::decode(inodes, p);
+    ::decode(dentries, p);
   }
   void encode_payload() {
-    ::_encode(base_ino, payload);
-    ::_encode(base_dir_frag, payload);
-    ::_encode(wanted_base_dir, payload);
-    ::_encode(wanted_xlocked, payload);
-    ::_encode(flag_error_dn, payload);
-    ::_encode(flag_error_ino, payload);
-    ::_encode(flag_error_dir, payload);
-    ::_encode(no_base_dir, payload);
-    ::_encode(no_base_dentry, payload);
-    ::_encode(error_dentry, payload);
-    ::_encode(dir_auth_hint, payload);
-
-    // dirs
-    int n = dirs.size();
-    payload.append((char*)&n, sizeof(int));
-    for (vector<CDirDiscover*>::iterator it = dirs.begin();
-         it != dirs.end();
-         it++) 
-      (*it)->_encode( payload );
-    
-    // inodes
-    n = inodes.size();
-    payload.append((char*)&n, sizeof(int));
-    for (vector<CInodeDiscover*>::iterator it = inodes.begin();
-         it != inodes.end();
-         it++) 
-       (*it)->_encode( payload );
-
-    // dentries
-    n = dentries.size();
-    payload.append((char*)&n, sizeof(int));
-    for (vector<CDentryDiscover*>::iterator it = dentries.begin();
-         it != dentries.end();
-         it++) 
-       (*it)->_encode( payload );
+    ::encode(base_ino, payload);
+    ::encode(base_dir_frag, payload);
+    ::encode(wanted_base_dir, payload);
+    ::encode(wanted_xlocked, payload);
+    ::encode(flag_error_dn, payload);
+    ::encode(flag_error_ino, payload);
+    ::encode(flag_error_dir, payload);
+    ::encode(no_base_dir, payload);
+    ::encode(no_base_dentry, payload);
+    ::encode(error_dentry, payload);
+    ::encode(dir_auth_hint, payload);
+
+    ::encode(dirs, payload);
+    ::encode(inodes, payload);
+    ::encode(dentries, payload);
   }
 
 };
index cef43803751a5bc44f4d52f01d227370f86d9c8b..a6a5b5247d68823f77e6169d71b179c2cd9aa07a 100644 (file)
@@ -113,92 +113,28 @@ class MExportDirPrep : public Message {
   }
 
   virtual void decode_payload() {
-    int off = 0;
-    payload.copy(off, sizeof(dirfrag), (char*)&dirfrag);
-    off += sizeof(dirfrag);
-    
-    ::_decode(bounds, payload, off);
-    
-    // inodes
-    int ni;
-    payload.copy(off, sizeof(int), (char*)&ni);
-    off += sizeof(int);
-    for (int i=0; i<ni; i++) {
-      // inode
-      CInodeDiscover *in = new CInodeDiscover;
-      in->_decode(payload, off);
-      inodes.push_back(in);
-
-      // dentry
-      CDentryDiscover *dn = new CDentryDiscover;
-      dn->_decode(payload, off);
-      dentries.push_back(dn);
-      
-      // dentry
-      string d;
-      _decode(d, payload, off);
-      inode_dentry[in->get_ino()] = d;
-      
-      // dir ino
-      dirfrag_t df;
-      payload.copy(off, sizeof(df), (char*)&df);
-      off += sizeof(df);
-      inode_dirfrag[in->get_ino()] = df;
-
-      // child frags
-      ::_decode(frags_by_ino[in->get_ino()], payload, off);
-    }
-
-    // dirs
-    int nd;
-    payload.copy(off, sizeof(int), (char*)&nd);
-    off += sizeof(int);
-    for (int i=0; i<nd; i++) {
-      CDirDiscover *dir = new CDirDiscover;
-      dir->_decode(payload, off);
-      dirfrags[dir->get_dirfrag()] = dir;
-    }
-    
-    ::_decode(bystanders, payload, off);
+    bufferlist::iterator p = payload.begin();
+    ::decode(dirfrag, p);
+    ::decode(bounds, p);
+    ::decode(inodes, p);
+    ::decode(dentries, p);
+    ::decode(inode_dirfrag, p);
+    ::decode(inode_dentry, p);
+    ::decode(frags_by_ino, p);
+    ::decode(dirfrags, p);
+    ::decode(bystanders, p);
   }
 
   virtual void encode_payload() {
-    payload.append((char*)&dirfrag, sizeof(dirfrag));
-
-    ::_encode(bounds, payload);
-
-    // inodes
-    int ni = inodes.size();
-    payload.append((char*)&ni, sizeof(int));
-    list<CDentryDiscover*>::iterator dit = dentries.begin();
-    list<CInodeDiscover*>::iterator iit = inodes.begin();
-    while (iit != inodes.end()) {
-      (*iit)->_encode(payload);
-      (*dit)->_encode(payload);
-
-      // dentry name
-      _encode(inode_dentry[(*iit)->get_ino()], payload);
-
-      // dir ino
-      dirfrag_t df = inode_dirfrag[(*iit)->get_ino()];
-      payload.append((char*)&df, sizeof(df));
-
-      // child frags
-      ::_encode(frags_by_ino[(*iit)->get_ino()], payload);
-
-      iit++;
-      dit++;
-    }
-
-    // dirs
-    int nd = dirfrags.size();
-    payload.append((char*)&nd, sizeof(int));
-    for (map<dirfrag_t,CDirDiscover*>::iterator dit = dirfrags.begin();
-         dit != dirfrags.end();
-         dit++)
-      dit->second->_encode(payload);
-
-    ::_encode(bystanders, payload);
+    ::encode(dirfrag, payload);
+    ::encode(bounds, payload);
+    ::encode(inodes, payload);
+    ::encode(dentries, payload);
+    ::encode(inode_dirfrag, payload);
+    ::encode(inode_dentry, payload);
+    ::encode(frags_by_ino, payload);
+    ::encode(dirfrags, payload);
+    ::encode(bystanders, payload);
   }
 };
 
index 03a230f9fea8a98cfef1733bca23034af2d0a9c9..d943df638ed607c7af4c3ab3fd2ec5bc51ff6f07 100644 (file)
@@ -86,12 +86,12 @@ class MMDSCacheRejoin : public Message {
     void decode(bufferlist::iterator& p) {
       ::decode(inode, p);
       ::decode(symlink, p);
-      dirfragtree._decode(p);
+      ::decode(dirfragtree, p);
     }
     void encode(bufferlist& bl) const {
       ::encode(inode, bl);
       ::encode(symlink, bl);
-      dirfragtree._encode(bl);
+      ::encode(dirfragtree, bl);
     }
   };
   WRITE_CLASS_ENCODERS(inode_full)