From a892671a0075151911edcf681d946046cff0ab90 Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 17 Jan 2013 10:23:41 -0800 Subject: [PATCH] mds: frag_info_t now uses modern encoding Signed-off-by: Sage Weil --- src/mds/mdstypes.cc | 62 +++++++++++++++++++++++++++++++++++++++ src/mds/mdstypes.h | 35 ++++------------------ src/test/encoding/types.h | 1 + 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index 3a113af7bd823..eaeecc21b93a1 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -4,6 +4,10 @@ #include "mdstypes.h" #include "common/Formatter.h" +/* + * default_file_layout + */ + void default_file_layout::encode(bufferlist &bl) const { ENCODE_START(2, 2, bl); @@ -47,3 +51,61 @@ void default_file_layout::generate_test_instances(list& ls ls.back()->layout.fl_object_stripe_unit = 8; ls.back()->layout.fl_pg_pool = 9; } + + +/* + * frag_info_t + */ + +void frag_info_t::encode(bufferlist &bl) const +{ + ENCODE_START(2, 2, bl); + ::encode(version, bl); + ::encode(mtime, bl); + ::encode(nfiles, bl); + ::encode(nsubdirs, bl); + ENCODE_FINISH(bl); +} + +void frag_info_t::decode(bufferlist::iterator &bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); + ::decode(version, bl); + ::decode(mtime, bl); + ::decode(nfiles, bl); + ::decode(nsubdirs, bl); + DECODE_FINISH(bl); +} + +void frag_info_t::dump(Formatter *f) const +{ + f->dump_unsigned("version", version); + f->dump_stream("mtime") << mtime; + f->dump_unsigned("num_files", nfiles); + f->dump_unsigned("num_subdirs", nsubdirs); +} + +void frag_info_t::generate_test_instances(list& ls) +{ + ls.push_back(new frag_info_t); + ls.push_back(new frag_info_t); + ls.back()->version = 1; + ls.back()->mtime = utime_t(2, 3); + ls.back()->nfiles = 4; + ls.back()->nsubdirs = 5; +} + +ostream& operator<<(ostream &out, const frag_info_t &f) +{ + if (f == frag_info_t()) + return out << "f()"; + out << "f(v" << f.version; + if (f.mtime != utime_t()) + out << " m" << f.mtime; + if (f.nfiles || f.nsubdirs) + out << " " << f.size() << "=" << f.nfiles << "+" << f.nsubdirs; + out << ")"; + return out; +} + + diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 58f647569193b..4c38bd5717141 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -163,24 +163,10 @@ struct frag_info_t : public scatter_info_t { nsubdirs += other.nsubdirs; } - void encode(bufferlist &bl) const { - __u8 v = 1; - ::encode(v, bl); - - ::encode(version, bl); - ::encode(mtime, bl); - ::encode(nfiles, bl); - ::encode(nsubdirs, bl); - } - void decode(bufferlist::iterator &bl) { - __u8 v; - ::decode(v, bl); - - ::decode(version, bl); - ::decode(mtime, bl); - ::decode(nfiles, bl); - ::decode(nsubdirs, 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(frag_info_t) @@ -188,17 +174,8 @@ inline bool operator==(const frag_info_t &l, const frag_info_t &r) { return memcmp(&l, &r, sizeof(l)) == 0; } -inline ostream& operator<<(ostream &out, const frag_info_t &f) { - if (f == frag_info_t()) - return out << "f()"; - out << "f(v" << f.version; - if (f.mtime != utime_t()) - out << " m" << f.mtime; - if (f.nfiles || f.nsubdirs) - out << " " << f.size() << "=" << f.nfiles << "+" << f.nsubdirs; - out << ")"; - return out; -} +ostream& operator<<(ostream &out, const frag_info_t &f); + struct nest_info_t : public scatter_info_t { // this frag + children diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 321250c17b532..4b06a72bee6a9 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -98,6 +98,7 @@ TYPE(sr_t)*/ #include "mds/mdstypes.h" TYPE(default_file_layout) +TYPE(frag_info_t) #ifdef WITH_RADOSGW -- 2.39.5