From 2888830f722b61d921826c91b45b9c54e056ee5f Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 17 Jan 2013 10:23:16 -0800 Subject: [PATCH] mds: default_file_layout now uses modern encoding And move implementations into mdstypes.cc from CInode and common/types. mdstypes.cc sadly lives in libcommon; as several of the types we're going to put there are needed for Messages and similar things. Signed-off-by: Sage Weil Signed-off-by: Greg Farnum --- src/Makefile.am | 1 + src/common/types.cc | 13 ----------- src/mds/CInode.h | 31 ------------------------- src/mds/mdstypes.cc | 49 +++++++++++++++++++++++++++++++++++++++ src/mds/mdstypes.h | 19 +++++++++++++++ src/test/encoding/types.h | 3 +++ 6 files changed, 72 insertions(+), 44 deletions(-) create mode 100644 src/mds/mdstypes.cc diff --git a/src/Makefile.am b/src/Makefile.am index 402386d1868ea..c95ab5af0533b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1279,6 +1279,7 @@ libcommon_files = \ osd/osd_types.cc \ mds/MDSMap.cc \ mds/inode_backtrace.cc \ + mds/mdstypes.cc \ common/blkdev.cc \ common/common_init.cc \ common/pipe.c \ diff --git a/src/common/types.cc b/src/common/types.cc index c5482e108225f..d50e7da4a5287 100644 --- a/src/common/types.cc +++ b/src/common/types.cc @@ -4,19 +4,6 @@ #include "include/types.h" #include "common/Formatter.h" -void dump(const ceph_file_layout& l, Formatter *f) -{ - f->dump_unsigned("stripe_unit", l.fl_stripe_unit); - f->dump_unsigned("stripe_count", l.fl_stripe_count); - f->dump_unsigned("object_size", l.fl_object_size); - if (l.fl_cas_hash) - f->dump_unsigned("cas_hash", l.fl_cas_hash); - if (l.fl_object_stripe_unit) - f->dump_unsigned("object_stripe_unit", l.fl_object_stripe_unit); - if (l.fl_pg_pool) - f->dump_unsigned("pg_pool", l.fl_pg_pool); -} - void dump(const ceph_dir_layout& dl, Formatter *f) { f->dump_unsigned("dir_hash", dl.dl_dir_hash); diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 51e1eea5d5829..7001c93393505 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -63,37 +63,6 @@ struct cinode_lock_info_t { extern cinode_lock_info_t cinode_lock_info[]; extern int num_cinode_locks; -/** - * Default file layout stuff. This lets us set a default file layout on - * a directory inode that all files in its tree will use on creation. - */ -struct default_file_layout { - - ceph_file_layout layout; - - default_file_layout() { - memset(&layout, 0, sizeof(layout)); - } - - void encode(bufferlist &bl) const { - __u8 struct_v = 1; - ::encode(struct_v, bl); - ::encode(layout, bl); - } - - void decode(bufferlist::iterator& bl) { - __u8 struct_v; - ::decode(struct_v, bl); - if (struct_v != 1) { //uh-oh - derr << "got default layout I don't understand!" << dendl; - assert(0); - } - ::decode(layout, bl); - } -}; -WRITE_CLASS_ENCODER(default_file_layout); - - // cached inode wrapper class CInode : public MDSCacheObject { /* diff --git a/src/mds/mdstypes.cc b/src/mds/mdstypes.cc new file mode 100644 index 0000000000000..3a113af7bd823 --- /dev/null +++ b/src/mds/mdstypes.cc @@ -0,0 +1,49 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "mdstypes.h" +#include "common/Formatter.h" + +void default_file_layout::encode(bufferlist &bl) const +{ + ENCODE_START(2, 2, bl); + ::encode(layout, bl); + ENCODE_FINISH(bl); +} + +void default_file_layout::decode(bufferlist::iterator& bl) +{ + DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); + ::decode(layout, bl); + DECODE_FINISH(bl); +} + +void dump(const ceph_file_layout& l, Formatter *f) +{ + f->dump_unsigned("stripe_unit", l.fl_stripe_unit); + f->dump_unsigned("stripe_count", l.fl_stripe_count); + f->dump_unsigned("object_size", l.fl_object_size); + if (l.fl_cas_hash) + f->dump_unsigned("cas_hash", l.fl_cas_hash); + if (l.fl_object_stripe_unit) + f->dump_unsigned("object_stripe_unit", l.fl_object_stripe_unit); + if (l.fl_pg_pool) + f->dump_unsigned("pg_pool", l.fl_pg_pool); +} + +void default_file_layout::dump(Formatter *f) const +{ + ::dump(layout, f); +} + +void default_file_layout::generate_test_instances(list& ls) +{ + ls.push_back(new default_file_layout); + ls.push_back(new default_file_layout); + ls.back()->layout.fl_stripe_unit = 1024; + ls.back()->layout.fl_stripe_count = 2; + ls.back()->layout.fl_object_size = 2048; + ls.back()->layout.fl_cas_hash = 3; + ls.back()->layout.fl_object_stripe_unit = 8; + ls.back()->layout.fl_pg_pool = 9; +} diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 74b8571e0f33f..58f647569193b 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -107,6 +107,25 @@ inline string ccap_string(int cap) } +/** + * Default file layout stuff. This lets us set a default file layout on + * a directory inode that all files in its tree will use on creation. + */ +struct default_file_layout { + ceph_file_layout layout; + + default_file_layout() { + memset(&layout, 0, sizeof(layout)); + } + + 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(default_file_layout); + + struct scatter_info_t { version_t version; diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index 3902337654a18..321250c17b532 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -96,6 +96,9 @@ TYPE(Anchor) TYPE(snaplink_t) TYPE(sr_t)*/ +#include "mds/mdstypes.h" +TYPE(default_file_layout) + #ifdef WITH_RADOSGW #include "rgw/rgw_rados.h" -- 2.39.5