From ad40bdd8b698759e94b9b104d73acdb4d9bc79bc Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Thu, 31 Jan 2013 13:14:27 -0800 Subject: [PATCH] MDSMap: mds_info_t now uses modern encoding We have to update the older-style MDSMap encodings to generate the previous versions for clients as well. Signed-off-by: Greg Farnum --- src/mds/MDSMap.cc | 60 ++++++++++++++++++++++++++++++++------- src/mds/MDSMap.h | 11 +++++-- src/test/encoding/types.h | 1 + 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/mds/MDSMap.cc b/src/mds/MDSMap.cc index 08e1a554d2553..ae09aeddbe5e9 100644 --- a/src/mds/MDSMap.cc +++ b/src/mds/MDSMap.cc @@ -64,6 +64,17 @@ void MDSMap::mds_info_t::dump(Formatter *f) const f->close_section(); } +void MDSMap::mds_info_t::generate_test_instances(list& ls) +{ + mds_info_t *sample = new mds_info_t(); + ls.push_back(sample); + sample = new mds_info_t(); + sample->global_id = 1; + sample->name = "test_instance"; + sample->rank = 0; + ls.push_back(sample); +} + void MDSMap::dump(Formatter *f) const { f->dump_int("epoch", epoch); @@ -268,10 +279,27 @@ void MDSMap::get_health(list >& summary, } } -void MDSMap::mds_info_t::encode(bufferlist& bl) const +void MDSMap::mds_info_t::encode_versioned(bufferlist& bl, uint64_t features) const +{ + ENCODE_START(4, 4, bl); + ::encode(global_id, bl); + ::encode(name, bl); + ::encode(rank, bl); + ::encode(inc, bl); + ::encode(state, bl); + ::encode(state_seq, bl); + ::encode(addr, bl); + ::encode(laggy_since, bl); + ::encode(standby_for_rank, bl); + ::encode(standby_for_name, bl); + ::encode(export_targets, bl); + ENCODE_FINISH(bl); +} + +void MDSMap::mds_info_t::encode_unversioned(bufferlist& bl) const { - __u8 v = 3; - ::encode(v, bl); + __u8 struct_v = 3; + ::encode(struct_v, bl); ::encode(global_id, bl); ::encode(name, bl); ::encode(rank, bl); @@ -287,8 +315,7 @@ void MDSMap::mds_info_t::encode(bufferlist& bl) const void MDSMap::mds_info_t::decode(bufferlist::iterator& bl) { - __u8 v; - ::decode(v, bl); + DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, bl); ::decode(global_id, bl); ::decode(name, bl); ::decode(rank, bl); @@ -299,8 +326,9 @@ void MDSMap::mds_info_t::decode(bufferlist::iterator& bl) ::decode(laggy_since, bl); ::decode(standby_for_rank, bl); ::decode(standby_for_name, bl); - if (v >= 2) + if (struct_v >= 2) ::decode(export_targets, bl); + DECODE_FINISH(bl); } @@ -318,8 +346,14 @@ void MDSMap::encode(bufferlist& bl, uint64_t features) const ::encode(session_autoclose, bl); ::encode(max_file_size, bl); ::encode(max_mds, bl); - ::encode(mds_info, bl); - __u32 n = data_pools.size(); + __u32 n = mds_info.size(); + ::encode(n, bl); + for (map::const_iterator i = mds_info.begin(); + i != mds_info.end(); ++i) { + ::encode(i->first, bl); + ::encode(i->second, bl, features); + } + n = data_pools.size(); ::encode(n, bl); for (set::const_iterator p = data_pools.begin(); p != data_pools.end(); ++p) { n = *p; @@ -340,7 +374,13 @@ void MDSMap::encode(bufferlist& bl, uint64_t features) const ::encode(session_autoclose, bl); ::encode(max_file_size, bl); ::encode(max_mds, bl); - ::encode(mds_info, bl); + __u32 n = mds_info.size(); + ::encode(n, bl); + for (map::const_iterator i = mds_info.begin(); + i != mds_info.end(); ++i) { + ::encode(i->first, bl); + ::encode(i->second, bl, features); + } ::encode(data_pools, bl); ::encode(cas_pool, bl); @@ -368,7 +408,7 @@ void MDSMap::encode(bufferlist& bl, uint64_t features) const ::encode(session_autoclose, bl); ::encode(max_file_size, bl); ::encode(max_mds, bl); - ::encode(mds_info, bl); + ::encode(mds_info, bl, features); ::encode(data_pools, bl); ::encode(cas_pool, bl); diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index 2a5ee888169c5..23c8482f25a41 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -124,9 +124,16 @@ public: entity_inst_t get_inst() const { return entity_inst_t(entity_name_t::MDS(rank), addr); } - void encode(bufferlist& bl) const; + void encode(bufferlist& bl, uint64_t features) const { + if ((features & CEPH_FEATURE_MDSENC) == 0 ) encode_unversioned(bl); + else encode_versioned(bl, features); + } void decode(bufferlist::iterator& p); void dump(Formatter *f) const; + static void generate_test_instances(list& ls); + private: + void encode_versioned(bufferlist& bl, uint64_t features) const; + void encode_unversioned(bufferlist& bl) const; }; @@ -490,7 +497,7 @@ public: void dump(Formatter *f) const; static void generate_test_instances(list& ls); }; -WRITE_CLASS_ENCODER(MDSMap::mds_info_t) +WRITE_CLASS_ENCODER_FEATURES(MDSMap::mds_info_t) WRITE_CLASS_ENCODER_FEATURES(MDSMap) inline ostream& operator<<(ostream& out, MDSMap& m) { diff --git a/src/test/encoding/types.h b/src/test/encoding/types.h index c36da829a34cd..423d8472eea98 100644 --- a/src/test/encoding/types.h +++ b/src/test/encoding/types.h @@ -111,6 +111,7 @@ TYPE(mds_table_pending_t) #include "mds/MDSMap.h" TYPE_FEATUREFUL(MDSMap) +TYPE_FEATUREFUL(MDSMap::mds_info_t) #ifdef WITH_RADOSGW -- 2.39.5