]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: EMetaBlob::full_bit more modernization for dencoder
authorGreg Farnum <greg@inktank.com>
Fri, 1 Feb 2013 04:31:13 +0000 (20:31 -0800)
committerGreg Farnum <greg@inktank.com>
Fri, 8 Feb 2013 21:17:52 +0000 (13:17 -0800)
While we're doing so, make the frag stream operator const!

Signed-off-by: Greg Farnum <greg@inktank.com>
src/include/frag.h
src/mds/events/EMetaBlob.h
src/mds/journal.cc
src/test/encoding/types.h

index a609833db9a48d67aa6423d4614ced5ad2aad82c..715eb09828391c7bf03f0e6dbefc66d3892bbbc6 100644 (file)
@@ -510,7 +510,7 @@ inline bool operator!=(const fragtree_t& l, const fragtree_t& r) {
   return l._splits != r._splits;
 }
 
-inline std::ostream& operator<<(std::ostream& out, fragtree_t& ft)
+inline std::ostream& operator<<(std::ostream& out, const fragtree_t& ft)
 {
   out << "fragtree_t(";
   
index d241c508b82383b04f5478471b5765748befbf8e..3480490acfd0e63a3e749d7b5f70fb40370607ed 100644 (file)
@@ -78,10 +78,10 @@ public:
     const fullbit& operator=(const fullbit& o);
 
     fullbit(const string& d, snapid_t df, snapid_t dl, 
-           version_t v, inode_t& i, fragtree_t &dft, 
-           map<string,bufferptr> &xa, const string& sym,
-           bufferlist &sbl, bool dr, file_layout_policy_t *defl = NULL,
-           old_inodes_t *oi = NULL) :
+           version_t v, const inode_t& i, const fragtree_t &dft, 
+           const map<string,bufferptr> &xa, const string& sym,
+           const bufferlist &sbl, bool dr, const file_layout_policy_t *defl = NULL,
+           const old_inodes_t *oi = NULL) :
       //dn(d), dnfirst(df), dnlast(dl), dnv(v), 
       //inode(i), dirfragtree(dft), xattrs(xa), symlink(sym), snapbl(sbl), dirty(dr) 
       dir_layout(NULL), _enc(1024)
@@ -114,48 +114,13 @@ public:
       delete dir_layout;
     }
 
-    void encode(bufferlist& bl) const {
-      assert(_enc.length());
-      ENCODE_START(4, 4, bl);
-      bl.append(_enc); 
-      ENCODE_FINISH(bl);
-    }
-    void decode(bufferlist::iterator &bl) {
-      DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, bl);
-      ::decode(dn, bl);
-      ::decode(dnfirst, bl);
-      ::decode(dnlast, bl);
-      ::decode(dnv, bl);
-      ::decode(inode, bl);
-      ::decode(xattrs, bl);
-      if (inode.is_symlink())
-       ::decode(symlink, bl);
-      if (inode.is_dir()) {
-       ::decode(dirfragtree, bl);
-       ::decode(snapbl, bl);
-       if (struct_v >= 2) {
-         bool dir_layout_exists;
-         ::decode(dir_layout_exists, bl);
-         if (dir_layout_exists) {
-           dir_layout = new file_layout_policy_t;
-           ::decode(*dir_layout, bl);
-         }
-       }
-      }
-      ::decode(dirty, bl);
-      if (struct_v >= 3) {
-       bool old_inodes_present;
-       ::decode(old_inodes_present, bl);
-       if (old_inodes_present) {
-         ::decode(old_inodes, bl);
-       }
-      }
-      DECODE_FINISH(bl);
-    }
-
+    void encode(bufferlist& bl) const;
+    void decode(bufferlist::iterator &bl);
+    void dump(Formatter *f) const;
+    static void generate_test_instances(list<EMetaBlob::fullbit*>& ls);
     void update_inode(MDS *mds, CInode *in);
 
-    void print(ostream& out) {
+    void print(ostream& out) const {
       out << " fullbit dn " << dn << " [" << dnfirst << "," << dnlast << "] dnv " << dnv
          << " inode " << inode.ino
          << " dirty=" << dirty << std::endl;
index c0d3d049709ab85a9f47d7a3bc5a16403f40c0b0..def0ea61ea28a3bea42ecd81538d369269a3056f 100644 (file)
@@ -378,6 +378,116 @@ void EMetaBlob::update_segment(LogSegment *ls)
   //if (!client_reqs.empty())
     //    ls->last_client_tid[client_reqs.rbegin()->client] = client_reqs.rbegin()->tid);
 }
+void EMetaBlob::fullbit::encode(bufferlist& bl) const {
+  ENCODE_START(4, 4, bl);
+  if (!_enc.length()) {
+    fullbit copy(dn, dnfirst, dnlast, dnv, inode, dirfragtree, xattrs, symlink,
+                snapbl, dirty, dir_layout, &old_inodes);
+    bl.append(copy._enc);
+  } else {
+    bl.append(_enc);
+  }
+  ENCODE_FINISH(bl);
+}
+
+void EMetaBlob::fullbit::decode(bufferlist::iterator &bl) {
+  DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, bl);
+  ::decode(dn, bl);
+  ::decode(dnfirst, bl);
+  ::decode(dnlast, bl);
+  ::decode(dnv, bl);
+  ::decode(inode, bl);
+  ::decode(xattrs, bl);
+  if (inode.is_symlink())
+    ::decode(symlink, bl);
+  if (inode.is_dir()) {
+    ::decode(dirfragtree, bl);
+    ::decode(snapbl, bl);
+    if (struct_v >= 2) {
+      bool dir_layout_exists;
+      ::decode(dir_layout_exists, bl);
+      if (dir_layout_exists) {
+       dir_layout = new file_layout_policy_t;
+       ::decode(*dir_layout, bl);
+      }
+    }
+  }
+  ::decode(dirty, bl);
+  if (struct_v >= 3) {
+    bool old_inodes_present;
+    ::decode(old_inodes_present, bl);
+    if (old_inodes_present) {
+      ::decode(old_inodes, bl);
+    }
+  }
+  DECODE_FINISH(bl);
+}
+
+void EMetaBlob::fullbit::dump(Formatter *f) const
+{
+  if (_enc.length() && !dn.length()) {
+    /* if our bufferlist has data but our name is empty, we
+     * haven't initialized ourselves; do so in order to print members!
+     * We use const_cast here because the whole point is we aren't
+     * fully set up and this isn't changing who we "are", just our
+     * representation.
+     */
+    EMetaBlob::fullbit *me = const_cast<EMetaBlob::fullbit*>(this);
+    bufferlist encoded;
+    encode(encoded);
+    bufferlist::iterator p = encoded.begin();
+    me->decode(p);
+  }
+  f->dump_string("dentry", dn);
+  f->dump_stream("snapid.first") << dnfirst;
+  f->dump_stream("snapid.last") << dnlast;
+  f->dump_int("dentry version", dnv);
+  f->open_object_section("inode");
+  inode.dump(f);
+  f->close_section(); // inode
+  f->open_array_section("xattrs");
+  for (map<string, bufferptr>::const_iterator iter = xattrs.begin();
+      iter != xattrs.end(); ++iter) {
+    f->dump_string(iter->first.c_str(), iter->second.c_str());
+  }
+  f->close_section(); // xattrs
+  if (inode.is_symlink()) {
+    f->dump_string("symlink", symlink);
+  }
+  if (inode.is_dir()) {
+    f->dump_stream("frag tree") << dirfragtree;
+    f->dump_string("has_snapbl", snapbl.length() ? "true" : "false");
+    if (dir_layout) {
+      f->open_object_section("file layout policy");
+      dir_layout->dump(f);
+      f->close_section(); // file layout policy
+    }
+  }
+  f->dump_string("dirty", dirty ? "true" : "false");
+  if (old_inodes.size()) {
+    f->open_array_section("old inodes");
+    for (old_inodes_t::const_iterator iter = old_inodes.begin();
+       iter != old_inodes.end(); ++iter) {
+      f->open_object_section("inode");
+      f->dump_int("snapid", iter->first);
+      iter->second.dump(f);
+      f->close_section(); // inode
+    }
+    f->close_section(); // old inodes
+  }
+}
+
+void EMetaBlob::fullbit::generate_test_instances(list<EMetaBlob::fullbit*>& ls)
+{
+  inode_t inode;
+  fragtree_t fragtree;
+  map<string,bufferptr> empty_xattrs;
+  bufferlist empty_snapbl;
+  fullbit *sample = new fullbit("/testdn", 0, 0, 0,
+                                inode, fragtree, empty_xattrs, "", empty_snapbl,
+                                false, NULL, NULL);
+  ls.push_back(sample);
+}
 
 void EMetaBlob::fullbit::update_inode(MDS *mds, CInode *in)
 {
index a6d185d76a03e83debe9c824a81bf03e928740e3..5528f08910d1bcaaeb516de889cf0d257f1e998b 100644 (file)
@@ -133,6 +133,8 @@ TYPE(EFragment)
 TYPE(EImportFinish)
 #include "mds/events/EImportStart.h"
 TYPE(EImportStart)
+#include "mds/events/EMetaBlob.h"
+TYPE(EMetaBlob::fullbit)
 
 #ifdef WITH_RADOSGW