From: Greg Farnum Date: Thu, 31 Jan 2013 19:16:30 +0000 (-0800) Subject: mds: inode_t now uses modern encoding X-Git-Tag: v0.58~100^2~65 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=843a35219c7cb8f34838c4823bf10ab60d27ec62;p=ceph.git mds: inode_t now uses modern encoding And we move implementations and the dumper into mdstypes.cc (from mdstypes.h and common/types.cc). Signed-off-by: Sage Weil Signed-off-by: Greg Farnum --- diff --git a/src/common/types.cc b/src/common/types.cc index d50e7da4a5287..8f69bf57da5fb 100644 --- a/src/common/types.cc +++ b/src/common/types.cc @@ -3,8 +3,3 @@ #include "include/types.h" #include "common/Formatter.h" - -void dump(const ceph_dir_layout& dl, Formatter *f) -{ - f->dump_unsigned("dir_hash", dl.dl_dir_hash); -} diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc index 282d22c8cb1a6..18c682757ce4c 100644 --- a/src/mds/mdstypes.cc +++ b/src/mds/mdstypes.cc @@ -35,6 +35,11 @@ void dump(const ceph_file_layout& l, Formatter *f) f->dump_unsigned("pg_pool", l.fl_pg_pool); } +void dump(const ceph_dir_layout& l, Formatter *f) +{ + f->dump_unsigned("dir_hash", l.dl_dir_hash); +} + void file_layout_policy_t::dump(Formatter *f) const { ::dump(layout, f); @@ -227,3 +232,163 @@ ostream& operator<<(ostream& out, const client_writeable_range_t& r) { return out << r.range.first << '-' << r.range.last << "@" << r.follows; } + + +/* + * inode_t + */ +void inode_t::encode(bufferlist &bl) const +{ + ENCODE_START(6, 6, bl); + + ::encode(ino, bl); + ::encode(rdev, bl); + ::encode(ctime, bl); + + ::encode(mode, bl); + ::encode(uid, bl); + ::encode(gid, bl); + + ::encode(nlink, bl); + ::encode(anchored, bl); + + ::encode(dir_layout, bl); + ::encode(layout, bl); + ::encode(size, bl); + ::encode(truncate_seq, bl); + ::encode(truncate_size, bl); + ::encode(truncate_from, bl); + ::encode(truncate_pending, bl); + ::encode(mtime, bl); + ::encode(atime, bl); + ::encode(time_warp_seq, bl); + ::encode(client_ranges, bl); + + ::encode(dirstat, bl); + ::encode(rstat, bl); + ::encode(accounted_rstat, bl); + + ::encode(version, bl); + ::encode(file_data_version, bl); + ::encode(xattr_version, bl); + ::encode(last_renamed_version, bl); + + ENCODE_FINISH(bl); +} + +void inode_t::decode(bufferlist::iterator &p) +{ + DECODE_START_LEGACY_COMPAT_LEN(6, 6, 6, p); + + ::decode(ino, p); + ::decode(rdev, p); + ::decode(ctime, p); + + ::decode(mode, p); + ::decode(uid, p); + ::decode(gid, p); + + ::decode(nlink, p); + ::decode(anchored, p); + + if (struct_v >= 4) + ::decode(dir_layout, p); + else + memset(&dir_layout, 0, sizeof(dir_layout)); + ::decode(layout, p); + ::decode(size, p); + ::decode(truncate_seq, p); + ::decode(truncate_size, p); + ::decode(truncate_from, p); + if (struct_v >= 5) + ::decode(truncate_pending, p); + else + truncate_pending = 0; + ::decode(mtime, p); + ::decode(atime, p); + ::decode(time_warp_seq, p); + if (struct_v >= 3) { + ::decode(client_ranges, p); + } else { + map m; + ::decode(m, p); + for (map::iterator + q = m.begin(); q != m.end(); q++) + client_ranges[q->first].range = q->second; + } + + ::decode(dirstat, p); + ::decode(rstat, p); + ::decode(accounted_rstat, p); + + ::decode(version, p); + ::decode(file_data_version, p); + ::decode(xattr_version, p); + if (struct_v >= 2) + ::decode(last_renamed_version, p); + + DECODE_FINISH(p); +} + +void inode_t::dump(Formatter *f) const +{ + f->dump_unsigned("ino", ino); + f->dump_unsigned("rdev", rdev); + f->dump_stream("ctime") << ctime; + f->dump_unsigned("mode", mode); + f->dump_unsigned("uid", uid); + f->dump_unsigned("gid", gid); + f->dump_unsigned("nlink", nlink); + f->dump_unsigned("anchored", (int)anchored); + + f->open_object_section("dir_layout"); + ::dump(dir_layout, f); + f->close_section(); + + f->open_object_section("layout"); + ::dump(layout, f); + f->close_section(); + + f->dump_unsigned("size", size); + f->dump_unsigned("truncate_seq", truncate_seq); + f->dump_unsigned("truncate_size", truncate_size); + f->dump_unsigned("truncate_from", truncate_from); + f->dump_unsigned("truncate_pending", truncate_pending); + f->dump_stream("mtime") << mtime; + f->dump_stream("atime") << atime; + f->dump_unsigned("time_warp_seq", time_warp_seq); + + f->open_array_section("client_ranges"); + for (map::const_iterator p = client_ranges.begin(); p != client_ranges.end(); ++p) { + f->open_object_section("client"); + f->dump_unsigned("client", p->first.v); + p->second.dump(f); + f->close_section(); + } + f->close_section(); + + f->open_object_section("dirstat"); + dirstat.dump(f); + f->close_section(); + + f->open_object_section("rstat"); + rstat.dump(f); + f->close_section(); + + f->open_object_section("accounted_rstat"); + accounted_rstat.dump(f); + f->close_section(); + + f->dump_unsigned("version", version); + f->dump_unsigned("file_data_version", file_data_version); + f->dump_unsigned("xattr_version", xattr_version); + f->dump_unsigned("last_renamed_version", last_renamed_version); +} + +void inode_t::generate_test_instances(list& ls) +{ + ls.push_back(new inode_t); + ls.push_back(new inode_t); + ls.back()->ino = 1; + // i am lazy. +} diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 68bfbcbab3fb0..b26e312f6d025 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -318,6 +318,9 @@ inline bool operator==(const client_writeable_range_t& l, } +/* + * inode_t + */ struct inode_t { // base (immutable) inodeno_t ino; @@ -423,93 +426,10 @@ struct inode_t { } } - void encode(bufferlist &bl) const { - __u8 v = 5; - ::encode(v, bl); - - ::encode(ino, bl); - ::encode(rdev, bl); - ::encode(ctime, bl); - - ::encode(mode, bl); - ::encode(uid, bl); - ::encode(gid, bl); - - ::encode(nlink, bl); - ::encode(anchored, bl); - - ::encode(dir_layout, bl); - ::encode(layout, bl); - ::encode(size, bl); - ::encode(truncate_seq, bl); - ::encode(truncate_size, bl); - ::encode(truncate_from, bl); - ::encode(truncate_pending, bl); - ::encode(mtime, bl); - ::encode(atime, bl); - ::encode(time_warp_seq, bl); - ::encode(client_ranges, bl); - - ::encode(dirstat, bl); - ::encode(rstat, bl); - ::encode(accounted_rstat, bl); - - ::encode(version, bl); - ::encode(file_data_version, bl); - ::encode(xattr_version, bl); - ::encode(last_renamed_version, bl); - } - void decode(bufferlist::iterator &p) { - __u8 v; - ::decode(v, p); - - ::decode(ino, p); - ::decode(rdev, p); - ::decode(ctime, p); - - ::decode(mode, p); - ::decode(uid, p); - ::decode(gid, p); - - ::decode(nlink, p); - ::decode(anchored, p); - - if (v >= 4) - ::decode(dir_layout, p); - else - memset(&dir_layout, 0, sizeof(dir_layout)); - ::decode(layout, p); - ::decode(size, p); - ::decode(truncate_seq, p); - ::decode(truncate_size, p); - ::decode(truncate_from, p); - if (v >= 5) - ::decode(truncate_pending, p); - else - truncate_pending = 0; - ::decode(mtime, p); - ::decode(atime, p); - ::decode(time_warp_seq, p); - if (v >= 3) { - ::decode(client_ranges, p); - } else { - map m; - ::decode(m, p); - for (map::iterator - q = m.begin(); q != m.end(); q++) - client_ranges[q->first].range = q->second; - } - - ::decode(dirstat, p); - ::decode(rstat, p); - ::decode(accounted_rstat, p); - - ::decode(version, p); - ::decode(file_data_version, p); - ::decode(xattr_version, p); - if (v >= 2) - ::decode(last_renamed_version, 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(inode_t) diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index ebe3d69611aae..ea6765f7f3fc5 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -101,6 +101,7 @@ TYPE(file_layout_policy_t) TYPE(frag_info_t) TYPE(nest_info_t) TYPE(client_writeable_range_t) +TYPE(inode_t) #ifdef WITH_RADOSGW