From 7b5689acfcb6e0b7f654c8bf41bd39d1cf66b0e9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 10 Feb 2012 14:38:13 -0800 Subject: [PATCH] messages: populate header.version in constructor Define a HEAD_VERSION and COMPAT_VERSION for any versioned message. Pass to Message constructor so that it is always initialized, even from the the default constructor. That's needed because we use that to check decoding compatibility when receiving/decoding messages. If we are conditionally encoding an old version, explicitly set header.version in encode_payload(). We also set compat_version to demonstrate what will happen for future revisions. In this case, it's moot, because no old code understands compat_version yet: nobody with old decode code will see these values anyway. But use this opportunity to demonstrate how it would be used in the future. Signed-off-by: Sage Weil --- src/messages/MClientCaps.h | 18 +++++++++++------ src/messages/MClientReconnect.h | 7 +++++-- src/messages/MDiscoverReply.h | 10 ++++++---- src/messages/MMDSBeacon.h | 11 ++++++---- src/messages/MMonElection.h | 6 ++++-- src/messages/MMonGetVersionReply.h | 8 +++++--- src/messages/MMonPaxos.h | 14 ++++++++----- src/messages/MMonSubscribe.h | 7 +++++-- src/messages/MOSDBoot.h | 14 ++++++++----- src/messages/MOSDFailure.h | 15 ++++++++------ src/messages/MOSDMap.h | 17 +++++++++------- src/messages/MOSDOp.h | 21 ++++++++++++-------- src/messages/MOSDOpReply.h | 13 ++++++++---- src/messages/MOSDPGLog.h | 21 +++++++++++--------- src/messages/MOSDPGNotify.h | 16 +++++++++------ src/messages/MOSDRepScrub.h | 19 +++++++++--------- src/messages/MOSDSubOp.h | 32 ++++++++++++++++-------------- src/messages/MPoolOp.h | 22 ++++++++++++-------- src/messages/PaxosServiceMessage.h | 10 ++++++---- src/msg/Message.h | 15 +++++++++----- 20 files changed, 182 insertions(+), 114 deletions(-) diff --git a/src/messages/MClientCaps.h b/src/messages/MClientCaps.h index f68e033618671..117f24162e7d6 100644 --- a/src/messages/MClientCaps.h +++ b/src/messages/MClientCaps.h @@ -20,6 +20,10 @@ class MClientCaps : public Message { + + static const int HEAD_VERSION = 2; // added flock metadata + static const int COMPAT_VERSION = 1; + public: struct ceph_mds_caps head; bufferlist snapbl; @@ -69,7 +73,8 @@ class MClientCaps : public Message { void set_mtime(const utime_t &t) { t.encode_timeval(&head.mtime); } void set_atime(const utime_t &t) { t.encode_timeval(&head.atime); } - MClientCaps() : Message(CEPH_MSG_CLIENT_CAPS) {} + MClientCaps() + : Message(CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION) { } MClientCaps(int op, inodeno_t ino, inodeno_t realm, @@ -78,8 +83,8 @@ class MClientCaps : public Message { int caps, int wanted, int dirty, - int mseq) : - Message(CEPH_MSG_CLIENT_CAPS) { + int mseq) + : Message(CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION) { memset(&head, 0, sizeof(head)); head.op = op; head.ino = ino; @@ -93,8 +98,8 @@ class MClientCaps : public Message { } MClientCaps(int op, inodeno_t ino, inodeno_t realm, - uint64_t id, int mseq) : - Message(CEPH_MSG_CLIENT_CAPS) { + uint64_t id, int mseq) + : Message(CEPH_MSG_CLIENT_CAPS, HEAD_VERSION) { memset(&head, 0, sizeof(head)); head.op = op; head.ino = ino; @@ -157,8 +162,9 @@ public: // conditionally include flock metadata if (features & CEPH_FEATURE_FLOCK) { - header.version = 2; ::encode(flockbl, payload); + } else { + header.version = 1; // old } } }; diff --git a/src/messages/MClientReconnect.h b/src/messages/MClientReconnect.h index aef97ee46df6a..400159c6db649 100644 --- a/src/messages/MClientReconnect.h +++ b/src/messages/MClientReconnect.h @@ -21,11 +21,14 @@ class MClientReconnect : public Message { + + const static int HEAD_VERSION = 2; + public: map caps; // only head inodes vector realms; - MClientReconnect() : Message(CEPH_MSG_CLIENT_RECONNECT) {} + MClientReconnect() : Message(CEPH_MSG_CLIENT_RECONNECT, HEAD_VERSION) { } private: ~MClientReconnect() {} @@ -52,10 +55,10 @@ public: void encode_payload(uint64_t features) { if (features & CEPH_FEATURE_FLOCK) { // new protocol - header.version = 2; ::encode(caps, data); } else { // compat crap + header.version = 1; map ocaps; for (map::iterator p = caps.begin(); p != caps.end(); p++) ocaps[p->first] = p->second; diff --git a/src/messages/MDiscoverReply.h b/src/messages/MDiscoverReply.h index bad3386c3efb1..1623cf3113819 100644 --- a/src/messages/MDiscoverReply.h +++ b/src/messages/MDiscoverReply.h @@ -66,6 +66,9 @@ using namespace std; */ class MDiscoverReply : public Message { + + static const int HEAD_VERSION = 2; + // info about original request inodeno_t base_ino; frag_t base_dir_frag; @@ -112,9 +115,9 @@ class MDiscoverReply : public Message { void set_base_dir_frag(frag_t df) { base_dir_frag = df; } // cons - MDiscoverReply() : Message(MSG_MDS_DISCOVERREPLY) {} + MDiscoverReply() : Message(MSG_MDS_DISCOVERREPLY, HEAD_VERSION) { } MDiscoverReply(MDiscover *dis) : - Message(MSG_MDS_DISCOVERREPLY), + Message(MSG_MDS_DISCOVERREPLY, HEAD_VERSION), base_ino(dis->get_base_ino()), base_dir_frag(dis->get_base_dir_frag()), wanted_base_dir(dis->wants_base_dir()), @@ -128,7 +131,7 @@ class MDiscoverReply : public Message { header.tid = dis->get_tid(); } MDiscoverReply(dirfrag_t df) : - Message(MSG_MDS_DISCOVERREPLY), + Message(MSG_MDS_DISCOVERREPLY, HEAD_VERSION), base_ino(df.ino), base_dir_frag(df.frag), wanted_base_dir(false), @@ -199,7 +202,6 @@ public: ::decode(wanted_ino, p); } void encode_payload(uint64_t features) { - header.version = 2; ::encode(base_ino, payload); ::encode(base_dir_frag, payload); ::encode(wanted_base_dir, payload); diff --git a/src/messages/MMDSBeacon.h b/src/messages/MMDSBeacon.h index e1c950d250b5f..64d442bf958fe 100644 --- a/src/messages/MMDSBeacon.h +++ b/src/messages/MMDSBeacon.h @@ -24,6 +24,9 @@ #include class MMDSBeacon : public PaxosServiceMessage { + + static const int HEAD_VERSION = 2; + uuid_d fsid; uint64_t global_id; string name; @@ -36,11 +39,12 @@ class MMDSBeacon : public PaxosServiceMessage { CompatSet compat; public: - MMDSBeacon() : PaxosServiceMessage(MSG_MDS_BEACON, 0) {} + MMDSBeacon() : PaxosServiceMessage(MSG_MDS_BEACON, 0, HEAD_VERSION) { } MMDSBeacon(const uuid_d &f, uint64_t g, string& n, epoch_t les, int st, version_t se) : - PaxosServiceMessage(MSG_MDS_BEACON, les), + PaxosServiceMessage(MSG_MDS_BEACON, les, HEAD_VERSION), fsid(f), global_id(g), name(n), state(st), seq(se), - standby_for_rank(-1) { } + standby_for_rank(-1) { + } private: ~MMDSBeacon() {} @@ -68,7 +72,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; paxos_encode(); ::encode(fsid, payload); ::encode(global_id, payload); diff --git a/src/messages/MMonElection.h b/src/messages/MMonElection.h index 26defa279d63b..6d8148bc4ec17 100644 --- a/src/messages/MMonElection.h +++ b/src/messages/MMonElection.h @@ -20,6 +20,9 @@ #include "mon/MonMap.h" class MMonElection : public Message { + + static const int HEAD_VERSION = 2; + public: static const int OP_PROPOSE = 1; static const int OP_ACK = 2; @@ -41,7 +44,7 @@ public: bufferlist monmap_bl; set quorum; - MMonElection() : Message(MSG_MON_ELECTION) {} + MMonElection() : Message(MSG_MON_ELECTION, HEAD_VERSION) { } MMonElection(int o, epoch_t e, MonMap *m) : Message(MSG_MON_ELECTION), fsid(m->fsid), op(o), epoch(e) { @@ -57,7 +60,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; ::encode(fsid, payload); ::encode(op, payload); ::encode(epoch, payload); diff --git a/src/messages/MMonGetVersionReply.h b/src/messages/MMonGetVersionReply.h index 2451cbeefc26d..95e384dbc62b4 100644 --- a/src/messages/MMonGetVersionReply.h +++ b/src/messages/MMonGetVersionReply.h @@ -25,8 +25,11 @@ * back. */ class MMonGetVersionReply : public Message { + + static const int HEAD_VERSION = 2; + public: - MMonGetVersionReply() : Message(CEPH_MSG_MON_GET_VERSION_REPLY) {} + MMonGetVersionReply() : Message(CEPH_MSG_MON_GET_VERSION_REPLY, HEAD_VERSION) { } const char *get_type_name() const { return "mon_check_map_ack"; @@ -37,7 +40,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; ::encode(handle, payload); ::encode(version, payload); ::encode(oldest_version, payload); @@ -47,7 +49,7 @@ public: bufferlist::iterator p = payload.begin(); ::decode(handle, p); ::decode(version, p); - if (header.version > 1) + if (header.version >= 2) ::decode(oldest_version, p); } diff --git a/src/messages/MMonPaxos.h b/src/messages/MMonPaxos.h index 66f7a645bd6cf..aefaebdfdd9d4 100644 --- a/src/messages/MMonPaxos.h +++ b/src/messages/MMonPaxos.h @@ -21,6 +21,9 @@ #include "include/ceph_features.h" class MMonPaxos : public Message { + + static const int HEAD_VERSION = 1; + public: // op types const static int OP_COLLECT = 1; // proposer: propose round @@ -60,14 +63,15 @@ class MMonPaxos : public Message { map values; - MMonPaxos() : Message(MSG_MON_PAXOS) {} + MMonPaxos() : Message(MSG_MON_PAXOS, HEAD_VERSION) { } MMonPaxos(epoch_t e, int o, int mid, utime_t now) : - Message(MSG_MON_PAXOS), + Message(MSG_MON_PAXOS, HEAD_VERSION), epoch(e), op(o), machine_id(mid), first_committed(0), last_committed(0), pn_from(0), pn(0), uncommitted_pn(0), sent_timestamp(now), - latest_version(0) { } + latest_version(0) { + } private: ~MMonPaxos() {} @@ -87,8 +91,8 @@ public: } void encode_payload(uint64_t features) { - if (features & CEPH_FEATURE_MONCLOCKCHECK) - header.version = 1; + if ((features & CEPH_FEATURE_MONCLOCKCHECK) == 0) + header.version = 0; ::encode(epoch, payload); ::encode(op, payload); ::encode(machine_id, payload); diff --git a/src/messages/MMonSubscribe.h b/src/messages/MMonSubscribe.h index c2c1636be0ee0..0233010fd8957 100644 --- a/src/messages/MMonSubscribe.h +++ b/src/messages/MMonSubscribe.h @@ -30,9 +30,12 @@ WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old) struct MMonSubscribe : public Message { + + static const int HEAD_VERSION = 2; + map what; - MMonSubscribe() : Message(CEPH_MSG_MON_SUBSCRIBE) {} + MMonSubscribe() : Message(CEPH_MSG_MON_SUBSCRIBE, HEAD_VERSION) { } private: ~MMonSubscribe() {} @@ -70,9 +73,9 @@ public: } void encode_payload(uint64_t features) { if (features & CEPH_FEATURE_SUBSCRIBE2) { - header.version = 2; ::encode(what, payload); } else { + header.version = 0; map oldwhat; for (map::iterator q = what.begin(); q != what.end(); diff --git a/src/messages/MOSDBoot.h b/src/messages/MOSDBoot.h index 2737e0da22100..70cf3ade23fd5 100644 --- a/src/messages/MOSDBoot.h +++ b/src/messages/MOSDBoot.h @@ -21,16 +21,21 @@ #include "osd/osd_types.h" class MOSDBoot : public PaxosServiceMessage { + + static const int HEAD_VERSION = 2; + public: OSDSuperblock sb; entity_addr_t hb_addr; entity_addr_t cluster_addr; - MOSDBoot() : PaxosServiceMessage(MSG_OSD_BOOT, 0) { } + MOSDBoot() : PaxosServiceMessage(MSG_OSD_BOOT, 0, HEAD_VERSION) { } MOSDBoot(OSDSuperblock& s, const entity_addr_t& hb_addr_ref, - const entity_addr_t& cluster_addr_ref) : - PaxosServiceMessage(MSG_OSD_BOOT, s.current_epoch), - sb(s), hb_addr(hb_addr_ref), cluster_addr(cluster_addr_ref) { } + const entity_addr_t& cluster_addr_ref) + : PaxosServiceMessage(MSG_OSD_BOOT, s.current_epoch, HEAD_VERSION), + sb(s), + hb_addr(hb_addr_ref), cluster_addr(cluster_addr_ref) { + } private: ~MOSDBoot() { } @@ -42,7 +47,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; paxos_encode(); ::encode(sb, payload); ::encode(hb_addr, payload); diff --git a/src/messages/MOSDFailure.h b/src/messages/MOSDFailure.h index 90c20a3167e05..3b8ed0b4a2cce 100644 --- a/src/messages/MOSDFailure.h +++ b/src/messages/MOSDFailure.h @@ -20,16 +20,19 @@ class MOSDFailure : public PaxosServiceMessage { + + static const int HEAD_VERSION = 2; + public: uuid_d fsid; entity_inst_t target_osd; __u8 is_failed; epoch_t epoch; - MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE, 0) {} - MOSDFailure(const uuid_d &fs, entity_inst_t f, epoch_t e) : - PaxosServiceMessage(MSG_OSD_FAILURE, e), - fsid(fs), target_osd(f), is_failed(true), epoch(e) {} + MOSDFailure() : PaxosServiceMessage(MSG_OSD_FAILURE, 0, HEAD_VERSION) { } + MOSDFailure(const uuid_d &fs, entity_inst_t f, epoch_t e) + : PaxosServiceMessage(MSG_OSD_FAILURE, e, HEAD_VERSION), + fsid(fs), target_osd(f), is_failed(true), epoch(e) { } private: ~MOSDFailure() {} @@ -46,10 +49,10 @@ public: ::decode(epoch, p); if (header.version >=2) ::decode(is_failed, p); - else is_failed = true; + else + is_failed = true; } void encode_payload(uint64_t features) { - header.version = 2; paxos_encode(); ::encode(fsid, payload); ::encode(target_osd, payload); diff --git a/src/messages/MOSDMap.h b/src/messages/MOSDMap.h index cea74f12fc339..f7838f7b7ae24 100644 --- a/src/messages/MOSDMap.h +++ b/src/messages/MOSDMap.h @@ -21,6 +21,9 @@ #include "include/ceph_features.h" class MOSDMap : public Message { + + static const int HEAD_VERSION = 2; + public: uuid_d fsid; map maps; @@ -53,11 +56,11 @@ class MOSDMap : public Message { } - MOSDMap() : Message(CEPH_MSG_OSD_MAP) { } + MOSDMap() : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION) { } MOSDMap(const uuid_d &f, OSDMap *oc=0) - : Message(CEPH_MSG_OSD_MAP), fsid(f), - oldest_map(0), newest_map(0) - { + : Message(CEPH_MSG_OSD_MAP, HEAD_VERSION), + fsid(f), + oldest_map(0), newest_map(0) { if (oc) oc->encode(maps[oc->get_epoch()]); } @@ -71,7 +74,7 @@ public: ::decode(fsid, p); ::decode(incremental_maps, p); ::decode(maps, p); - if (header.version > 1) { + if (header.version >= 2) { ::decode(oldest_map, p); ::decode(newest_map, p); } else { @@ -81,9 +84,10 @@ public: } void encode_payload(uint64_t features) { ::encode(fsid, payload); - header.version = 2; if ((features & CEPH_FEATURE_PGID64) == 0 || (features & CEPH_FEATURE_PGPOOL3) == 0) { + header.version = 1; + // reencode maps using old format // // FIXME: this can probably be done more efficiently higher up @@ -113,7 +117,6 @@ public: p->second.clear(); m.encode(p->second, features); } - header.version = 1; } ::encode(incremental_maps, payload); ::encode(maps, payload); diff --git a/src/messages/MOSDOp.h b/src/messages/MOSDOp.h index b77d85500454c..418886507ffc8 100644 --- a/src/messages/MOSDOp.h +++ b/src/messages/MOSDOp.h @@ -31,6 +31,10 @@ class OSD; class MOSDOp : public Message { + + static const int HEAD_VERSION = 4; + static const int COMPAT_VERSION = 3; + private: uint32_t client_inc; __u32 osdmap_epoch; @@ -104,17 +108,18 @@ public: return peer_stat; } + MOSDOp() + : Message(CEPH_MSG_OSD_OP, HEAD_VERSION, COMPAT_VERSION) { } MOSDOp(int inc, long tid, object_t& _oid, object_locator_t& _oloc, pg_t _pgid, epoch_t _osdmap_epoch, - int _flags) : - Message(CEPH_MSG_OSD_OP), - client_inc(inc), - osdmap_epoch(_osdmap_epoch), flags(_flags), retry_attempt(-1), - oid(_oid), oloc(_oloc), pgid(_pgid), - rmw_flags(flags) { + int _flags) + : Message(CEPH_MSG_OSD_OP, HEAD_VERSION, COMPAT_VERSION), + client_inc(inc), + osdmap_epoch(_osdmap_epoch), flags(_flags), retry_attempt(-1), + oid(_oid), oloc(_oloc), pgid(_pgid), + rmw_flags(flags) { set_tid(tid); } - MOSDOp() : Message(CEPH_MSG_OSD_OP) {} private: ~MOSDOp() {} @@ -216,6 +221,7 @@ struct ceph_osd_request_head { struct ceph_osd_op ops[]; /* followed by ops[], obj, ticket, snaps */ } __attribute__ ((packed)); #endif + header.version = 1; ::encode(client_inc, payload); @@ -246,7 +252,6 @@ struct ceph_osd_request_head { if (flags & CEPH_OSD_FLAG_PEERSTAT) ::encode(peer_stat, payload); } else { - header.version = 4; ::encode(client_inc, payload); ::encode(osdmap_epoch, payload); ::encode(flags, payload); diff --git a/src/messages/MOSDOpReply.h b/src/messages/MOSDOpReply.h index 8fe58a08e7061..9f47e5db95c99 100644 --- a/src/messages/MOSDOpReply.h +++ b/src/messages/MOSDOpReply.h @@ -30,6 +30,10 @@ */ class MOSDOpReply : public Message { + + static const int HEAD_VERSION = 4; + static const int COMPAT_VERSION = 2; + object_t oid; pg_t pgid; vector ops; @@ -86,8 +90,10 @@ public: */ public: - MOSDOpReply(MOSDOp *req, int r, epoch_t e, int acktype) : - Message(CEPH_MSG_OSD_OPREPLY) { + MOSDOpReply() + : Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION) { } + MOSDOpReply(MOSDOp *req, int r, epoch_t e, int acktype) + : Message(CEPH_MSG_OSD_OPREPLY, HEAD_VERSION, COMPAT_VERSION) { set_tid(req->get_tid()); ops = req->ops; result = r; @@ -103,7 +109,6 @@ public: for (unsigned i = 0; i < ops.size(); i++) ops[i].op.payload_len = 0; } - MOSDOpReply() : Message(CEPH_MSG_OSD_OPREPLY) {} private: ~MOSDOpReply() {} @@ -113,6 +118,7 @@ public: OSDOp::merge_osd_op_vector_out_data(ops, data); if ((features & CEPH_FEATURE_PGID64) == 0) { + header.version = 1; ceph_osd_reply_head head; memset(&head, 0, sizeof(head)); head.layout.ol_pgid = pgid.get_old_pg().v; @@ -127,7 +133,6 @@ public: } ::encode_nohead(oid.name, payload); } else { - header.version = 4; ::encode(oid, payload); ::encode(pgid, payload); ::encode(flags, payload); diff --git a/src/messages/MOSDPGLog.h b/src/messages/MOSDPGLog.h index 3b925bedc5804..bf4297d39d5f7 100644 --- a/src/messages/MOSDPGLog.h +++ b/src/messages/MOSDPGLog.h @@ -19,6 +19,9 @@ #include "msg/Message.h" class MOSDPGLog : public Message { + + static const int HEAD_VERSION = 2; + epoch_t epoch; /// query_epoch is the epoch of the query being responded to, or /// the current epoch if this is not being sent in response to a @@ -35,13 +38,14 @@ public: pg_t get_pgid() { return info.pgid; } epoch_t get_query_epoch() { return query_epoch; } - MOSDPGLog() : Message(MSG_OSD_PG_LOG) {} - MOSDPGLog(version_t mv, pg_info_t& i) : - Message(MSG_OSD_PG_LOG), - epoch(mv), query_epoch(mv), info(i) { } - MOSDPGLog(version_t mv, pg_info_t& i, epoch_t query_epoch) : - Message(MSG_OSD_PG_LOG), - epoch(mv), query_epoch(query_epoch), info(i) { } + MOSDPGLog() : Message(MSG_OSD_PG_LOG, HEAD_VERSION) { } + MOSDPGLog(version_t mv, pg_info_t& i) + : Message(MSG_OSD_PG_LOG, HEAD_VERSION), + epoch(mv), query_epoch(mv), info(i) { } + MOSDPGLog(version_t mv, pg_info_t& i, epoch_t query_epoch) + : Message(MSG_OSD_PG_LOG, HEAD_VERSION), + epoch(mv), query_epoch(query_epoch), info(i) { } + private: ~MOSDPGLog() {} @@ -53,7 +57,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; ::encode(epoch, payload); ::encode(info, payload); ::encode(log, payload); @@ -66,7 +69,7 @@ public: ::decode(info, p); ::decode(log, p); ::decode(missing, p); - if (header.version > 1) { + if (header.version >= 2) { ::decode(query_epoch, p); } } diff --git a/src/messages/MOSDPGNotify.h b/src/messages/MOSDPGNotify.h index 88a091729d7fb..55aa1dc5ecd5c 100644 --- a/src/messages/MOSDPGNotify.h +++ b/src/messages/MOSDPGNotify.h @@ -24,6 +24,10 @@ */ class MOSDPGNotify : public Message { + + static const int HEAD_VERSION = 2; + static const int COMPAT_VERSION = 1; + epoch_t epoch; /// query_epoch is the epoch of the query being responded to, or /// the current epoch if this is not being sent in response to a @@ -37,10 +41,11 @@ class MOSDPGNotify : public Message { vector& get_pg_list() { return pg_list; } epoch_t get_query_epoch() { return query_epoch; } - MOSDPGNotify() : Message(MSG_OSD_PG_NOTIFY) {} - MOSDPGNotify(epoch_t e, vector& l, epoch_t query_epoch) : - Message(MSG_OSD_PG_NOTIFY), epoch(e), - query_epoch(query_epoch) { + MOSDPGNotify() + : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) { } + MOSDPGNotify(epoch_t e, vector& l, epoch_t query_epoch) + : Message(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION), + epoch(e), query_epoch(query_epoch) { pg_list.swap(l); } private: @@ -50,7 +55,6 @@ public: const char *get_type_name() const { return "PGnot"; } void encode_payload(uint64_t features) { - header.version = 2; ::encode(epoch, payload); ::encode(pg_list, payload); ::encode(query_epoch, payload); @@ -59,7 +63,7 @@ public: bufferlist::iterator p = payload.begin(); ::decode(epoch, p); ::decode(pg_list, p); - if (header.version > 1) { + if (header.version >= 2) { ::decode(query_epoch, p); } } diff --git a/src/messages/MOSDRepScrub.h b/src/messages/MOSDRepScrub.h index 3a32ba2145802..af3569c0a320f 100644 --- a/src/messages/MOSDRepScrub.h +++ b/src/messages/MOSDRepScrub.h @@ -23,19 +23,22 @@ */ struct MOSDRepScrub : public Message { + + static const int HEAD_VERSION = 2; + pg_t pgid; // PG to scrub eversion_t scrub_from; // only scrub log entries after scrub_from eversion_t scrub_to; // last_update_applied when message sent epoch_t map_epoch; - MOSDRepScrub() : Message(MSG_OSD_REP_SCRUB) {} + MOSDRepScrub() : Message(MSG_OSD_REP_SCRUB, HEAD_VERSION) { } MOSDRepScrub(pg_t pgid, eversion_t scrub_from, eversion_t scrub_to, - epoch_t map_epoch) : - Message(MSG_OSD_REP_SCRUB), - pgid(pgid), - scrub_from(scrub_from), - scrub_to(scrub_to), - map_epoch(map_epoch) {} + epoch_t map_epoch) + : Message(MSG_OSD_REP_SCRUB, HEAD_VERSION), + pgid(pgid), + scrub_from(scrub_from), + scrub_to(scrub_to), + map_epoch(map_epoch) { } private: ~MOSDRepScrub() {} @@ -50,14 +53,12 @@ public: } void encode_payload(uint64_t features) { - header.version = 2; ::encode(pgid, payload); ::encode(scrub_from, payload); ::encode(scrub_to, payload); ::encode(map_epoch, payload); } void decode_payload() { - assert(header.version == 2); bufferlist::iterator p = payload.begin(); ::decode(pgid, p); ::decode(scrub_from, p); diff --git a/src/messages/MOSDSubOp.h b/src/messages/MOSDSubOp.h index bee6a97e592c9..fdf03e27eac1a 100644 --- a/src/messages/MOSDSubOp.h +++ b/src/messages/MOSDSubOp.h @@ -24,6 +24,10 @@ */ class MOSDSubOp : public Message { + + static const int HEAD_VERSION = 3; + static const int COMPAT_VERSION = 1; + public: epoch_t map_epoch; @@ -109,8 +113,6 @@ public: } virtual void encode_payload(uint64_t features) { - header.version = 3; - ::encode(map_epoch, payload); ::encode(reqid, payload); ::encode(pgid, payload); @@ -149,23 +151,23 @@ public: } + MOSDSubOp() + : Message(MSG_OSD_SUBOP, HEAD_VERSION, COMPAT_VERSION) { } MOSDSubOp(osd_reqid_t r, pg_t p, const hobject_t& po, bool noop_, int aw, - epoch_t mape, tid_t rtid, eversion_t v) : - Message(MSG_OSD_SUBOP), - map_epoch(mape), - reqid(r), - pgid(p), - poid(po), - acks_wanted(aw), - noop(noop_), - old_exists(false), old_size(0), - version(v), - first(false), complete(false) - { + epoch_t mape, tid_t rtid, eversion_t v) + : Message(MSG_OSD_SUBOP, HEAD_VERSION, COMPAT_VERSION), + map_epoch(mape), + reqid(r), + pgid(p), + poid(po), + acks_wanted(aw), + noop(noop_), + old_exists(false), old_size(0), + version(v), + first(false), complete(false) { memset(&peer_stat, 0, sizeof(peer_stat)); set_tid(rtid); } - MOSDSubOp() : Message(MSG_OSD_SUBOP) {} private: ~MOSDSubOp() {} diff --git a/src/messages/MPoolOp.h b/src/messages/MPoolOp.h index c4ec9d863444c..e6d31ee226b03 100644 --- a/src/messages/MPoolOp.h +++ b/src/messages/MPoolOp.h @@ -19,6 +19,10 @@ class MPoolOp : public PaxosServiceMessage { + + static const int HEAD_VERSION = 4; + static const int COMPAT_VERSION = 2; + public: uuid_d fsid; __u32 pool; @@ -28,16 +32,19 @@ public: snapid_t snapid; __s16 crush_rule; - MPoolOp() : PaxosServiceMessage(CEPH_MSG_POOLOP, 0) {} - MPoolOp(const uuid_d& f, tid_t t, int p, string& n, int o, version_t v) : - PaxosServiceMessage(CEPH_MSG_POOLOP, v), fsid(f), pool(p), name(n), op(o), - auid(0), snapid(0), crush_rule(0) { + MPoolOp() + : PaxosServiceMessage(CEPH_MSG_POOLOP, 0, HEAD_VERSION, COMPAT_VERSION) { } + MPoolOp(const uuid_d& f, tid_t t, int p, string& n, int o, version_t v) + : PaxosServiceMessage(CEPH_MSG_POOLOP, v, HEAD_VERSION, COMPAT_VERSION), + fsid(f), pool(p), name(n), op(o), + auid(0), snapid(0), crush_rule(0) { set_tid(t); } MPoolOp(const uuid_d& f, tid_t t, int p, string& n, - int o, uint64_t uid, version_t v) : - PaxosServiceMessage(CEPH_MSG_POOLOP, v), fsid(f), pool(p), name(n), op(o), - auid(uid), snapid(0), crush_rule(0) { + int o, uint64_t uid, version_t v) + : PaxosServiceMessage(CEPH_MSG_POOLOP, v, HEAD_VERSION, COMPAT_VERSION), + fsid(f), pool(p), name(n), op(o), + auid(uid), snapid(0), crush_rule(0) { set_tid(t); } @@ -55,7 +62,6 @@ public: } void encode_payload(uint64_t features) { - header.version = 4; paxos_encode(); ::encode(fsid, payload); ::encode(pool, payload); diff --git a/src/messages/PaxosServiceMessage.h b/src/messages/PaxosServiceMessage.h index 341a0b3f308cc..fc82e86395cd2 100644 --- a/src/messages/PaxosServiceMessage.h +++ b/src/messages/PaxosServiceMessage.h @@ -10,10 +10,12 @@ class PaxosServiceMessage : public Message { __s16 session_mon; uint64_t session_mon_tid; - PaxosServiceMessage() : Message(MSG_PAXOS), - version(0), session_mon(-1), session_mon_tid(0) { } - PaxosServiceMessage(int type, version_t v) : Message(type), - version(v), session_mon(-1), session_mon_tid(0) { } + PaxosServiceMessage() + : Message(MSG_PAXOS), + version(0), session_mon(-1), session_mon_tid(0) { } + PaxosServiceMessage(int type, version_t v, int enc_version=1, int compat_enc_version=0) + : Message(type, enc_version, compat_enc_version), + version(v), session_mon(-1), session_mon_tid(0) { } protected: ~PaxosServiceMessage() {} diff --git a/src/msg/Message.h b/src/msg/Message.h index 0d356ff57f72b..35bc39ee05cfb 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -298,19 +298,24 @@ protected: friend class Messenger; public: - Message() : connection(NULL), dispatch_throttle_size(0) { + Message() + : connection(NULL), + throttler(NULL), + dispatch_throttle_size(0) { memset(&header, 0, sizeof(header)); memset(&footer, 0, sizeof(footer)); - throttler = NULL; }; - Message(int t) : connection(NULL), dispatch_throttle_size(0) { + Message(int t, int version=1, int compat_version=0) + : connection(NULL), + throttler(NULL), + dispatch_throttle_size(0) { memset(&header, 0, sizeof(header)); header.type = t; - header.version = 1; + header.version = version; + header.compat_version = compat_version; header.priority = 0; // undef header.data_off = 0; memset(&footer, 0, sizeof(footer)); - throttler = NULL; } Message *get() { -- 2.39.5