From: Greg Farnum Date: Thu, 17 Jan 2013 18:03:19 +0000 (-0800) Subject: mds: SnapInfo, snaplink_t, sr_t now use modern encoding X-Git-Tag: v0.58~100^2~75 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08124fc72ecb25fd9d68ae0de2ed88386da0a6ee;p=ceph.git mds: SnapInfo, snaplink_t, sr_t now use modern encoding This commit doesn't enable the dencoder integration due to some build and compile issues, but we'll turn it on later. Signed-off-by: Sage Weil Signed-off-by: Greg Farnum --- diff --git a/src/mds/snap.cc b/src/mds/snap.cc index fa434b79d02..df1b73f1753 100644 --- a/src/mds/snap.cc +++ b/src/mds/snap.cc @@ -18,6 +18,174 @@ #include "messages/MClientSnap.h" +/* + * SnapInfo + */ + +void SnapInfo::encode(bufferlist& bl) const +{ + ENCODE_START(2, 2, bl); + ::encode(snapid, bl); + ::encode(ino, bl); + ::encode(stamp, bl); + ::encode(name, bl); + ENCODE_FINISH(bl); +} + +void SnapInfo::decode(bufferlist::iterator& bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); + ::decode(snapid, bl); + ::decode(ino, bl); + ::decode(stamp, bl); + ::decode(name, bl); + DECODE_FINISH(bl); +} + +void SnapInfo::dump(Formatter *f) const +{ + f->dump_unsigned("snapid", snapid); + f->dump_unsigned("ino", ino); + f->dump_stream("stamp") << stamp; + f->dump_string("name", name); +} + +void SnapInfo::generate_test_instances(list& ls) +{ + ls.push_back(new SnapInfo); + ls.push_back(new SnapInfo); + ls.back()->snapid = 1; + ls.back()->ino = 2; + ls.back()->stamp = utime_t(3, 4); + ls.back()->name = "foo"; +} + +ostream& operator<<(ostream& out, const SnapInfo &sn) +{ + return out << "snap(" << sn.snapid + << " " << sn.ino + << " '" << sn.name + << "' " << sn.stamp << ")"; +} + +/* + * snaplink_t + */ + +void snaplink_t::encode(bufferlist& bl) const +{ + ENCODE_START(2, 2, bl); + ::encode(ino, bl); + ::encode(first, bl); + ENCODE_FINISH(bl); +} + +void snaplink_t::decode(bufferlist::iterator& bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); + ::decode(ino, bl); + ::decode(first, bl); + DECODE_FINISH(bl); +} + +void snaplink_t::dump(Formatter *f) const +{ + f->dump_unsigned("ino", ino); + f->dump_unsigned("first", first); +} + +void snaplink_t::generate_test_instances(list& ls) +{ + ls.push_back(new snaplink_t); + ls.push_back(new snaplink_t); + ls.back()->ino = 2; + ls.back()->first = 123; +} + +ostream& operator<<(ostream& out, const snaplink_t &l) +{ + return out << l.ino << "@" << l.first; +} + +/* + * sr_t + */ + +void sr_t::encode(bufferlist& bl) const +{ + ENCODE_START(4, 4, bl); + ::encode(seq, bl); + ::encode(created, bl); + ::encode(last_created, bl); + ::encode(last_destroyed, bl); + ::encode(current_parent_since, bl); + ::encode(snaps, bl); + ::encode(past_parents, bl); + ENCODE_FINISH(bl); +} + +void sr_t::decode(bufferlist::iterator& p) +{ + DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, p); + if (struct_v == 2) { + __u8 struct_v; + ::decode(struct_v, p); // yes, really: extra byte for v2 encoding only, see 6ee52e7d. + } + ::decode(seq, p); + ::decode(created, p); + ::decode(last_created, p); + ::decode(last_destroyed, p); + ::decode(current_parent_since, p); + ::decode(snaps, p); + ::decode(past_parents, p); + DECODE_FINISH(p); +} + +void sr_t::dump(Formatter *f) const +{ + f->dump_unsigned("seq", seq); + f->dump_unsigned("created", created); + f->dump_unsigned("last_created", last_created); + f->dump_unsigned("last_destroyed", last_destroyed); + f->dump_unsigned("current_parent_since", current_parent_since); + + f->open_array_section("snaps"); + for (map::const_iterator p = snaps.begin(); p != snaps.end(); ++p) { + f->open_object_section("snapinfo"); + f->dump_unsigned("last", p->first); + p->second.dump(f); + f->close_section(); + } + f->close_section(); + + f->open_array_section("past_parents"); + for (map::const_iterator p = past_parents.begin(); p != past_parents.end(); ++p) { + f->open_object_section("past_parent"); + f->dump_unsigned("last", p->first); + p->second.dump(f); + f->close_section(); + } + f->close_section(); +} + +void sr_t::generate_test_instances(list& ls) +{ + ls.push_back(new sr_t); + ls.push_back(new sr_t); + ls.back()->seq = 1; + ls.back()->created = 2; + ls.back()->last_created = 3; + ls.back()->last_destroyed = 4; + ls.back()->current_parent_since = 5; + ls.back()->snaps[123].snapid = 7; + ls.back()->snaps[123].ino = 8; + ls.back()->snaps[123].stamp = utime_t(9, 10); + ls.back()->snaps[123].name = "name1"; + ls.back()->past_parents[12].ino = 12; + ls.back()->past_parents[12].first = 3; +} + + /* * SnapRealm */ diff --git a/src/mds/snap.h b/src/mds/snap.h index e583820dce9..45c2c036677 100644 --- a/src/mds/snap.h +++ b/src/mds/snap.h @@ -27,35 +27,20 @@ struct SnapInfo { snapid_t snapid; inodeno_t ino; utime_t stamp; - string name, long_name; + string name; + + string long_name; ///< cached _$ino_$name - void encode(bufferlist& bl) const { - __u8 struct_v = 1; - ::encode(struct_v, bl); - ::encode(snapid, bl); - ::encode(ino, bl); - ::encode(stamp, bl); - ::encode(name, bl); - } - void decode(bufferlist::iterator& bl) { - __u8 struct_v; - ::decode(struct_v, bl); - ::decode(snapid, bl); - ::decode(ino, bl); - ::decode(stamp, bl); - ::decode(name, bl); - } + void encode(bufferlist &bl) const; + void decode(bufferlist::iterator &bl); + void dump(Formatter *f) const; + static void generate_test_instances(list& ls); + const string& get_long_name(); }; WRITE_CLASS_ENCODER(SnapInfo) -inline ostream& operator<<(ostream& out, const SnapInfo &sn) { - return out << "snap(" << sn.snapid - << " " << sn.ino - << " '" << sn.name - << "' " << sn.stamp << ")"; -} - +ostream& operator<<(ostream& out, const SnapInfo &sn); /* @@ -74,25 +59,16 @@ class MDRequest; struct snaplink_t { inodeno_t ino; snapid_t first; - void encode(bufferlist& bl) const { - __u8 struct_v = 1; - ::encode(struct_v, bl); - ::encode(ino, bl); - ::encode(first, bl); - } - void decode(bufferlist::iterator& bl) { - __u8 struct_v; - ::decode(struct_v, bl); - ::decode(ino, bl); - ::decode(first, bl); - } + + void encode(bufferlist &bl) const; + void decode(bufferlist::iterator &bl); + void dump(Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(snaplink_t) -inline ostream& operator<<(ostream& out, const snaplink_t &l) -{ - return out << l.ino << "@" << l.first; -} +ostream& operator<<(ostream& out, const snaplink_t &l); + // carry data about a specific version of a SnapRealm struct sr_t { @@ -104,37 +80,16 @@ struct sr_t { map snaps; map past_parents; // key is "last" (or NOSNAP) - sr_t() : - seq(0), created(0), - last_created(0), last_destroyed(0), - current_parent_since(1) + sr_t() + : seq(0), created(0), + last_created(0), last_destroyed(0), + current_parent_since(1) {} - - void encode(bufferlist& bl) const { - __u8 struct_v = 3; - ::encode(struct_v, bl); - ::encode(seq, bl); - ::encode(created, bl); - ::encode(last_created, bl); - ::encode(last_destroyed, bl); - ::encode(current_parent_since, bl); - ::encode(snaps, bl); - ::encode(past_parents, bl); - } - void decode(bufferlist::iterator& p) { - __u8 struct_v; - ::decode(struct_v, p); - if (struct_v == 2) - ::decode(struct_v, p); // yes, really: extra byte for v2 encoding only, see 6ee52e7d. - ::decode(seq, p); - ::decode(created, p); - ::decode(last_created, p); - ::decode(last_destroyed, p); - ::decode(current_parent_since, p); - ::decode(snaps, p); - ::decode(past_parents, p); - } + void encode(bufferlist &bl) const; + void decode(bufferlist::iterator &bl); + void dump(Formatter *f) const; + static void generate_test_instances(list& ls); }; WRITE_CLASS_ENCODER(sr_t); diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index e3616c1fbad..3902337654a 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -91,6 +91,11 @@ TYPE(DBObjectMap::State) #include "mds/Anchor.h" TYPE(Anchor) +#include "mds/snap.h" +/*TYPE(SnapInfo) +TYPE(snaplink_t) +TYPE(sr_t)*/ + #ifdef WITH_RADOSGW #include "rgw/rgw_rados.h"