]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
messages: populate header.version in constructor
authorSage Weil <sage@newdream.net>
Fri, 10 Feb 2012 22:38:13 +0000 (14:38 -0800)
committerSage Weil <sage@newdream.net>
Fri, 10 Feb 2012 22:38:13 +0000 (14:38 -0800)
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 <sage.weil@dreamhost.com>
20 files changed:
src/messages/MClientCaps.h
src/messages/MClientReconnect.h
src/messages/MDiscoverReply.h
src/messages/MMDSBeacon.h
src/messages/MMonElection.h
src/messages/MMonGetVersionReply.h
src/messages/MMonPaxos.h
src/messages/MMonSubscribe.h
src/messages/MOSDBoot.h
src/messages/MOSDFailure.h
src/messages/MOSDMap.h
src/messages/MOSDOp.h
src/messages/MOSDOpReply.h
src/messages/MOSDPGLog.h
src/messages/MOSDPGNotify.h
src/messages/MOSDRepScrub.h
src/messages/MOSDSubOp.h
src/messages/MPoolOp.h
src/messages/PaxosServiceMessage.h
src/msg/Message.h

index f68e033618671264b91f64cd1cbd2b896494b5c2..117f24162e7d6b8a153dbfeade522b0d6e6eb6bb 100644 (file)
 
 
 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
     }
   }
 };
index aef97ee46df6aa06956bcee29c36059d8786ca05..400159c6db649f9314960984246c923131ddf3e1 100644 (file)
 
 
 class MClientReconnect : public Message {
+
+  const static int HEAD_VERSION = 2;
+
 public:
   map<inodeno_t, cap_reconnect_t>  caps;   // only head inodes
   vector<ceph_mds_snaprealm_reconnect> 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<inodeno_t, old_cap_reconnect_t> ocaps;
       for (map<inodeno_t,cap_reconnect_t>::iterator p = caps.begin(); p != caps.end(); p++)
        ocaps[p->first] = p->second;
index bad3386c3efb1f4d2e64116706dce61e67dc43a0..1623cf3113819cf66d5205bf79cd003e8498a492 100644 (file)
@@ -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);
index e1c950d250b5fae81bdc0358341ed26e05f1c7eb..64d442bf958fe31fa51a78750eab03940f24e0fb 100644 (file)
@@ -24,6 +24,9 @@
 #include <uuid/uuid.h>
 
 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);
index 26defa279d63b2952aedc544ebd1c2d684a1a230..6d8148bc4ec1794908ab28e608683860c809ca59 100644 (file)
@@ -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<int> 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);
index 2451cbeefc26d8e10ad09ae6b403c1a11090ee66..95e384dbc62b431edc21e79a2825b3de528d4c11 100644 (file)
  * 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);
   }
 
index 66f7a645bd6cfbb517c5ab75d8753409c3515f32..aefaebdfdd9d45d79e50dea0b7a7c9d26019c0b4 100644 (file)
@@ -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<version_t,bufferlist> 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);
index c2c1636be0ee00b1f0df1f64cdf944de5a0e5eb1..0233010fd8957fdfa521a6e7c8fe00b56e6b0803 100644 (file)
@@ -30,9 +30,12 @@ WRITE_RAW_ENCODER(ceph_mon_subscribe_item_old)
 
 
 struct MMonSubscribe : public Message {
+
+  static const int HEAD_VERSION = 2;
+
   map<string, ceph_mon_subscribe_item> 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<string, ceph_mon_subscribe_item_old> oldwhat;
       for (map<string, ceph_mon_subscribe_item>::iterator q = what.begin();
           q != what.end();
index 2737e0da22100423f8d1943e3d1be0e647e78853..70cf3ade23fd546fc39a2321ff568569d4acbbbf 100644 (file)
 #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);
index 90c20a3167e0508dd0588c9769b3ce5ac53a4196..3b8ed0b4a2cceaab72d8b10053fb95522625cfbf 100644 (file)
 
 
 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);
index cea74f12fc339dab922c32cc9d9d55b9cb9b5563..f7838f7b7ae24f7b00a5a9cbd48de7fc03b304e5 100644 (file)
@@ -21,6 +21,9 @@
 #include "include/ceph_features.h"
 
 class MOSDMap : public Message {
+
+  static const int HEAD_VERSION = 2;
+
  public:
   uuid_d fsid;
   map<epoch_t, bufferlist> 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);
index b77d85500454c082c746ff72ba09b1ee7b4a2aa5..418886507ffc8b054545c0f77bb3fca427ab918e 100644 (file)
 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);
index 8fe58a08e70616875000a9d38928ed55ec6721b1..9f47e5db95c999441b5f61d603174e6cbda6b518 100644 (file)
  */
 
 class MOSDOpReply : public Message {
+
+  static const int HEAD_VERSION = 4;
+  static const int COMPAT_VERSION = 2;
+
   object_t oid;
   pg_t pgid;
   vector<OSDOp> 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);
index 3b925bedc580422451f3cc67aead230e5dc41812..bf4297d39d5f7243d96bf7a5e40ce529c139ab78 100644 (file)
@@ -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);
     }
   }
index 88a091729d7fbf493674a634feecf4795c10a15c..55aa1dc5ecd5c3d990b5acc91e183772cefc9488 100644 (file)
  */
 
 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<pg_info_t>& 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<pg_info_t>& 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<pg_info_t>& 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);
     }
   }
index 3a32ba21458025ada0bf0533b29a041f0de00fd5..af3569c0a320fa1897eafb848a04d1870c47b160 100644 (file)
  */
 
 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);
index bee6a97e592c9b1497526d3deba1283edb200c73..fdf03e27eac1a4755171cb4f73149f647669a5bc 100644 (file)
  */
 
 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() {}
 
index c4ec9d863444ca6c52042e8ad578141b62e6ceb0..e6d31ee226b03b976fee56f6e0cb4c1a6f92fbca 100644 (file)
 
 
 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);
index 341a0b3f308cc7fd89f87977bbaceb6354cb1105..fc82e86395cd2c327d49c6d025ff03fb9cb896d2 100644 (file)
@@ -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() {}
 
index 0d356ff57f72b5ec28e2278c964cf798675e01b1..35bc39ee05cfbea836c13c37bdefd54929b81bb5 100644 (file)
@@ -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() {