summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGreg Farnum <greg@inktank.com>2013-02-01 05:31:13 +0100
committerGreg Farnum <greg@inktank.com>2013-02-08 22:17:52 +0100
commitdeb0d45c084434b914cb95f186d12b5b8f868a85 (patch)
treee4e5f5f7115154322fffd0abc629572887757117 /src
parentmds: EMetaBlob and its sub-parts use modern encoding now (diff)
downloadceph-deb0d45c084434b914cb95f186d12b5b8f868a85.tar.xz
ceph-deb0d45c084434b914cb95f186d12b5b8f868a85.zip
mds: EMetaBlob::full_bit more modernization for dencoder
While we're doing so, make the frag stream operator const! Signed-off-by: Greg Farnum <greg@inktank.com>
Diffstat (limited to 'src')
-rw-r--r--src/include/frag.h2
-rw-r--r--src/mds/events/EMetaBlob.h53
-rw-r--r--src/mds/journal.cc110
-rw-r--r--src/test/encoding/types.h2
4 files changed, 122 insertions, 45 deletions
diff --git a/src/include/frag.h b/src/include/frag.h
index a609833db9a..715eb098283 100644
--- a/src/include/frag.h
+++ b/src/include/frag.h
@@ -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(";
diff --git a/src/mds/events/EMetaBlob.h b/src/mds/events/EMetaBlob.h
index d241c508b82..3480490acfd 100644
--- a/src/mds/events/EMetaBlob.h
+++ b/src/mds/events/EMetaBlob.h
@@ -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;
diff --git a/src/mds/journal.cc b/src/mds/journal.cc
index c0d3d049709..def0ea61ea2 100644
--- a/src/mds/journal.cc
+++ b/src/mds/journal.cc
@@ -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)
{
diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h
index a6d185d76a0..5528f08910d 100644
--- a/src/test/encoding/types.h
+++ b/src/test/encoding/types.h
@@ -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