From: Sage Weil Date: Thu, 20 Oct 2011 04:47:50 +0000 (-0700) Subject: osd: pg_pool_t: normalize encoding X-Git-Tag: v0.38~57^2~2^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f2816a1e68a3a017ebcb254997ec3711be0653c5;p=ceph.git osd: pg_pool_t: normalize encoding Normalize encoding to be less awkward. Use a FEATURE bit to indicate whether the new encoding is supported, and encode appropriately. Signed-off-by: Sage Weil --- diff --git a/src/include/ceph_fs.h b/src/include/ceph_fs.h index 294231d19779..d07f99f1802f 100644 --- a/src/include/ceph_fs.h +++ b/src/include/ceph_fs.h @@ -50,6 +50,7 @@ #define CEPH_FEATURE_OBJECTLOCATOR (1<<8) #define CEPH_FEATURE_PGID64 (1<<9) #define CEPH_FEATURE_INCSUBOSDMAP (1<<10) +#define CEPH_FEATURE_PGPOOL3 (1<<11) /* * ceph_file_layout - describe data layout for a file/inode diff --git a/src/messages/MOSDMap.h b/src/messages/MOSDMap.h index 6c158a8a60ea..1a956a44b6e2 100644 --- a/src/messages/MOSDMap.h +++ b/src/messages/MOSDMap.h @@ -79,7 +79,8 @@ public: void encode_payload(CephContext *cct) { ::encode(fsid, payload); header.version = 2; - if (connection && !connection->has_feature(CEPH_FEATURE_PGID64)) { + if (connection && (!connection->has_feature(CEPH_FEATURE_PGID64) || + !connection->has_feature(CEPH_FEATURE_PGPOOL3))) { // reencode maps using old format // // FIXME: this can probably be done more efficiently higher up diff --git a/src/msg/SimpleMessenger.h b/src/msg/SimpleMessenger.h index 3c81c92dc282..10583501e89a 100644 --- a/src/msg/SimpleMessenger.h +++ b/src/msg/SimpleMessenger.h @@ -61,7 +61,8 @@ using namespace __gnu_cxx; CEPH_FEATURE_DIRLAYOUTHASH | \ CEPH_FEATURE_OBJECTLOCATOR | \ CEPH_FEATURE_PGID64 | \ - CEPH_FEATURE_INCSUBOSDMAP + CEPH_FEATURE_INCSUBOSDMAP | \ + CEPH_FEATURE_PGPOOL3 class SimpleMessenger : public Messenger { public: diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 87f83234e70b..80f3e023ff31 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -92,7 +92,7 @@ void OSDMap::Incremental::encode_client_old(bufferlist& bl) const ++p) { n = p->first; ::encode(n, bl); - ::encode(p->second, bl); + ::encode(p->second, bl, 0); } // for ::encode(new_pool_names, bl); n = new_pool_names.size(); @@ -143,7 +143,7 @@ void OSDMap::Incremental::encode(bufferlist& bl, uint64_t features) const ::encode(crush, bl); ::encode(new_max_osd, bl); - ::encode(new_pools, bl); + ::encode(new_pools, bl, features); ::encode(new_pool_names, bl); ::encode(old_pools, bl); ::encode(new_up_client, bl); @@ -460,7 +460,7 @@ void OSDMap::encode_client_old(bufferlist& bl) const ++p) { n = p->first; ::encode(n, bl); - ::encode(p->second, bl); + ::encode(p->second, bl, 0); } // for ::encode(pool_name, bl); n = pool_name.size(); @@ -516,7 +516,7 @@ void OSDMap::encode(bufferlist& bl, uint64_t features) const ::encode(created, bl); ::encode(modified, bl); - ::encode(pools, bl); + ::encode(pools, bl, features); ::encode(pool_name, bl); ::encode(pool_max, bl); diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 4710a5bc670f..79265c3c04f9 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -396,9 +396,37 @@ ps_t pg_pool_t::raw_pg_to_pps(pg_t pg) const return ceph_stable_mod(pg.ps(), pgp_num, pgp_num_mask) + pg.pool(); } -void pg_pool_t::encode(bufferlist& bl) const -{ - __u8 struct_v = 2; +void pg_pool_t::encode(bufferlist& bl, uint64_t features) const +{ + if ((features & CEPH_FEATURE_PGPOOL3) == 0) { + // this encoding matches the old struct ceph_pg_pool + __u8 struct_v = 2; + ::encode(struct_v, bl); + ::encode(type, bl); + ::encode(size, bl); + ::encode(crush_ruleset, bl); + ::encode(object_hash, bl); + ::encode(pg_num, bl); + ::encode(pgp_num, bl); + ::encode(lpg_num, bl); + ::encode(lpgp_num, bl); + ::encode(last_change, bl); + ::encode(snap_seq, bl); + ::encode(snap_epoch, bl); + + __u32 n = snaps.size(); + ::encode(n, bl); + n = removed_snaps.num_intervals(); + ::encode(n, bl); + + ::encode(auid, bl); + + ::encode_nohead(snaps, bl); + removed_snaps.encode_nohead(bl); + return; + } + + __u8 struct_v = 3; ::encode(struct_v, bl); ::encode(type, bl); ::encode(size, bl); @@ -411,23 +439,16 @@ void pg_pool_t::encode(bufferlist& bl) const ::encode(last_change, bl); ::encode(snap_seq, bl); ::encode(snap_epoch, bl); - - __u32 n = snaps.size(); - ::encode(n, bl); - n = removed_snaps.num_intervals(); - ::encode(n, bl); - + ::encode(snaps, bl); + ::encode(removed_snaps, bl); ::encode(auid, bl); - - ::encode_nohead(snaps, bl); - removed_snaps.encode_nohead(bl); } void pg_pool_t::decode(bufferlist::iterator& bl) { __u8 struct_v; ::decode(struct_v, bl); - if (struct_v > 2) + if (struct_v > 3) throw buffer::error(); ::decode(type, bl); @@ -441,15 +462,19 @@ void pg_pool_t::decode(bufferlist::iterator& bl) ::decode(last_change, bl); ::decode(snap_seq, bl); ::decode(snap_epoch, bl); - - __u32 n, m; - ::decode(n, bl); - ::decode(m, bl); - - ::decode(auid, bl); - ::decode_nohead(n, snaps, bl); - removed_snaps.decode_nohead(m, bl); + if (struct_v >= 3) { + ::decode(snaps, bl); + ::decode(removed_snaps, bl); + ::decode(auid, bl); + } else { + __u32 n, m; + ::decode(n, bl); + ::decode(m, bl); + ::decode(auid, bl); + ::decode_nohead(n, snaps, bl); + removed_snaps.decode_nohead(m, bl); + } calc_pg_masks(); } diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 7c2483c56507..cd8740d95f72 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -654,10 +654,10 @@ struct pg_pool_t { */ ps_t raw_pg_to_pps(pg_t pg) const; - void encode(bufferlist& bl) const; + void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::iterator& bl); }; -WRITE_CLASS_ENCODER(pg_pool_t) +WRITE_CLASS_ENCODER_FEATURES(pg_pool_t) ostream& operator<<(ostream& out, const pg_pool_t& p);